#include<bits/stdc++.h>
using namespace std;
int n,m,k;
int grid[105][15];
int winner(){
int winner[20];
memset(winner,0,sizeof(winner));
for(int i = 0; i < n; i++){
winner[grid[i][0]]++;
}
int win,winval = 0;
for(int i = 1; i <= m; i++){
if(winner[i] > winval){
winval = winner[i];
win = i;
}
}
return win;
}
int currwin(int mask){
int winner[20];
memset(winner,0,sizeof(winner));
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(mask & (1 << (grid[i][j]-1))) continue;
winner[grid[i][j]]++;
break;
}
}
int winval = 0, win;
for(int i = 1; i <= m; i++){
if(winner[i] > winval){
winval = winner[i];
win = i;
}
}
return win;
}
int main(){
cin >> n >> m >> k;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cin >> grid[i][j];
}
}
int currentwinner = winner();
int izbaceni = 0;
int fullmask = 1 << m;
queue <pair<int,int>> q;
q.push(make_pair(fullmask + (1 << (currentwinner-1)),1));
if(currentwinner == k) goto kr;
while(!q.empty()){
auto node = q.front();
q.pop();
int currmask = node.first;
if(currwin(currmask) == k){
izbaceni = node.second;
break;
}
for(int i = 0; i < m; i++){
if(i+1 != k && !(currmask & (1 << i))){
q.push(make_pair((currmask + (1 << i)),node.second+1));
}
}
}
kr:;
cout << currentwinner << endl << izbaceni;
}
Compilation message
izbori.cpp: In function 'int winner()':
izbori.cpp:21:9: warning: 'win' may be used uninitialized in this function [-Wmaybe-uninitialized]
return win;
^~~
izbori.cpp: In function 'int currwin(int)':
izbori.cpp:41:9: warning: 'win' may be used uninitialized in this function [-Wmaybe-uninitialized]
return win;
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Partially correct |
2 ms |
560 KB |
Partially correct |
4 |
Correct |
2 ms |
616 KB |
Output is correct |
5 |
Partially correct |
15 ms |
940 KB |
Partially correct |
6 |
Partially correct |
2 ms |
940 KB |
Partially correct |
7 |
Correct |
2 ms |
940 KB |
Output is correct |
8 |
Correct |
2 ms |
940 KB |
Output is correct |
9 |
Partially correct |
2 ms |
940 KB |
Partially correct |
10 |
Partially correct |
2 ms |
940 KB |
Partially correct |
11 |
Correct |
2 ms |
940 KB |
Output is correct |
12 |
Correct |
2 ms |
940 KB |
Output is correct |
13 |
Correct |
6 ms |
972 KB |
Output is correct |
14 |
Correct |
2 ms |
972 KB |
Output is correct |
15 |
Partially correct |
2 ms |
972 KB |
Partially correct |
16 |
Correct |
2 ms |
972 KB |
Output is correct |
17 |
Correct |
2 ms |
972 KB |
Output is correct |
18 |
Runtime error |
2659 ms |
65536 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
19 |
Correct |
7 ms |
65536 KB |
Output is correct |
20 |
Runtime error |
2756 ms |
65536 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |