Submission #473203

# Submission time Handle Problem Language Result Execution time Memory
473203 2021-09-15T10:10:32 Z _L__ Doktor (COCI17_doktor) C++17
0 / 100
404 ms 21052 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 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;}
    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;}
    ll a_1 = ans_odd, a_2 = ans_odd, a_3 = ans_even, a_4 = ans_even+1; int i = a_1, j = a_2;
    while(i > 0 && j <= n){
        if(a[i] == i+ans_odd){a_1 = i, a_2 = j;}
        if(a[j] == j-ans_odd){a_1 = i, a_2 = j;}
        --i; ++j;
    }
    i = a_3, j = a_4;
    while(i > 0 && j <= n){
        if(a[i] == ans_even+((ans_even-i)*2)){a_3 = i, a_4 = j;}
        if(a[j] == (j-(ans_even+1))*2+ans_even+1){a_3 = i, a_4 = j;}
        ++j, --i;
    }
    if(a_3 == 0 || a_4 == 0){a_3 = 0; a_4 = 0;}
    ll sum1 = 0, sum2 = 0;
    reverse(a+a_1, a+a_2+1);
    for(int i = 1; i <= n; ++i) sum1 += (a[i] == i);
    reverse(a+a_1, a+a_2+1);
    reverse(a+a_3, a+a_4+1);
    for(int i = 1; i <= n; ++i) sum2 += (a[i] == i);
    reverse(a+a_3, a+a_4+1);
    if(sum1 >= sum2) cout << a[a_1] << ' ' << a[a_2] << endl;
    else cout << a[a_3] << ' ' << a[a_4] << endl;
} 
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 4076 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 404 ms 21052 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 165 ms 12416 KB Output isn't correct
2 Halted 0 ms 0 KB -