답안 #52132

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
52132 2018-06-24T06:14:54 Z EntityIT Doktor (COCI17_doktor) C++14
100 / 100
289 ms 61624 KB
#include<bits/stdc++.h>

using namespace std;

#define int long long

const int N = 500005;
int n, a[N], maxx = -N, pter1, pter2, sum[N];
vector<int> vec[N][2];

signed main () {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i], sum[i] = sum[i - 1] + (a[i] == i);
        if ( (a[i] + i) % 2) vec[(a[i] + i) / 2][1].push_back(abs(a[i] - i));
        else vec[(a[i] + i) / 2][0].push_back(abs(a[i] - i));
    }
    for (int i = 1; i <= n; ++i) {
        sort(vec[i][0].begin(), vec[i][0].end() );
        sort(vec[i][1].begin(), vec[i][1].end() );
    }

    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j < vec[i][0].size(); ++j) {
            int radius = vec[i][0][j];
            int res = j + sum[i - radius / 2 - 1] + sum[n] - sum[i + radius / 2];
            if (maxx < res) {
                maxx = res;
                pter1 = i - radius / 2;
                pter2 = i + radius / 2;
            }
        }
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j < vec[i][1].size(); ++j) {
            int radius = vec[i][1][j];
            int res = j + sum[i - radius / 2 - 1] + sum[n] - sum[i + radius / 2 + 1];
            if (maxx < res) {
                maxx = res;
                pter1 = i - radius / 2;
                pter2 = i + radius / 2 + 1;
            }
        }
    }

    cout << a[pter1] << ' ' << a[pter2];

    return 0;
}

Compilation message

doktor.cpp: In function 'int main()':
doktor.cpp:25:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < vec[i][0].size(); ++j) {
                         ~~^~~~~~~~~~~~~~~~~~
doktor.cpp:36:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < vec[i][1].size(); ++j) {
                         ~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 23800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 24048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 24048 KB Output is correct
2 Correct 22 ms 24048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 24076 KB Output is correct
2 Correct 22 ms 24264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 24284 KB Output is correct
2 Correct 23 ms 24284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 24372 KB Output is correct
2 Correct 23 ms 24372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 24700 KB Output is correct
2 Correct 112 ms 34620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 34620 KB Output is correct
2 Correct 48 ms 34620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 289 ms 49992 KB Output is correct
2 Correct 148 ms 49992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 218 ms 49992 KB Output is correct
2 Correct 134 ms 61624 KB Output is correct