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>
#define N 5 * 100500
using namespace std;
int n, pf[N], a[N], ans, al = 0, ar = 0;
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);
int cur = ((l - 1 < 0) ? 0 : pf[l - 1]) + (pf[n - 1] - pf[r]);
while (l < r) {
cur += (a[l] == r);
cur += (a[r] == l);
l++, r--;
}
if (l == r && a[l] == l)
cur++;
if (cur > ans) {
ans = cur;
al = i;
ar = a[i];
}
}
if (al > ar)
swap(al, ar);
cout << a[al] + 1 << ' ' << a[ar] + 1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |