답안 #792554

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
792554 2023-07-25T06:53:42 Z 이동현(#10054) Line Town (CCO23_day1problem3) C++17
3 / 25
2000 ms 12444 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();
        }

        // cout << i << ' ' << now << endl;

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

    if(ans > (int)1e17){
        ans = -1;
    }

    cout << ans << '\n';
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 29 ms 340 KB Output is correct
6 Correct 29 ms 372 KB Output is correct
7 Correct 29 ms 340 KB Output is correct
8 Correct 28 ms 340 KB Output is correct
9 Correct 29 ms 340 KB Output is correct
10 Correct 33 ms 348 KB Output is correct
11 Correct 32 ms 340 KB Output is correct
12 Correct 32 ms 340 KB Output is correct
13 Correct 29 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 29 ms 340 KB Output is correct
6 Correct 29 ms 372 KB Output is correct
7 Correct 29 ms 340 KB Output is correct
8 Correct 28 ms 340 KB Output is correct
9 Correct 29 ms 340 KB Output is correct
10 Correct 33 ms 348 KB Output is correct
11 Correct 32 ms 340 KB Output is correct
12 Correct 32 ms 340 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 2058 ms 12444 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 29 ms 340 KB Output is correct
6 Correct 29 ms 372 KB Output is correct
7 Correct 29 ms 340 KB Output is correct
8 Correct 28 ms 340 KB Output is correct
9 Correct 29 ms 340 KB Output is correct
10 Correct 33 ms 348 KB Output is correct
11 Correct 32 ms 340 KB Output is correct
12 Correct 32 ms 340 KB Output is correct
13 Correct 29 ms 340 KB Output is correct
14 Incorrect 1 ms 212 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 29 ms 340 KB Output is correct
6 Correct 29 ms 372 KB Output is correct
7 Correct 29 ms 340 KB Output is correct
8 Correct 28 ms 340 KB Output is correct
9 Correct 29 ms 340 KB Output is correct
10 Correct 33 ms 348 KB Output is correct
11 Correct 32 ms 340 KB Output is correct
12 Correct 32 ms 340 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 2058 ms 12444 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 29 ms 340 KB Output is correct
6 Correct 29 ms 372 KB Output is correct
7 Correct 29 ms 340 KB Output is correct
8 Correct 28 ms 340 KB Output is correct
9 Correct 29 ms 340 KB Output is correct
10 Correct 33 ms 348 KB Output is correct
11 Correct 32 ms 340 KB Output is correct
12 Correct 32 ms 340 KB Output is correct
13 Correct 29 ms 340 KB Output is correct
14 Incorrect 1 ms 212 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 29 ms 340 KB Output is correct
6 Correct 29 ms 372 KB Output is correct
7 Correct 29 ms 340 KB Output is correct
8 Correct 28 ms 340 KB Output is correct
9 Correct 29 ms 340 KB Output is correct
10 Correct 33 ms 348 KB Output is correct
11 Correct 32 ms 340 KB Output is correct
12 Correct 32 ms 340 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 2058 ms 12444 KB Time limit exceeded
16 Halted 0 ms 0 KB -