Submission #886706

#TimeUsernameProblemLanguageResultExecution timeMemory
886706vjudge1Doktor (COCI17_doktor)C++17
50 / 100
1059 ms25228 KiB
#include <bits/stdc++.h> using namespace std; using i64 = long long; #define ONLINE_JUDGE void solve() { int n; cin >> n; vector <int> v(n +1); for(int i = 1; i <= n; i++) { cin >> v[i]; } vector <int> pref(n +2), suf(n +2); for(int i = 1; i <= n; i++) { pref[i] = pref[i -1] + (v[i] == i); } for(int i = n; i >= 1; i--) { suf[i] = suf[i +1] + (v[i] == i); } vector <int> c(n +1); for(int i = 1; i <= n; i++) { c[i] = (v[i] - i) + 2 * i; cerr << c[i] << " \n"[i == n]; } array <int, 3> ans = {-1, 0, 0}; for(int l = 1; l <= n; l++) { map <int, int> mp; for(int r = l; r <= n; r++) { mp[c[r]]++; int calc = pref[l -1] + mp[r + l] + suf[r +1]; //cerr << l << " " << r << " :: " << calc << " -> " << pref[l -1] << " " << mp[r + l] << " " << suf[r +1] << "\n"; if(calc >= ans[0]) { ans = {calc, v[l], v[r]}; } } } cout << ans[1] << " " << ans[2]; return; } signed main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; //cin >> t; for(int i = 1; i <= t; i++) { solve(); } return 0; }
#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...