This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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;
^~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |