Submission #132826

# Submission time Handle Problem Language Result Execution time Memory
132826 2019-07-19T17:20:17 Z Ort Doktor (COCI17_doktor) C++11
80 / 100
309 ms 48888 KB
#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

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 time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Failed 2 ms 376 KB Checker failed - contact admins or jury
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 508 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 760 KB Output is correct
2 Correct 3 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 760 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1272 KB Output is correct
2 Correct 108 ms 22380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 8568 KB Output is correct
2 Correct 36 ms 7764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 309 ms 45700 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 169 ms 26792 KB Output is correct
2 Correct 131 ms 48888 KB Output is correct