#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] = {}, j[n] = {};
for (int i = 0; i < n; i++) {
while (j[i] < m) {
bool fl = 1;
for (int u : v) if (a[i][j[i]] == u) fl = 0;
if (fl) break;
j[i]++;
}
f[a[i][j[i]]]++;
}
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 |
348 KB |
Partially correct |
2 |
Partially correct |
3 ms |
348 KB |
Partially correct |
3 |
Partially correct |
1 ms |
348 KB |
Partially correct |
4 |
Correct |
9 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
344 KB |
Output is correct |
6 |
Partially correct |
1 ms |
348 KB |
Partially correct |
7 |
Partially correct |
0 ms |
348 KB |
Partially correct |
8 |
Correct |
5 ms |
348 KB |
Output is correct |
9 |
Partially correct |
6 ms |
348 KB |
Partially correct |
10 |
Partially correct |
1 ms |
348 KB |
Partially correct |
11 |
Correct |
5 ms |
348 KB |
Output is correct |
12 |
Correct |
22 ms |
348 KB |
Output is correct |
13 |
Correct |
43 ms |
348 KB |
Output is correct |
14 |
Correct |
21 ms |
348 KB |
Output is correct |
15 |
Correct |
5 ms |
344 KB |
Output is correct |
16 |
Partially correct |
52 ms |
348 KB |
Partially correct |
17 |
Partially correct |
23 ms |
344 KB |
Partially correct |
18 |
Incorrect |
47 ms |
348 KB |
Output isn't correct |
19 |
Partially correct |
52 ms |
348 KB |
Partially correct |
20 |
Correct |
51 ms |
344 KB |
Output is correct |