Submission #176144

#TimeUsernameProblemLanguageResultExecution timeMemory
176144notwhatyouneedtoknowIzbori (COCI17_izbori)C++14
80 / 80
16 ms504 KiB
#include<bits/stdc++.h>
using namespace std;

int n, m, k, x, rj=20;
int polje [110][17];
int brojac [15];

int main ( ){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m >> k;
    k--;
    for (int i=0; i<n; i++){
        for (int j=0; j<m; j++){
            cin >> polje [i][j];
            polje[i][j]--;
        }
    }
    for (int mask=0; mask<(1<<m); mask++){
        if (mask & (1<<k)) continue;
        for (int i=0; i<m; i++) brojac[i]=0;
        for (int i=0; i<n; i++){
            int j=0;
            while (mask & (1<<polje[i][j])) j++;
            brojac [polje[i][j]]++;
        }
        x=0;
        for (int i=1; i<m; i++){
            if (brojac[i]>brojac[x]) x=i;
        }
        if (mask==0) cout << x+1 << endl;
        if (x==k){
            x=0;
            for (int i=0; i<m; i++){
                if (mask & (1<<i)){
                    x++;
                }
            }
            rj = min(rj, x);
        }
    }
    cout << rj;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...