# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
886706 |
2023-12-12T17:23:11 Z |
vjudge1 |
Doktor (COCI17_doktor) |
C++17 |
|
1000 ms |
25228 KB |
#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 time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
348 KB |
Output is correct |
2 |
Correct |
13 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
356 ms |
608 KB |
Output is correct |
2 |
Correct |
250 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1029 ms |
600 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
892 ms |
764 KB |
Output is correct |
2 |
Correct |
26 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1032 ms |
1104 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1012 ms |
8008 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1043 ms |
10960 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1059 ms |
25228 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |