Submission #166786

# Submission time Handle Problem Language Result Execution time Memory
166786 2019-12-04T06:14:18 Z muhi1112 Doktor (COCI17_doktor) C++17
100 / 100
289 ms 45176 KB
#include <bits/stdc++.h>
using namespace std;
 
#define endl '\n'
#define f1 first
#define s2 second
#define pb push_back
#define mp make_pair
#define ll long long
#define fri(a) freopen(a,"r",stdin);
#define fro(a) freopen(a,"w",stdout);
const int N=5e5+5;

int n,ans1,ans,maxl,maxr,l,r;

int main(){
	//fri("in.txt");
	//fro("out.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	vector<int>v[2*n+5],pre(n+5,0),dizi(n+5);
	for(int i=1;i<=n;i++){
		cin>>dizi[i];
		v[dizi[i]+i].pb(abs(dizi[i]-i));
		if(dizi[i]==i)pre[i]++;
	}
	for(int i=1;i<=n;i++){
		pre[i]+=pre[i-1];
		//cout<<pre[i]<<endl;
	}
	for(int i=0;i<=2*n;i++){
		sort(v[i].begin(),v[i].end());
		for(int j=0;j<v[i].size();j++){
			l=(i-v[i][j])/2;
			r=(i+v[i][j])/2;
			ans1=j+pre[l]+pre[n]-pre[r];
			//cout<<l<<" "<<r<<" "<<ans1<<endl;
			if(ans1>ans){
				maxl=l;
				maxr=r;
				ans=ans1;
			}
		}
	}
	cout<<dizi[maxl]<<" "<<dizi[maxr]<<endl;
return 0;
}

Compilation message

doktor.cpp: In function 'int main()':
doktor.cpp:34:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0;j<v[i].size();j++){
               ~^~~~~~~~~~~~
# 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 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 684 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 632 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1144 KB Output is correct
2 Correct 90 ms 19876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 7800 KB Output is correct
2 Correct 30 ms 7036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 289 ms 41160 KB Output is correct
2 Correct 150 ms 33392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 143 ms 23928 KB Output is correct
2 Correct 144 ms 45176 KB Output is correct