#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
#define int long long
#define mod 1000000007
#define base 7001
#define base2 757
// #define pi acos(-1)
#define double long double
// #define ordered_set tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>
// #define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#pragma GCC optimize("O3,Ofast,unroll-loops")
#pragma GCC target("avx2,sse3,sse4,avx")
constexpr int maxn = 1000001;
const int N = 1 << (int)(ceil(log2(maxn)));
int n, m, k;
int a[101][16];
bool take[16];
void f(int i, int cnt) {
if (i > m) {
short frq[16] = {};
for (int j = 0; j < n; j++) {
bool flag = 0;
for (int c = 0; c <= cnt; c++){
if (!take[a[j][c]]) {
frq[a[j][c]]++;
flag = 1;
break;
}
}
}
short mx = 0, mxi = 0;
for (int j = 1; j <= m; j++)
{
if (frq[j] > mx)
{
mx = frq[j];
mxi = j;
}
}
if (mxi == k)
{
int ans = 0;
for (int j = 0; j < 16; j++) {
if (take[j]) ans++;
}
cout << ans;
exit(0);
}
return;
}
f(i + 1, cnt);
if (i != k) {
take[i] = 1;
f(i + 1, cnt + 1);
}
return;
}
signed main()
{
cin.tie(0) -> sync_with_stdio(0);
cin >> n >> m >> k;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> a[i][j];
int frq[16] = {};
for (int i = 0; i < n; i++) frq[a[i][0]]++;
short mx = 0, mxi = 0;
for (int j = 1; j <= m; j++)
{
if (frq[j] > mx)
{
mx = frq[j];
mxi = j;
}
}
cout << mxi << "\n";
f(1, 0);
}
Compilation message
izbori.cpp: In function 'void f(long long int, long long int)':
izbori.cpp:31:18: warning: variable 'flag' set but not used [-Wunused-but-set-variable]
31 | bool flag = 0;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
348 KB |
Partially correct |
2 |
Partially correct |
0 ms |
348 KB |
Partially correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Partially correct |
0 ms |
348 KB |
Partially correct |
5 |
Partially correct |
0 ms |
348 KB |
Partially correct |
6 |
Partially correct |
1 ms |
344 KB |
Partially correct |
7 |
Partially correct |
0 ms |
348 KB |
Partially correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Partially correct |
1 ms |
344 KB |
Partially correct |
10 |
Partially correct |
0 ms |
348 KB |
Partially correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Partially correct |
0 ms |
348 KB |
Partially correct |
13 |
Partially correct |
1 ms |
348 KB |
Partially correct |
14 |
Partially correct |
0 ms |
348 KB |
Partially correct |
15 |
Partially correct |
1 ms |
344 KB |
Partially correct |
16 |
Partially correct |
2 ms |
348 KB |
Partially correct |
17 |
Partially correct |
1 ms |
348 KB |
Partially correct |
18 |
Partially correct |
3 ms |
468 KB |
Partially correct |
19 |
Partially correct |
1 ms |
348 KB |
Partially correct |
20 |
Partially correct |
1 ms |
348 KB |
Partially correct |