Submission #235187

#TimeUsernameProblemLanguageResultExecution timeMemory
235187NONAMEDoktor (COCI17_doktor)C++17
100 / 100
395 ms42872 KiB
#include <bits/stdc++.h> #define sz(x) int(x.size()) #define N 5 * 100500 #define pb push_back #define mp make_pair #define ft first #define sd second #define el '\n' using namespace std; int n, pf[N], a[N], ans, al = 0, ar = 0; vector <pair <int, int> > v[2 * N]; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; a[i]--; pf[i] = (i - 1 < 0) ? 0 : pf[i - 1]; pf[i] += (a[i] == i); } for (int i = 0; i < n; i++) { int l = i, r = a[i]; if (l > r) swap(l, r); v[l + r].pb(mp(l, r)); } for (int i = 0; i < 2 * n; i++) { sort(v[i].rbegin(), v[i].rend()); for (int j = 0; j < sz(v[i]); j++) { int l = v[i][j].ft, r = v[i][j].sd; int cur = (j + 1) + (pf[n - 1] - pf[r]) + (l - 1 < 0 ? 0 : pf[l - 1]); if (cur > ans) { al = l; ar = r; ans = cur; } } } cerr << ans << el; cout << a[al] + 1 << ' ' << a[ar] + 1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...