Submission #792547

# Submission time Handle Problem Language Result Execution time Memory
792547 2023-07-25T06:48:14 Z 이동현(#10054) Line Town (CCO23_day1problem3) C++17
0 / 25
1 ms 468 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, one;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        if(!a[i]){
            zp.push_back(i);
        }
        else{
            one.push_back(a[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 < (int)one.size(); ++j){
            int pos = j;
            if(j >= i){
                pos += (int)zp.size();
            }
            vc[pos % 2 ^ (a[pos] == -1)].push_back(pos);
        }

        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();
        }

        assert(now % 2 == 0);
        ans = min(ans, now / 2);
    }

    if(ans == (int)1e18){
        ans = -1;
    }

    cout << ans << '\n';
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
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 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -