Submission #116881

#TimeUsernameProblemLanguageResultExecution timeMemory
116881nhimnam120Doktor (COCI17_doktor)C++14
30 / 100
1091 ms4188 KiB
#include<bits/stdc++.h> using namespace std; long long inp[500005]; signed main() { long long n; cin >> n; long long ans=0; for(int i=1;i<=n;i++){ cin >> inp[i]; if(inp[i]==i){ ans++; } } long long mdx=ans; long long pos1,pos2; for(int i=1;i<=n-1;i++) { for(int j=i+1;j<=n;j++){ long long pre=0; long long pas=0; for(int k=i;k<=j;k++){ if(inp[k]==k){ pre++; } if(inp[k]==j-(k-i)) { pas++; } } long long now=ans-pre+pas; if(now>mdx){ mdx=now; pos1=i; pos2=j; } } } if(mdx==ans){ cout << inp[1]<< " " << inp[1]; return 0; } else { cout << inp[pos1]<< " " << inp[pos2]; } }

Compilation message (stderr)

doktor.cpp: In function 'int main()':
doktor.cpp:45:38: warning: 'pos2' may be used uninitialized in this function [-Wmaybe-uninitialized]
   cout << inp[pos1]<< " " << inp[pos2];
                                      ^
doktor.cpp:45:19: warning: 'pos1' may be used uninitialized in this function [-Wmaybe-uninitialized]
   cout << inp[pos1]<< " " << inp[pos2];
                   ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...