Submission #132826

#TimeUsernameProblemLanguageResultExecution timeMemory
132826OrtDoktor (COCI17_doktor)C++11
80 / 100
309 ms48888 KiB
#include<iostream> #include<algorithm> #include<vector> #define MAX 500005 using namespace std; int n, x, soll, solr, sol; int arr[MAX], indx[MAX], lef[MAX], righ[MAX]; vector<vector<int> > a; int main() { cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit); cin >> n; a.resize(n*2+1); for(int i=1;i<=n;i++) { cin >> arr[i]; indx[arr[i]] = i; a[i+arr[i]].push_back(i); } for(int i=0;i<a.size();i++) sort(a[i].begin(),a[i].end()); for(int i=1;i<=n;i++) righ[i] = righ[i-1]+(arr[i]==i); for(int i=n;i>0;i--) lef[i] = lef[i+1]+(arr[i]==i); for(int i=1;i<=n;i++) { int l=i, r=indx[i]; int f = (upper_bound(a[l+r].begin(),a[l+r].end(),r) - lower_bound(a[l+r].begin(),a[l+r].end(),l)); if(righ[l]+lef[r]+f > sol) {soll = l; solr = r; sol = righ[l]+lef[r]+f;} } cout << arr[soll] << " " << arr[solr]; return 0; }

Compilation message (stderr)

doktor.cpp: In function 'int main()':
doktor.cpp:21:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<a.size();i++) sort(a[i].begin(),a[i].end());
              ~^~~~~~~~~
#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...