// This code is written by _L__
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define F_word ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
typedef long long ll;
typedef long double ld;
const int mod = 1e9+7, N = 2e5+13, inf = 1e9+1;
const ld E = 1e-6;
#define ff first
#define ss second
int main(void){
F_word;
int n; cin >> n;
int a[n+2] = {}, doc[n+4] = {}; for(int i = 1; i <= n; ++i){cin >> a[i]; doc[a[i]] = a[i]-i;}a[0] = 1;
map<int, int> freq_odd, freq_even;
for(int i = 1; i <= n; ++i)
if(!(doc[a[i]]%2))
freq_odd[i+(doc[a[i]]/2)]++;
for(int i = 1; i <= n; ++i)
if(doc[a[i]]%2)
freq_even[i+(doc[a[i]]/2)-1]++;
ll ans_odd = 0, tar = 0, ans_even = 0;
for(auto u: freq_odd)
if(u.ss >= tar)
{tar = u.ss, ans_odd = u.ff;}
tar = 0;
for(auto u: freq_even)
if(u.ss >= tar)
{tar = u.ss, ans_even = u.ff;}
if(ans_even == 0 && ans_odd == 0)return cout << 1 << ' ' << 1 << endl, 0;
if(ans_even == 0){
ll a_1 = ans_odd, a_2 = ans_odd, sum = 0, i = ans_odd, j = ans_odd;
while(i > 0 && j <= n){
reverse(a+i, a+j+1); ll x = 0;
for(int k = 1; k <= n; ++k) x += (a[k] == k);
if(x >= sum){
a_1 = i, a_2 = j; sum = x;
}
reverse(a+i, a+j+1); ++j, --i;
}
cout << a[a_1] << ' ' << a[a_2] << endl;
} else if(ans_odd == 0){
ll a_3 = ans_even, a_4 = ans_even+1, sum1 = 0, i = a_3, j = a_4;
while(i > 0 && j <= n){
reverse(a+i, a+j+1); ll x = 0;
for(int k = 1; k <= n; ++k) x += (a[k] == k);
if(x >= sum1){
a_3 = i, a_4 = j; sum1 = x;
}
reverse(a+i, a+j+1); ++j, --i;
}
cout << a[a_3] << ' ' << a[a_4] << endl;
} else {
ll a_1 = ans_odd, a_2 = ans_odd, sum = 0, i = ans_odd, j = ans_odd;
while(i > 0 && j <= n){
reverse(a+i, a+j+1); ll x = 0;
for(int k = 1; k <= n; ++k) x += (a[k] == k);
if(x >= sum){
a_1 = i, a_2 = j; sum = x;
}
reverse(a+i, a+j+1); ++j, --i;
}
ll a_3 = ans_even, a_4 = ans_even+1, sum1 = 0; i = a_3, j = a_4;
while(i > 0 && j <= n){
reverse(a+i, a+j+1); ll x = 0;
for(int k = 1; k <= n; ++k) x += (a[k] == k);
if(x >= sum1){
a_3 = i, a_4 = j; sum1 = x;
}
reverse(a+i, a+j+1); ++j, --i;
}
if(sum >= sum1) cout << a[a_1] << ' ' << a[a_2] << endl;
else cout << a[a_3] << ' ' << a[a_4] << endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
332 KB |
Output is correct |
2 |
Correct |
5 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
480 KB |
Output is correct |
2 |
Correct |
8 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
119 ms |
716 KB |
Output is correct |
2 |
Execution timed out |
1084 ms |
2636 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1086 ms |
4036 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1048 ms |
20964 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1089 ms |
12404 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |