-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtournament.cpp
More file actions
47 lines (35 loc) · 1.12 KB
/
tournament.cpp
File metadata and controls
47 lines (35 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// NOTE: it is recommended to use this even if you don't understand the following code.
#include <fstream>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
int main() {
// uncomment the two following lines if you want to read/write from files
// ifstream cin("input.txt");
// ofstream cout("output.txt");
int N;
cin >> N;
vector<int> P(N);
for (int i = 0; i < N; ++i)
cin >> P[i];
int winner = 0, runnerup = 0;
// INSERT YOUR CODE HERE
int temp, p;
vector<vector<int>> ans(log2(N), vector<int> (N, 0));
ans[0] = P;
for (int r=1; r<log2(N); r++) {
fill(ans[r].begin(), ans[r].end(), 0);
p = 0;
for (int i=0; i<N; i+=2) {
temp = max(ans[r-1][i], ans[r-1][i+1]);
ans[r][p] = temp;
p ++;
}
}
winner = find(P.begin(), P.end(), max(ans[ans.size()-1][0], ans[ans.size()-1][1])) - P.begin();
runnerup = find(P.begin(), P.end(), min(ans[ans.size()-1][0], ans[ans.size()-1][1])) - P.begin();
cout << winner << " " << runnerup << endl;
return 0;
}