Submission #236724

# Submission time Handle Problem Language Result Execution time Memory
236724 2020-06-03T06:48:59 Z VEGAnn Izbori (COCI17_izbori) C++14
80 / 80
42 ms 768 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
const int oo = int(2e9);
bool mrk[N];
int n, m, k, ans = oo, kol[N], per[N][N];

int who(int mask){
    fill(kol, kol + m, 0);

    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++)
            if (!(mask & (1 << per[i][j]))) {
                kol[per[i][j]]++;
                break;
            }
    }

    int mx = -1;

    for (int i = 0; i < m; i++)
        mx = max(mx, kol[i]);

    for (int i = 0; i < m; i++)
        if (mx == kol[i])
            return i;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

#ifdef _LOCAL
    freopen("in.txt","r",stdin);
#endif // _LOCAL

    cin >> n >> m >> k;
    k--;

    for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
        cin >> per[i][j];
        per[i][j]--;
    }

    cout << who(0) + 1 << '\n';

    for (int mask = 0; mask < (1 << m) - 1; mask++)
        if (who(mask) == k)
            ans = min(ans, __builtin_popcount(mask));

    cout << ans;

    return 0;
}

Compilation message

izbori.cpp: In function 'int who(int)':
izbori.cpp:27:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 11 ms 640 KB Output is correct
2 Correct 7 ms 384 KB Output is correct
3 Correct 6 ms 712 KB Output is correct
4 Correct 13 ms 640 KB Output is correct
5 Correct 6 ms 640 KB Output is correct
6 Correct 6 ms 512 KB Output is correct
7 Correct 5 ms 640 KB Output is correct
8 Correct 7 ms 384 KB Output is correct
9 Correct 9 ms 768 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 9 ms 640 KB Output is correct
12 Correct 19 ms 768 KB Output is correct
13 Correct 31 ms 640 KB Output is correct
14 Correct 18 ms 640 KB Output is correct
15 Correct 8 ms 640 KB Output is correct
16 Correct 37 ms 768 KB Output is correct
17 Correct 19 ms 640 KB Output is correct
18 Correct 37 ms 640 KB Output is correct
19 Correct 42 ms 768 KB Output is correct
20 Correct 38 ms 768 KB Output is correct