# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
52132 | EntityIT | Doktor (COCI17_doktor) | C++14 | 289 ms | 61624 KiB |
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>
using namespace std;
#define int long long
const int N = 500005;
int n, a[N], maxx = -N, pter1, pter2, sum[N];
vector<int> vec[N][2];
signed main () {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i], sum[i] = sum[i - 1] + (a[i] == i);
if ( (a[i] + i) % 2) vec[(a[i] + i) / 2][1].push_back(abs(a[i] - i));
else vec[(a[i] + i) / 2][0].push_back(abs(a[i] - i));
}
for (int i = 1; i <= n; ++i) {
sort(vec[i][0].begin(), vec[i][0].end() );
sort(vec[i][1].begin(), vec[i][1].end() );
}
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < vec[i][0].size(); ++j) {
int radius = vec[i][0][j];
int res = j + sum[i - radius / 2 - 1] + sum[n] - sum[i + radius / 2];
if (maxx < res) {
maxx = res;
pter1 = i - radius / 2;
pter2 = i + radius / 2;
}
}
}
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < vec[i][1].size(); ++j) {
int radius = vec[i][1][j];
int res = j + sum[i - radius / 2 - 1] + sum[n] - sum[i + radius / 2 + 1];
if (maxx < res) {
maxx = res;
pter1 = i - radius / 2;
pter2 = i + radius / 2 + 1;
}
}
}
cout << a[pter1] << ' ' << a[pter2];
return 0;
}
Compilation message (stderr)
# | 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... |