Submission #792560

# Submission time Handle Problem Language Result Execution time Memory
792560 2023-07-25T06:55:57 Z 이동현(#10054) Line Town (CCO23_day1problem3) C++17
3 / 25
2000 ms 8564 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){
            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 1 ms 212 KB Output is correct
4 Correct 39 ms 340 KB Output is correct
5 Correct 27 ms 356 KB Output is correct
6 Correct 28 ms 340 KB Output is correct
7 Correct 31 ms 352 KB Output is correct
8 Correct 29 ms 340 KB Output is correct
9 Correct 34 ms 340 KB Output is correct
10 Correct 39 ms 340 KB Output is correct
11 Correct 29 ms 340 KB Output is correct
12 Correct 28 ms 352 KB Output is correct
13 Correct 39 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 1 ms 212 KB Output is correct
4 Correct 39 ms 340 KB Output is correct
5 Correct 27 ms 356 KB Output is correct
6 Correct 28 ms 340 KB Output is correct
7 Correct 31 ms 352 KB Output is correct
8 Correct 29 ms 340 KB Output is correct
9 Correct 34 ms 340 KB Output is correct
10 Correct 39 ms 340 KB Output is correct
11 Correct 29 ms 340 KB Output is correct
12 Correct 28 ms 352 KB Output is correct
13 Correct 39 ms 340 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Execution timed out 2052 ms 8564 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 1 ms 212 KB Output is correct
4 Correct 39 ms 340 KB Output is correct
5 Correct 27 ms 356 KB Output is correct
6 Correct 28 ms 340 KB Output is correct
7 Correct 31 ms 352 KB Output is correct
8 Correct 29 ms 340 KB Output is correct
9 Correct 34 ms 340 KB Output is correct
10 Correct 39 ms 340 KB Output is correct
11 Correct 29 ms 340 KB Output is correct
12 Correct 28 ms 352 KB Output is correct
13 Correct 39 ms 340 KB Output is correct
14 Incorrect 0 ms 212 KB Output isn't correct
15 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 1 ms 212 KB Output is correct
4 Correct 39 ms 340 KB Output is correct
5 Correct 27 ms 356 KB Output is correct
6 Correct 28 ms 340 KB Output is correct
7 Correct 31 ms 352 KB Output is correct
8 Correct 29 ms 340 KB Output is correct
9 Correct 34 ms 340 KB Output is correct
10 Correct 39 ms 340 KB Output is correct
11 Correct 29 ms 340 KB Output is correct
12 Correct 28 ms 352 KB Output is correct
13 Correct 39 ms 340 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Execution timed out 2052 ms 8564 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 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 1 ms 212 KB Output is correct
4 Correct 39 ms 340 KB Output is correct
5 Correct 27 ms 356 KB Output is correct
6 Correct 28 ms 340 KB Output is correct
7 Correct 31 ms 352 KB Output is correct
8 Correct 29 ms 340 KB Output is correct
9 Correct 34 ms 340 KB Output is correct
10 Correct 39 ms 340 KB Output is correct
11 Correct 29 ms 340 KB Output is correct
12 Correct 28 ms 352 KB Output is correct
13 Correct 39 ms 340 KB Output is correct
14 Incorrect 0 ms 212 KB Output isn't correct
15 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 1 ms 212 KB Output is correct
4 Correct 39 ms 340 KB Output is correct
5 Correct 27 ms 356 KB Output is correct
6 Correct 28 ms 340 KB Output is correct
7 Correct 31 ms 352 KB Output is correct
8 Correct 29 ms 340 KB Output is correct
9 Correct 34 ms 340 KB Output is correct
10 Correct 39 ms 340 KB Output is correct
11 Correct 29 ms 340 KB Output is correct
12 Correct 28 ms 352 KB Output is correct
13 Correct 39 ms 340 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Execution timed out 2052 ms 8564 KB Time limit exceeded
16 Halted 0 ms 0 KB -