QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#326852#6627. Line Towntybbs#0 1ms7664kbC++141.1kb2024-02-14 09:47:522024-07-04 03:23:54

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 03:23:54]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:7664kb
  • [2024-02-14 09:47:52]
  • 提交

answer

#include<bits/stdc++.h>
#define mp make_pair
using namespace std;
const int N=5e5+5;
int a[N];
int pre[N],suf[N];
inline void upd(int &x,int val){
	if(x==-1) x=val;
	else x=min(x,val);
}
int main(){
	int n;cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int st=1;
	vector<pair<int,int> > len;
	for(int i=2;i<=n;i++){
		if(a[i]!=a[i-1]){
			len.push_back(mp(i-st,a[i-1]));
			st=i;
		}
	}
	len.push_back(mp(n+1-st,a[n]));
	int siz=len.size();
	for(int i=0;i<siz;i++){
		if(i) pre[i]=pre[i-1];
		if(len[i].second==1){
			if(len[i].first%2==1){
				pre[i]=-1;
			}
			else if(pre[i]!=-1){
				pre[i]+=len[i].first/2;
			}
		}
	}
	for(int i=siz-1;i>=0;i--){
		if(i!=siz-1) suf[i]=suf[i+1];
		if(len[i].second==-1){
			if(len[i].first%2==1){
				suf[i]=-1;
			}
			else if(suf[i]!=-1){
				suf[i]+=len[i].first/2;
			}
		}
	}
	int ans=-1;
	for(int i=0;i<siz;i++){
		if(i==0){
			if(suf[i]!=-1){
				upd(ans,suf[i]);
			}
		}
		else if(i==siz){
			if(pre[i-1]!=-1){
				upd(ans,pre[i-1]);
			}
		}
		else{
			if(pre[i-1]!=-1 && suf[i]!=-1){
				upd(ans,pre[i-1]+suf[i]);
			}
		}
	}
	cout<<ans;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 3
Accepted
time: 1ms
memory: 7664kb

input:

10
1 1 1 1 1 -1 -1 -1 1 -1

output:

-1

result:

ok 1 number(s): "-1"

Test #2:

score: -3
Wrong Answer
time: 1ms
memory: 5632kb

input:

10
1 1 1 1 1 1 -1 1 1 -1

output:

-1

result:

wrong answer 1st numbers differ - expected: '3', found: '-1'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Wrong Answer

Test #60:

score: 0
Wrong Answer
time: 1ms
memory: 5632kb

input:

10
3 10 5 -9 7 2 -6 1 8 0

output:

0

result:

wrong answer 1st numbers differ - expected: '-1', found: '0'

Subtask #6:

score: 0
Skipped

Dependency #5:

0%

Subtask #7:

score: 0
Skipped

Dependency #3:

0%

Subtask #8:

score: 0
Skipped

Dependency #1:

0%