답안 #967994

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
967994 2024-04-23T06:40:04 Z weakweakweak Line Town (CCO23_day1problem3) C++17
0 / 25
1 ms 4444 KB
#include <bits/stdc++.h>
using namespace std;

int n, a[500010], pre[500100], suf[500100];

int main () {
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n;
    bool y = 1;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i <= n; i++) pre[i] = suf[i] = INT_MAX / 3;
    pre[0] = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] == -1) pre[i] = pre[i - 1];
        if (i > 1 and a[i] == 1 and a[i - 1] == 1) pre[i] = min(pre[i], pre[i - 2] + 1);
    }
    suf[0] = 0;
    for (int i = 1; i <= n; i++) {
        int j = n + 1 - i;
        if (a[j] == 1) suf[i] = suf[i - 1];
        if (i > 1 and a[j] == -1 and a[j + 1] == -1) suf[i] = min(suf[i], suf[i - 2] + 1); 
    }

    int ans = INT_MAX / 2;
    for (int i = 0; i <= n; i++) ans = min(ans, suf[i] + pre[n - i]);

    if (ans > n * 5) ans = -1;
    cout << ans << '\n';
return 0;}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:9:10: warning: unused variable 'y' [-Wunused-variable]
    9 |     bool y = 1;
      |          ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -