답안 #82229

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
82229 2018-10-29T14:45:26 Z Leonardo_Paes Doktor (COCI17_doktor) C++11
60 / 100
1000 ms 2356 KB
#include <bits/stdc++.h>

using namespace std;

#define MAXN 100100

int vet[MAXN], pos[MAXN], ans[MAXN], pre[MAXN];

pair<int,int> ans2[MAXN];
int main(){

    int n;

    cin >> n;

    for(int i=1; i<=n; i++){
        cin >> vet[i];
        pos[vet[i]]=i;
    }

    for(int i=1; i<=n; i++){
        if(vet[i]==i){
            pre[i]++;
        }
        pre[i]+=pre[i-1];
        //cout << pre[i] << " ";
    }

    for(int i=1; i<=n; i++){
        if(pos[i] == i){
            ans[i] = pre[n];
            ans2[i] = {i,i};
        }
        if(pos[i] < i){
            int atual = 0;
            for(int x = pos[i], u=0; x<=i; x++, u++){
                if(vet[x]+u==vet[pos[i]]){
                    atual++;
                }
            }
            ans2[i] = {i, vet[i]};
            ans[i]=atual;
            // antes
            ans[i]+=pre[pos[i]-1];
            //depois
            ans[i]+=pre[n]-pre[i];
        }
        if(pos[i] > i){
            int atual = 0;
            for(int x = pos[i], u=0; x>=i; x--, u++){
                if(vet[x]-u==vet[pos[i]]){
                    atual++;
                }
            }
            ans2[i] = {vet[i], i};
            ans[i]=atual;
            //antes
            ans[i]+=pre[i-1];
            //depois
            ans[i]+=pre[n]-pre[pos[i]];
        }
    }
    int resp = 1;
    int idx;
    for(int i=1; i<=n; i++){
        if(ans[i]>resp){
            resp=ans[i];
            idx = i;
        }
    }

    cout << ans2[idx].first << " " << ans2[idx].second << endl;
}

Compilation message

doktor.cpp: In function 'int main()':
doktor.cpp:72:49: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
     cout << ans2[idx].first << " " << ans2[idx].second << endl;
                                                 ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 448 KB Output is correct
2 Correct 2 ms 528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 528 KB Output is correct
2 Correct 4 ms 660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 660 KB Output is correct
2 Correct 5 ms 660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 660 KB Output is correct
2 Correct 3 ms 660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 816 KB Output is correct
2 Runtime error 2 ms 816 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1079 ms 2356 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 2356 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 2356 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -