답안 #1097041

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1097041 2024-10-05T21:21:27 Z vjudge1 Izbori (COCI17_izbori) C++17
56 / 80
46 ms 348 KB
#include "bits/stdc++.h"
const signed MOD = 1e9 + 7;
const signed mod = 998244353;
using namespace std;
#define all(x) x.begin(), x.end()
#define ld long double
#define ll long long
#define pb push_back
#define mp make_pair
#define co cout <<
#define S second
#define F first
int a[105][20];
vector<int> v;
int n, m, k;
int ans;

int sol() {
    int f[m + 1] = {};
    for (int i = 0; i < n; i++) {
        int j = 0;
        while (j < m) {
            bool flag = 1;
            for (int d : v) if (a[i][j] == d) flag = 0;
            if (flag) break;
            j++;
        }
        f[a[i][j]]++;
    }
    int mx = 0, num = 0;

    for (int i = 1; i <= m; i++) {
         if (f[i] >= mx) {
            if (f[i] == mx && i < num) num = i;
            else {
                mx = f[i];
                num = i;
            }
        }
    }
    return num;
}

void rec(int i, int cn) {
    if (i == m) {
        if (sol() == k) ans = min(ans, cn);
        return;
    }
    v.pb(i + 1);
    rec(i + 1, cn + 1);
    v.pop_back();
    rec(i + 1, cn);
}

void solve() {
    cin >> n >> m >> k;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }
    co sol() << endl;
    ans = m - 1;
    rec(0, 0);
    co ans;
}

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    signed t = 1;
    // cin >> t;
    while (t--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Partially correct 3 ms 344 KB Partially correct
2 Partially correct 3 ms 348 KB Partially correct
3 Partially correct 1 ms 348 KB Partially correct
4 Correct 8 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Partially correct 1 ms 348 KB Partially correct
7 Partially correct 0 ms 348 KB Partially correct
8 Correct 4 ms 348 KB Output is correct
9 Partially correct 5 ms 348 KB Partially correct
10 Partially correct 1 ms 348 KB Partially correct
11 Correct 4 ms 348 KB Output is correct
12 Correct 19 ms 348 KB Output is correct
13 Correct 37 ms 348 KB Output is correct
14 Correct 20 ms 348 KB Output is correct
15 Correct 5 ms 348 KB Output is correct
16 Partially correct 44 ms 348 KB Partially correct
17 Partially correct 20 ms 348 KB Partially correct
18 Incorrect 40 ms 348 KB Output isn't correct
19 Partially correct 44 ms 348 KB Partially correct
20 Correct 46 ms 348 KB Output is correct