답안 #251698

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
251698 2020-07-22T07:47:33 Z Vladikus004 Izbori (COCI17_izbori) C++14
80 / 80
30 ms 384 KB
#include <bits/stdc++.h>
#define inf 2e9
//#define int long long
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;

const int N = 100 + 3;
int n, m, k, a[N][15], cnt[15], mx;

int get_win(int ind, int mask){
    for (int i = 0; i < m; i++){
        if ((1<<a[ind][i]) & mask){
            continue;
        }
        return a[ind][i];
    }
}

int get(int mask){
    fill(cnt, cnt + 15, 0);
    int mx = 0;
    for (int i = 0; i < n; i++){
        int cur = get_win(i, mask);
        cnt[cur]++;
        mx = max(mx, cnt[cur]);
    }
    for (int i = 0; i < m; i++)
        if (mx == cnt[i]) return i;
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif // LOCAL
    cin >> n >> m >> k;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            cin >> a[i][j];
            a[i][j]--;
        }
        cnt[a[i][0]]++;
        mx = max(mx, cnt[a[i][0]]);
    }
    for (int i = 0; i < m; i++){
        if (cnt[i] == mx){
            cout << i + 1 << "\n";
            break;
        }
    }
    int mn = m;
    for (int mask = 0; mask < (1<<m) - 1; mask++){
        if (get(mask) == k - 1){
            mn = min(mn, __builtin_popcount(mask));
        }
    }
    cout << mn;
}

Compilation message

izbori.cpp: In function 'int get_win(int, int)':
izbori.cpp:20:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
izbori.cpp: In function 'int get(int)':
izbori.cpp:32:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 14 ms 384 KB Output is correct
13 Correct 26 ms 384 KB Output is correct
14 Correct 13 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 30 ms 384 KB Output is correct
17 Correct 15 ms 384 KB Output is correct
18 Correct 28 ms 384 KB Output is correct
19 Correct 30 ms 384 KB Output is correct
20 Correct 30 ms 384 KB Output is correct