Uva 11588 - Image Coding

#include<bits/stdc++.h>
using namespace std;

typedef map<char,int>mpci;
typedef long long LL;
typedef vector<int>vi;

int ar[30];

int main()
{
    int t,tc=0;
    cin >> t;
    while(t--)
    {
        memset(ar,0,sizeof(ar));
        int r,c,m,n;
        cin >> r >> c >> m >> n;
        int rocl=r*c;
        char ch;
        for(int i=0;i<r;i++)
        {
            for(int j=0;j<c;j++)
            {
                cin >> ch;
                ar[ch-'A']++;
            }
        }
        int mx=-1, cnt=0;
        for(int i=0; i<26; i++)
        {
            if(ar[i]>mx)
            {
                mx = ar[i];
                cnt=1;
            }
            else if(mx==ar[i])
            {
                ++cnt;
            }
        }
        int due = rocl - (mx*cnt);
        LL res = (mx*m*cnt) + (due*n);
        cout << "Case " << ++tc << ": ";
        cout << res << "\n";
    }

    return 0;
}


/*

1
5 4 2 1
ABCD
ABCA
EFAC
BCAG
AZIP

*/

Comments

Popular posts from this blog

SPOJ-CMG - Collecting Mango

LightOJ 1009 - Back to Underworld

LeetCode Palindrome Number