QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#121673#6627. Line Townkshitij_sodani0 1ms3492kbC++141019b2023-07-08 17:15:402023-07-08 17:15:44

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-08 17:15:44]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3492kb
  • [2023-07-08 17:15:40]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define a first
#define b second
#define pb push_back
typedef long long llo;
#define endl '\n'


llo it[500001];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	llo n;
	cin>>n;
	llo su=0;
	vector<llo> ss;
	vector<llo> tt;
	for(llo i=0;i<n;i++){
		cin>>it[i];
		if(it[i]==-1){
			if(i%2==0){
				su--;
				ss.pb(i);
			}
			else{
				su++;
				tt.pb(i);
			}
		}
	}
	if(su<-1 or su>0){
		cout<<-1<<endl;
		return 0;
	}
	llo ans=0;
	if(su==0){
		llo st=1;
		for(llo i=0;i<ss.size();i++){
			if(st==1){
				if(ss[i]==i*2){
					ans+=(tt[i]-ss[i]-1);
					continue;
				}
				st=0;
			}
			ans+=(abs(tt[i]-ss[i]));
		}
		cout<<ans<<endl;
		return 0;
	}
	ans+=(ss[0]);
	int st=1;
	for(llo i=0;i<tt.size();i++){
		if(st==1){
			if(tt[i]==i*2+1){
				ans+=(ss[i+1]-tt[i]-1);
				continue;
			}
			st=0;
		}
		ans+=(abs(tt[i]-ss[i+1]));
	}
	cout<<ans<<endl;



	

	








	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

input:

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

output:

-1

result:

ok 1 number(s): "-1"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3492kb

input:

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

output:

3

result:

ok 1 number(s): "3"

Test #3:

score: 0
Accepted
time: 1ms
memory: 3380kb

input:

1
-1

output:

0

result:

ok 1 number(s): "0"

Test #4:

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

input:

2000
1 -1 -1 -1 -1 -1 1 -1 1 1 1 -1 -1 -1 1 1 -1 1 1 -1 -1 1 -1 -1 1 -1 1 -1 1 1 -1 1 -1 -1 1 -1 -1 -1 -1 1 -1 -1 -1 1 -1 -1 1 1 -1 -1 1 -1 -1 -1 1 -1 -1 1 1 -1 -1 -1 1 1 -1 1 -1 1 1 -1 -1 -1 1 1 1 -1 1 1 -1 -1 1 -1 1 1 1 1 -1 -1 -1 1 1 -1 -1 1 1 1 -1 -1 -1 -1 1 -1 -1 1 1 -1 1 -1 1 -1 -1 -1 1 -1 -1 ...

output:

15675

result:

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

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: 3456kb

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%