Submission #391358

# Submission time Handle Problem Language Result Execution time Memory
391358 2021-04-18T16:02:08 Z qwerasdfzxcl Lamps (JOI19_lamps) C++14
4 / 100
49 ms 14232 KB
#include <bits/stdc++.h>

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

int calc(int n){
    for (int i=0;i<n;i++) dp[i][0] = 1e9, dp[i][1] = 1e9, dp[i][2] = 1e9;
    dp[0][0] = 1;
    if (x[0]!=y[0]) dp[0][1] = 1, dp[0][2] = 1;
    else dp[0][2] = 0;
    for (int i=1;i<n;i++){
        if (x[i]==y[i]){
            if (y[i-1]!=y[i]) dp[i][0] = dp[i-1][2]+1;
            else dp[i][0] = min(dp[i-1][0], dp[i-1][2]+1);
            dp[i][2] = dp[i-1][2];
        }
        else{
            if (y[i-1]!=y[i]) dp[i][0] = dp[i-1][2]+1;
            else dp[i][0] = min(dp[i-1][0], dp[i-1][2]+1);
            if (x[i-1]==y[i-1]) dp[i][1] = dp[i-1][2]+1;
            else dp[i][1] = min(dp[i-1][2]+1, dp[i-1][1]);
            dp[i][2] = min(dp[i][0], dp[i][1]);
        }
    }
    //for (int i=0;i<n-1;i++) cout << dp[i][2];
    return dp[n-1][2];
}

int main(){
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n >> x >> y;
    int ans = calc(n);
    int pt1=-1, pt2=-1;
    for (int i=0;i<n;i++) if(x[i]!=y[i]){
        pt1=i; break;
    }
    for (int i=n-1;i>=0;i--) if(x[i]!=y[i]){
        pt2=i; break;
    }
    if (pt1!=-1){
        for (int i=pt1;i<=pt2;i++){
            if (x[i]=='0') x[i] = '1';
            else x[i] = '0';
        }
        ans = min(ans, calc(n)+1);
    }
    for (int j=0;j<2;j++){
        for (int i=0;i<n;i++) x[i] = '0'+j;
        ans = min(ans, calc(n)+1);
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 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 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Incorrect 1 ms 204 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 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 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Incorrect 1 ms 204 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 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 39 ms 14232 KB Output is correct
8 Correct 45 ms 14108 KB Output is correct
9 Correct 46 ms 14108 KB Output is correct
10 Correct 45 ms 14108 KB Output is correct
11 Correct 49 ms 14108 KB Output is correct
12 Correct 49 ms 14160 KB Output is correct
13 Correct 49 ms 14148 KB Output is correct
14 Correct 49 ms 14048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 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 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Incorrect 1 ms 204 KB Output isn't correct
14 Halted 0 ms 0 KB -