답안 #892014

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
892014 2023-12-24T15:48:22 Z serifefedartar Lamps (JOI19_lamps) C++17
0 / 100
24 ms 28836 KB
#include <bits/stdc++.h>
using namespace std;
 
#define fast ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
#define f first
#define s second
#define MOD 998244353
#define LOGN 21
const ll MAXN = 1e6 + 100;

int dp[MAXN][6];
    // 0 : değişiklik yok
    // 1 : hepsi 0
    // 2 : hepsi 1
    // 3 : ters çevir
    // 4 : önce sıfırla sonra çevir
    // 5 : önce birle sonra çevir

int main() {
    fast
    int N;
    string S, T;
    cin >> N >> S >> T;

    for (int i = 0; i < N; i++)
        S[i] = (S[i] != T[i] ? '1' : '0');

    for (int i = 0; i < MAXN; i++) {
        for (int j = 0; j < 6; j++)
            dp[i][j] = 1e9;
    }
    dp[0][0] = 0;
    S = "#" + S;
    for (int i = 1; i <= N; i++) {
        if (S[i] == '1') {
            dp[i][3] = min({dp[i-1][0] + 1, dp[i-1][1] + 1, dp[i-1][2] + 1, dp[i-1][3], dp[i-1][4], dp[i-1][5]});
            if (T[i-1] == '1') {
                dp[i][2] = min({dp[i-1][0] + 1, dp[i-1][1] + 1, dp[i-1][2], dp[i-1][3] + 1, dp[i-1][4] + 1, dp[i-1][5]});
                dp[i][4] = min({dp[i-1][0] + 2, dp[i-1][1] + 1, dp[i-1][2] + 2, dp[i-1][3] + 1, dp[i-1][4], dp[i-1][5] + 1});
            } else {
                dp[i][1] = min({dp[i-1][0] + 1, dp[i-1][1], dp[i-1][2] + 1, dp[i-1][3] + 1, dp[i-1][4], dp[i-1][5] + 1});
                dp[i][5] = min({dp[i-1][0] + 2, dp[i-1][1] + 2, dp[i-1][2] + 1, dp[i-1][3] + 1, dp[i-1][4] + 1, dp[i-1][5]});
            }
        } else {
            dp[i][0] = min({dp[i-1][0], dp[i-1][1], dp[i-1][2], dp[i-1][3], dp[i-1][4], dp[i-1][5]});
            if (T[i-1] == '1') {
                dp[i][2] = min({dp[i-1][0] + 1, dp[i-1][1] + 1, dp[i-1][2], dp[i-1][3] + 1, dp[i-1][4] + 1, dp[i-1][5]});
                dp[i][4] = min({dp[i-1][0] + 2, dp[i-1][1] + 1, dp[i-1][2] + 2, dp[i-1][3] + 1, dp[i-1][4], dp[i-1][5] + 1});
            } else {
                dp[i][2] = min({dp[i-1][0] + 1, dp[i-1][1] + 1, dp[i-1][2], dp[i-1][3] + 1, dp[i-1][4] + 1, dp[i-1][5]});
                dp[i][5] = min({dp[i-1][0] + 2, dp[i-1][1] + 2, dp[i-1][2] + 1, dp[i-1][3] + 1, dp[i-1][4] + 1, dp[i-1][5]});
            }
        }
    }
    cout << min({dp[N][0], dp[N][1], dp[N][2], dp[N][3], dp[N][4]}) << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 23900 KB Output is correct
2 Correct 6 ms 23764 KB Output is correct
3 Correct 5 ms 23900 KB Output is correct
4 Correct 5 ms 23900 KB Output is correct
5 Correct 5 ms 23900 KB Output is correct
6 Correct 5 ms 23760 KB Output is correct
7 Correct 5 ms 23936 KB Output is correct
8 Incorrect 5 ms 23704 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 23900 KB Output is correct
2 Correct 6 ms 23764 KB Output is correct
3 Correct 5 ms 23900 KB Output is correct
4 Correct 5 ms 23900 KB Output is correct
5 Correct 5 ms 23900 KB Output is correct
6 Correct 5 ms 23760 KB Output is correct
7 Correct 5 ms 23936 KB Output is correct
8 Incorrect 5 ms 23704 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 23900 KB Output is correct
2 Correct 5 ms 23764 KB Output is correct
3 Correct 5 ms 23900 KB Output is correct
4 Correct 5 ms 23760 KB Output is correct
5 Correct 5 ms 23896 KB Output is correct
6 Correct 5 ms 23900 KB Output is correct
7 Correct 20 ms 28836 KB Output is correct
8 Incorrect 24 ms 28832 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 23900 KB Output is correct
2 Correct 6 ms 23764 KB Output is correct
3 Correct 5 ms 23900 KB Output is correct
4 Correct 5 ms 23900 KB Output is correct
5 Correct 5 ms 23900 KB Output is correct
6 Correct 5 ms 23760 KB Output is correct
7 Correct 5 ms 23936 KB Output is correct
8 Incorrect 5 ms 23704 KB Output isn't correct
9 Halted 0 ms 0 KB -