답안 #391655

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
391655 2021-04-19T13:09:38 Z qwerasdfzxcl Lamps (JOI19_lamps) C++14
4 / 100
20 ms 10240 KB
#include <bits/stdc++.h>

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

int main(){
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n >> x >> y;
    int pt[2] = {-2, -2}, pt2=-2;
    if (x[0]!=y[0]) dp[0][0]=1, pt2=0;
    dp[0][1] = 1;
    pt[y[0]-'0']=0;
    for (int i=1;i<n;i++){
        if (x[i]==y[i]) dp[i][0]=min(dp[i-1][0], dp[i-1][1]);
        else{
            if (x[i-1]!=y[i-1]) dp[i][0] = min(dp[i-1][0], dp[i-1][1]+1);
            else if (pt2==-2) dp[i][0] = min(dp[i-1][0], dp[i-1][1])+1;
            else dp[i][0] = min(min(dp[i-1][0], dp[i-1][1]), dp[pt2][0])+1;
            pt2=i;
        }
        if (y[i-1]==y[i]) dp[i][1] = min(dp[i-1][1], dp[i-1][0]+1), pt[y[i]-'0']=i;
        else{
            if (pt[y[i]-'0']==-2) dp[i][1] = min(dp[i-1][0], dp[i-1][1])+1;
            else dp[i][1] = min(min(dp[i-1][0], dp[i-1][1]), dp[pt[y[i]-'0']][1])+1;
            pt[y[i]-'0']=i;
        }
    }
    /*for (int i=0;i<n;i++) cout << dp[i][0] << ' ';
    cout << '\n';
    for (int i=0;i<n;i++) cout << dp[i][1] << ' ';
    cout << '\n';*/
    cout << min(dp[n-1][0], dp[n-1][1]);
    return 0;
}
# 결과 실행 시간 메모리 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 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 -
# 결과 실행 시간 메모리 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 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 208 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 13 ms 10140 KB Output is correct
8 Correct 20 ms 10240 KB Output is correct
9 Correct 14 ms 10180 KB Output is correct
10 Correct 14 ms 10140 KB Output is correct
11 Correct 14 ms 10140 KB Output is correct
12 Correct 13 ms 10140 KB Output is correct
13 Correct 13 ms 10140 KB Output is correct
14 Correct 13 ms 10140 KB Output is correct
# 결과 실행 시간 메모리 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 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 -