Submission #97831

# Submission time Handle Problem Language Result Execution time Memory
97831 2019-02-18T18:44:12 Z dalgerok Doktor (COCI17_doktor) C++17
0 / 100
281 ms 39812 KB
#include<bits/stdc++.h>
using namespace std;


const int N = 5e5 + 5;


int n, a[N], pref[N];
vector < pair < int, pair < int, int > > > q[2 * N];


int main(){
    srand(time(nullptr));
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        pref[i] = pref[i - 1] + (a[i] == i);
    }
    for(int i = 1; i <= n; i++){
        int l = i, r = a[i];
        if(l > r){
            swap(l, r);
        }
        q[l + r].push_back(make_pair(pref[r] - pref[l - 1], make_pair(l, r)));
    }
    pair < int, pair < int, int > > ans = make_pair(pref[n], make_pair(1, 1));
    for(int i = 1; i <= 2 * n; i++){
        if(q[i].empty()){
            continue;
        }
        sort(q[i].begin(), q[i].end());
        for(int j = 0; j < (int)q[i].size(); j++){
            int l = q[i][j].second.first,
                r = q[i][j].second.second;
            int val = j + 1 + pref[n] - q[i][j].first;
            ans = max(ans, make_pair(val, q[i][j].second));
        }
    }
    cout << a[ans.second.first] << " " << a[ans.second.second];
}

Compilation message

doktor.cpp: In function 'int main()':
doktor.cpp:34:17: warning: unused variable 'l' [-Wunused-variable]
             int l = q[i][j].second.first,
                 ^
doktor.cpp:35:17: warning: unused variable 'r' [-Wunused-variable]
                 r = q[i][j].second.second;
                 ^
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 23808 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 23808 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 23936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 23936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 23936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 24064 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 24184 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 58 ms 26744 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 281 ms 39812 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 171 ms 33144 KB Output isn't correct
2 Halted 0 ms 0 KB -