# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
473388 |
2021-09-15T13:00:22 Z |
_L__ |
Doktor (COCI17_doktor) |
C++17 |
|
506 ms |
41800 KB |
// 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 ll 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;
ll n; cin >> n;
ll a[n+2] = {}, doc[n+4] = {}, pref[n+3] = {};
for(ll i = 1; i <= n; ++i){
cin >> a[i]; doc[a[i]] = a[i]-i; pref[i] += pref[i-1]; pref[i] += (doc[a[i]] == 0);
}
a[0] = 1;
if(n <= 500){
ll sum = 0, ans1 = 1, ans2 = 1;
for(int i = 1; i <= n; ++i){
for(int j = i; j <= n; ++j){
reverse(a+i, a+j+1);
ll x = 0; for(int k = 1; k <= n; ++k) x += (a[k] == k);
if(x >= sum){
ans1 = i, ans2 = j, sum = x;
}
reverse(a+i, a+j+1);
}
}
cout << a[ans1] << ' ' << a[ans2] << endl;
return 0;
}
map<ll, ll> freq_odd, freq_even;
for(ll i = 1; i <= n; ++i){
if(!(doc[a[i]]%2))
freq_odd[(i+a[i])/2]++;
if(doc[a[i]]%2)
freq_even[(a[i]+i)/2]++;
}
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-1, j = ans_odd+1, total = (a[a_1] == a_1);
while(i > 0 && j <= n){
ll c = (a[i]+i)/2; if(c==ans_odd)++total;
c = (a[j]+j)/2; if(c==ans_odd)++total;
ll x = total+pref[i-1]+(pref[n]-pref[j]);
if(x >= sum){
a_1 = i, a_2 = j; sum = x;
}
++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-1, j = a_4+1, total = (a[a_3] == a_4) + (a[a_4] == a_3);
while(i > 0 && j <= n){
ll c = (a[i]+i)/2; if(c==ans_even)++total;
c = (a[j]+j)/2; if(c == ans_even)++total;
ll x = total+pref[i-1]+(pref[n]-pref[j]);
if(x >= sum1){
a_3 = i, a_4 = j; sum1 = x;
}
++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-1, j = ans_odd+1, total = (a[a_1] == a_1);
while(i > 0 && j <= n){
ll c = (a[i]+i)/2; if(c==ans_odd)++total;
c = (a[j]+j)/2; if(c==ans_odd)++total;
ll x = total+pref[i-1]+(pref[n]-pref[j]);
if(x >= sum){
a_1 = i, a_2 = j; sum = x;
}
++j; --i;
}
ll a_3 = ans_even, a_4 = ans_even+1, sum1 = 0; i = a_3-1, j = a_4+1, total = (a[a_3] == a_4) + (a[a_4] == a_3);
while(i > 0 && j <= n){
ll c = (a[i]+i)/2; if(c==ans_even)++total;
c = (a[j]+j)/2; if(c==ans_even)++total;
ll x = total+pref[i-1]+(pref[n]-pref[j]);
if(x >= sum1){
a_3 = i, a_4 = j; sum1 = x;
}
++j; --i;
}
if(sum > sum1) cout << a[a_1] << ' ' << a[a_2] << endl;
else cout << a[a_3] << ' ' << a[a_4] << endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
308 KB |
Output is correct |
2 |
Correct |
36 ms |
292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
588 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
972 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
46 ms |
6512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
506 ms |
34532 KB |
Output is correct |
2 |
Correct |
59 ms |
11980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
233 ms |
20208 KB |
Output is correct |
2 |
Correct |
186 ms |
41800 KB |
Output is correct |