QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#121673 | #6627. Line Town | kshitij_sodani | 0 | 1ms | 3492kb | C++14 | 1019b | 2023-07-08 17:15:40 | 2023-07-08 17:15:44 |
Judging History
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%