252162026-02-18 13:22:02linhnkSzorzatország csapata (40 pont)cpp17Wrong answer 8/4021ms1436 KiB
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
using ll=long long;
int main() {
	ll n, d=0, p=0, nul=-1, egy=-1; cin>>n; vector<int> comp(n);
	priority_queue<pair<ll, pair<int, int>>> que;
	bool ketto=false;
	for(int i=0; i<n; i++){
		cin>>comp[i];
		if(abs(comp[i])==2) ketto = true;
		else if(comp[i]==1) egy=i;
		else if(comp[i]==0) nul=i;
	}
	if(n==1){
		cout<<1<<" "<<1; return 0;
	}
	int beg=-1, end;
	for(int i=0; i<=n; i++){
		if((i!=n&&comp[i]==0)||i==n){
			end=i;
			if(end-beg<2){	
				beg=end; d=0; p=0;		
				continue;
			}
			if(p%2==1){
				int a=beg+1, b=end-1, ad=0, bd=0;
				while(comp[a]>0&&a<end){
					if(comp[a]==2) ad++;
					a++;
				}
				if(a<end&&comp[a]==-2) ad++;
				while(comp[b]>0&&b>beg){
					if(comp[b]==2) bd++;
					b--;
				}
				if(b>beg&&comp[b]==-2) bd++;
				if(b>beg&&b-bd>a-ad) que.push({b-bd, {beg+1, b-1}});
				else if(a<end) que.push({a-ad, {a+1, end-1}});
			} 
			else{
				que.push({d, {beg+1, end-1}});
			}
			beg=end;
			d=0;
			p=0;
		}
		else if(abs(comp[i])==2) d++;
		if(i<n&&comp[i]<0) p++;
	}
	if(!ketto){
		if(egy!=-1) cout<<egy+1<<" "<<egy+1;
		else if(nul!=-1)cout<<nul+1<<" "<<nul+1;
		else cout<<1<<" "<<2;
	}
	else cout<<que.top().second.first+1<<" "<<que.top().second.second+1;
}
SubtaskSumTestVerdictTimeMemory
base8/40
1Accepted0/01ms512 KiB
2Wrong answer0/019ms816 KiB
3Accepted1/11ms316 KiB
4Accepted1/11ms316 KiB
5Accepted1/11ms316 KiB
6Accepted1/11ms316 KiB
7Wrong answer0/11ms316 KiB
8Wrong answer0/21ms316 KiB
9Wrong answer0/21ms316 KiB
10Wrong answer0/320ms800 KiB
11Wrong answer0/320ms1436 KiB
12Wrong answer0/318ms564 KiB
13Wrong answer0/421ms800 KiB
14Wrong answer0/417ms564 KiB
15Accepted4/418ms564 KiB
16Wrong answer0/521ms804 KiB
17Wrong answer0/519ms800 KiB