Submission #1067941

#TimeUsernameProblemLanguageResultExecution timeMemory
1067941thinknoexitArchery (IOI09_archery)C++17
2 / 100
29 ms604 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; const int N = 404; int a[2 * N]; int val[N][2]; int mx[N]; int n, r, rnk; int cal() { for (int i = 0;i < n;i++) { val[i][0] = min(a[2 * i], a[2 * i + 1]); val[i][1] = max(a[2 * i], a[2 * i + 1]); } bool ch = 1; int nowr = r; do { ch = 1; for (int i = 0;i < n;i++) { if (i == 0) swap(val[i][0], val[i][1]); mx[i] = val[i][0]; } for (int i = 0;i < n;i++) { val[i][0] = mx[(i + 1) % n]; if (val[i][0] > val[i][1]) swap(val[i][0], val[i][1]); if (i == 0 && val[i][0] != 1) ch = 0; if (i != 0 && val[i][1] <= n + 1) ch = 0; } nowr--; } while (nowr && !ch); for (int i = 0;i < n;i++) if (val[i][0] == rnk || val[i][1] == rnk) return (i + nowr) % n; return -1; } int main() { cin.tie(nullptr)->sync_with_stdio(false); cin >> n >> r; for (int i = 0;i < 2 * n;i++) cin >> a[i]; rnk = a[0]; int mn = n, idx = -1; for (int i = 0;i < 2 * n;i += 2) { if (i) swap(a[i], a[i - 2]); int val = cal(); if (val <= mn) { mn = val; idx = i / 2; } } cout << idx + 1 << '\n'; return 0; } /* 7 4 2 6 5 8 1 3 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...