# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
792563 |
2023-07-25T06:57:33 Z |
이동현(#10054) |
Line Town (CCO23_day1problem3) |
C++17 |
|
2000 ms |
8424 KB |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define int long long
using namespace std;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
vector<int> zp;
for(int i = 0; i < n; ++i){
cin >> a[i];
if(!a[i]){
zp.push_back(i);
}
}
int ans = (int)1e18;
for(int i = 0; i + (int)zp.size() <= n; ++i){
int now = 0;
for(int j = 0; j < (int)zp.size(); ++j){
now += abs(i + j - zp[j]);
}
vector<deque<int>> vc(2);
for(int j = 0; j < n; ++j){
if(a[j]) vc[j % 2 ^ (a[j] == -1)].push_back(j);
}
for(int j = 0; j < n; ++j){
if(j >= i && j < i + (int)zp.size()){
continue;
}
int bt = ((j % 2) ^ (j < i));
if(!(int)vc[bt].size()){
now = (int)1e18;
break;
}
now += abs(j - vc[bt].front());
vc[bt].pop_front();
}
// cout << i << ' ' << now << endl;
assert(now % 2 == 0);
ans = min(ans, now / 2);
}
if(ans > (int)1e17){
ans = -1;
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
28 ms |
340 KB |
Output is correct |
5 |
Correct |
28 ms |
340 KB |
Output is correct |
6 |
Correct |
36 ms |
340 KB |
Output is correct |
7 |
Correct |
37 ms |
340 KB |
Output is correct |
8 |
Correct |
28 ms |
340 KB |
Output is correct |
9 |
Correct |
30 ms |
340 KB |
Output is correct |
10 |
Correct |
28 ms |
340 KB |
Output is correct |
11 |
Correct |
28 ms |
340 KB |
Output is correct |
12 |
Correct |
28 ms |
348 KB |
Output is correct |
13 |
Correct |
29 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
28 ms |
340 KB |
Output is correct |
5 |
Correct |
28 ms |
340 KB |
Output is correct |
6 |
Correct |
36 ms |
340 KB |
Output is correct |
7 |
Correct |
37 ms |
340 KB |
Output is correct |
8 |
Correct |
28 ms |
340 KB |
Output is correct |
9 |
Correct |
30 ms |
340 KB |
Output is correct |
10 |
Correct |
28 ms |
340 KB |
Output is correct |
11 |
Correct |
28 ms |
340 KB |
Output is correct |
12 |
Correct |
28 ms |
348 KB |
Output is correct |
13 |
Correct |
29 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Execution timed out |
2047 ms |
8424 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
28 ms |
340 KB |
Output is correct |
5 |
Correct |
28 ms |
340 KB |
Output is correct |
6 |
Correct |
36 ms |
340 KB |
Output is correct |
7 |
Correct |
37 ms |
340 KB |
Output is correct |
8 |
Correct |
28 ms |
340 KB |
Output is correct |
9 |
Correct |
30 ms |
340 KB |
Output is correct |
10 |
Correct |
28 ms |
340 KB |
Output is correct |
11 |
Correct |
28 ms |
340 KB |
Output is correct |
12 |
Correct |
28 ms |
348 KB |
Output is correct |
13 |
Correct |
29 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
28 ms |
340 KB |
Output is correct |
5 |
Correct |
28 ms |
340 KB |
Output is correct |
6 |
Correct |
36 ms |
340 KB |
Output is correct |
7 |
Correct |
37 ms |
340 KB |
Output is correct |
8 |
Correct |
28 ms |
340 KB |
Output is correct |
9 |
Correct |
30 ms |
340 KB |
Output is correct |
10 |
Correct |
28 ms |
340 KB |
Output is correct |
11 |
Correct |
28 ms |
340 KB |
Output is correct |
12 |
Correct |
28 ms |
348 KB |
Output is correct |
13 |
Correct |
29 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Execution timed out |
2047 ms |
8424 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
28 ms |
340 KB |
Output is correct |
5 |
Correct |
28 ms |
340 KB |
Output is correct |
6 |
Correct |
36 ms |
340 KB |
Output is correct |
7 |
Correct |
37 ms |
340 KB |
Output is correct |
8 |
Correct |
28 ms |
340 KB |
Output is correct |
9 |
Correct |
30 ms |
340 KB |
Output is correct |
10 |
Correct |
28 ms |
340 KB |
Output is correct |
11 |
Correct |
28 ms |
340 KB |
Output is correct |
12 |
Correct |
28 ms |
348 KB |
Output is correct |
13 |
Correct |
29 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
28 ms |
340 KB |
Output is correct |
5 |
Correct |
28 ms |
340 KB |
Output is correct |
6 |
Correct |
36 ms |
340 KB |
Output is correct |
7 |
Correct |
37 ms |
340 KB |
Output is correct |
8 |
Correct |
28 ms |
340 KB |
Output is correct |
9 |
Correct |
30 ms |
340 KB |
Output is correct |
10 |
Correct |
28 ms |
340 KB |
Output is correct |
11 |
Correct |
28 ms |
340 KB |
Output is correct |
12 |
Correct |
28 ms |
348 KB |
Output is correct |
13 |
Correct |
29 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Execution timed out |
2047 ms |
8424 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |