This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int n, r;
int t;
void one_round(vector<int> &archers) {
vector<int> narchers(archers.begin(), archers.end());
for (int i = 2; i <= n; i++) {
if (archers[2 * (i - 1)] < archers[2 * (i - 1) + 1]) {
narchers[2 * (i - 2) + 1] = archers[2 * (i - 1)];
narchers[2 * (i - 1)] = archers[2 * (i - 1) + 1];
} else {
narchers[2 * (i - 2) + 1] = archers[2 * (i - 1) + 1];
narchers[2 * (i - 1)] = archers[2 * (i - 1)];
}
}
if (archers[0] < archers[1]) {
narchers[2 * (n - 1) + 1] = archers[1];
narchers[0] = archers[0];
} else {
narchers[2 * (n - 1) + 1] = archers[0];
narchers[0] = archers[1];
}
swap(archers, narchers);
}
void tournament(vector<int> &archers) {
r %= (n - 1) * n;
for (int i = 0; i < r; i++) {
one_round(archers);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> r;
int me;
cin >> me;
vector<int> archers;
for (int i = 2; i <= 2 * n; i++) {
int x;
cin >> x;
archers.push_back(x);
}
int ans = -1;
int mn = 2 * n + 1;
for (int i = 0; i < 2 * n; i++) {
vector<int> tmp = archers;
tmp.insert(tmp.begin() + i, me);
tournament(tmp);
int ending = find(tmp.begin(), tmp.end(), me) - tmp.begin();
if (ending <= mn) {
mn = ending;
ans = i / 2 + 1;
}
}
cout << ans << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |