Submission #44567

# Submission time Handle Problem Language Result Execution time Memory
44567 2018-04-03T10:15:39 Z heon Izbori (COCI17_izbori) C++11
48 / 80
3 ms 636 KB
#include<bits/stdc++.h>

using namespace std;

int n,m,k;
vector <int> vec[105];

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 currentwinner(){
	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;
		}
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			if(vec[i][j] == win){
				vec[i].erase(vec[i].begin() + j);
				break;
			}
		}
	}
	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;
	while(currentwinner() != k){
		izbaceni++;
	}
	cout << originalwinner << 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 currentwinner()':
izbori.cpp:45:9: warning: 'win' may be used uninitialized in this function [-Wmaybe-uninitialized]
  return win;
         ^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Partially correct 2 ms 376 KB Partially correct
4 Partially correct 2 ms 428 KB Partially correct
5 Partially correct 2 ms 428 KB Partially correct
6 Partially correct 2 ms 460 KB Partially correct
7 Partially correct 2 ms 460 KB Partially correct
8 Partially correct 2 ms 520 KB Partially correct
9 Partially correct 3 ms 520 KB Partially correct
10 Partially correct 2 ms 520 KB Partially correct
11 Correct 2 ms 616 KB Output is correct
12 Correct 2 ms 616 KB Output is correct
13 Partially correct 2 ms 620 KB Partially correct
14 Partially correct 3 ms 620 KB Partially correct
15 Partially correct 3 ms 620 KB Partially correct
16 Partially correct 2 ms 620 KB Partially correct
17 Partially correct 2 ms 636 KB Partially correct
18 Partially correct 2 ms 636 KB Partially correct
19 Partially correct 2 ms 636 KB Partially correct
20 Partially correct 2 ms 636 KB Partially correct