# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
44571 |
2018-04-03T11:06:57 Z |
heon |
Izbori (COCI17_izbori) |
C++11 |
|
2359 ms |
65536 KB |
#include<bits/stdc++.h>
using namespace std;
int n,m,k;
vector <int> vec[105];
int currvecfind(vector <int> &currvec, int a){
for(auto x : currvec){
if(x == a) return 1;
}
return 0;
}
int currentwinner(vector <int> &currvec){
int winner[105];
memset(winner,0,sizeof(winner));
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(!currvecfind(currvec,vec[i][j])){
winner[vec[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 winner(){
int winner[105];
memset(winner,0,sizeof(winner));
for(int i = 0; i < n; i++){
winner[vec[i][0]]++;
}
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++){
int input;
cin >> input;
vec[i].push_back(input);
}
}
int originalwinner = winner();
int izbaceni = 0;
queue < pair<vector<int>,int> > q;
vector <int> v = {originalwinner};
q.push(make_pair(v,1));
if(originalwinner == k) goto kr;
while(!q.empty()){
auto node = q.front();
q.pop();
auto currvec = node.first;
if(currentwinner(currvec) == k){
izbaceni = node.second;
break;
}
for(int i = 1; i <= m; i++){
if(!currvecfind(currvec,i) && i != k){
vector <int> temp = currvec;
temp.push_back(i);
q.push(make_pair(temp,node.second+1));
}
}
}
kr:;
cout << originalwinner << endl << izbaceni;
}
Compilation message
izbori.cpp: In function 'int currentwinner(std::vector<int>&)':
izbori.cpp:33:9: warning: 'win' may be used uninitialized in this function [-Wmaybe-uninitialized]
return win;
^~~
izbori.cpp: In function 'int winner()':
izbori.cpp:49:9: warning: 'win' may be used uninitialized in this function [-Wmaybe-uninitialized]
return win;
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
1272 KB |
Output is correct |
2 |
Correct |
2 ms |
1272 KB |
Output is correct |
3 |
Partially correct |
2 ms |
1272 KB |
Partially correct |
4 |
Correct |
2 ms |
1272 KB |
Output is correct |
5 |
Partially correct |
55 ms |
5376 KB |
Partially correct |
6 |
Partially correct |
2 ms |
5376 KB |
Partially correct |
7 |
Correct |
2 ms |
5376 KB |
Output is correct |
8 |
Correct |
2 ms |
5376 KB |
Output is correct |
9 |
Partially correct |
2 ms |
5376 KB |
Partially correct |
10 |
Partially correct |
3 ms |
5376 KB |
Partially correct |
11 |
Correct |
2 ms |
5376 KB |
Output is correct |
12 |
Correct |
2 ms |
5376 KB |
Output is correct |
13 |
Correct |
18 ms |
5376 KB |
Output is correct |
14 |
Correct |
2 ms |
5376 KB |
Output is correct |
15 |
Partially correct |
2 ms |
5376 KB |
Partially correct |
16 |
Correct |
2 ms |
5376 KB |
Output is correct |
17 |
Correct |
2 ms |
5376 KB |
Output is correct |
18 |
Runtime error |
2359 ms |
65536 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
19 |
Correct |
19 ms |
65536 KB |
Output is correct |
20 |
Runtime error |
2230 ms |
65536 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |