QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#117245 | #6627. Line Town | pandapythoner# | 0 | 1ms | 3640kb | C++20 | 1.3kb | 2023-06-30 19:18:30 | 2024-05-31 18:43:36 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
mt19937 rnd(234);
const ll inf = 1e18;
int n;
vector<ll> h;
ll solve_abs_1(){
vector<int> a(n + 2);
a[0] = 0;
a[n + 1] = 1;
for(int i = 0; i < n; i += 1){
if(h[i] < 0){
a[i + 1] = 0;
} else{
a[i + 1] = 1;
}
}
vector<int> d(n + 1);
for(int i = 0; i <= n; i += 1){
d[i] = (a[i] ^ a[i + 1]);
}
vector<int> stck;
int rs = 0;
for(int i = 0; i <= n; i += 1){
if(d[i]){
if(!stck.empty() && stck.back() % 2 == i % 2){
rs += (i - stck.back()) / 2;
stck.pop_back();
} else{
stck.push_back(i);
}
}
}
if((int)stck.size() != 1){
return -1;
}
return rs;
}
int32_t main(){
if(1){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
cin >> n;
h.resize(n);
for(int i = 0; i < n; i += 1){
cin >> h[i];
}
cout << solve_abs_1() << "\n";
return 0;
}
/*
4
1 -1 1 -1
4
1 1 -1 -1
*/
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: 3576kb
input:
10 1 1 1 1 1 -1 -1 -1 1 -1
output:
-1
result:
ok 1 number(s): "-1"
Test #2:
score: 0
Wrong Answer
time: 1ms
memory: 3640kb
input:
10 1 1 1 1 1 1 -1 1 1 -1
output:
4
result:
wrong answer 1st numbers differ - expected: '3', found: '4'
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: 0ms
memory: 3616kb
input:
10 3 10 5 -9 7 2 -6 1 8 0
output:
3
result:
wrong answer 1st numbers differ - expected: '-1', found: '3'
Subtask #6:
score: 0
Skipped
Dependency #5:
0%
Subtask #7:
score: 0
Skipped
Dependency #3:
0%
Subtask #8:
score: 0
Skipped
Dependency #1:
0%