Submission #422380

# Submission time Handle Problem Language Result Execution time Memory
422380 2021-06-10T05:25:16 Z qwerasdfzxcl Lamps (JOI19_lamps) C++14
4 / 100
35 ms 18132 KB
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
string x, y;
int dp[1001000][3], ans[1001000];

int main(){
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n >> x >> y;
    if (x[0]==y[0]){
        if (y[0]=='0') dp[0][0] = 1, dp[0][1] = 2;
        else dp[0][0] = 2, dp[0][1] = 1;
        dp[0][2] = 2;
    }
    else{
        if (y[0]=='0') dp[0][0] = 1, dp[0][1] = 2;
        else dp[0][0] = 2, dp[0][1] = 1;
        dp[0][2] = 1;
        ans[0] = 1;
    }
    for (int i=1;i<n;i++){
        if (y[i]==y[i-1]) dp[i][0] = dp[i-1][0], dp[i][1] = dp[i-1][1];
        else dp[i][y[i]-'0'] = dp[i-1][y[i]-'0'], dp[i][(y[i]-'0')^1] = dp[i-1][(y[i]-'0')^1]+1;
        dp[i][y[i]-'0'] = min(dp[i][y[i]-'0'], ans[i-1]+1);
        dp[i][(y[i]-'0')^1] = min(dp[i][(y[i]-'0')^1], ans[i-1]+2);
        if (x[i]!=y[i]){
            dp[i][2] = min(dp[i-1][2], ans[i-1]+1);
            ans[i] = min(ans[i-1]+1, min(dp[i][0], min(dp[i][1], dp[i][2])));
        }
        else{
            dp[i][2] = min(ans[i-1]+2, min(dp[i-1][2], dp[i-1][(y[i]-'0')^1])+1);
            ans[i] = ans[i-1];
        }
    }
    /*for (int i=0;i<n;i++) printf("%d", dp[i][0]);
    printf("\n");
    for (int i=0;i<n;i++) printf("%d", dp[i][1]);
    printf("\n");
    for (int i=0;i<n;i++) printf("%d", dp[i][2]);
    printf("\n");
    for (int i=0;i<n;i++) printf("%d", ans[i]);
    printf("\n");*/
    cout << ans[n-1];
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Incorrect 0 ms 204 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Incorrect 0 ms 204 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 25 ms 18020 KB Output is correct
8 Correct 35 ms 18064 KB Output is correct
9 Correct 31 ms 17940 KB Output is correct
10 Correct 32 ms 18132 KB Output is correct
11 Correct 32 ms 18040 KB Output is correct
12 Correct 25 ms 18064 KB Output is correct
13 Correct 22 ms 18076 KB Output is correct
14 Correct 25 ms 17948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Incorrect 0 ms 204 KB Output isn't correct
14 Halted 0 ms 0 KB -