Submission #116983

# Submission time Handle Problem Language Result Execution time Memory
116983 2019-06-14T10:48:27 Z FutymyClone Doktor (COCI17_doktor) C++14
100 / 100
268 ms 44704 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 5e5 + 5;

int n, a[N], f[N], p[N];
vector <pair <int, int> > vec[N + N];

int main(){
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= n; i++) {
        int x = i - a[i];
        p[a[i]] = i;
        vec[2 * i - 1 - x].push_back({min(i, a[i]), max(i, a[i])});
        f[i] = f[i - 1] + (a[i] == i);
    }

    int Max = -1, ans1 = 0, ans2 = 0;
    for (int i = 1; i <= 2 * n - 1; i++) {
        sort(vec[i].begin(), vec[i].end(), greater <pair <int, int> >());
        for (int j = 0; j < vec[i].size(); j++) {
            int res = j + 1 - (f[vec[i][j].second] - f[vec[i][j].first - 1]);
            if (res > Max) {
                Max = res;
                ans1 = a[vec[i][j].first];
                ans2 = a[vec[i][j].second];
            }
        }
    }

    if (p[ans1] > p[ans2]) swap(ans1, ans2);
    cout << ans1 << " " << ans2;
    return 0;
}

Compilation message

doktor.cpp: In function 'int main()':
doktor.cpp:23:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < vec[i].size(); j++) {
                         ~~^~~~~~~~~~~~~~~
doktor.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
doktor.cpp:12:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
                                  ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 22 ms 23936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 23808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 23808 KB Output is correct
2 Correct 21 ms 23800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 23936 KB Output is correct
2 Correct 22 ms 23932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 24056 KB Output is correct
2 Correct 22 ms 23916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 23928 KB Output is correct
2 Correct 24 ms 23808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 24192 KB Output is correct
2 Correct 95 ms 31336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 27000 KB Output is correct
2 Correct 58 ms 26480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 268 ms 41252 KB Output is correct
2 Correct 141 ms 34028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 164 ms 34072 KB Output is correct
2 Correct 113 ms 44704 KB Output is correct