이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;
int dp[1000001][3][2];
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
string A, B;
cin >> A >> B;
dp[0][2][0] = 0;
dp[0][0][0] = dp[0][1][0] = 1;
dp[0][2][1] = 1;
dp[0][0][1] = dp[0][1][1] = 2;
for(int q = 0; q < n; q++){
int i = q + 1;
int w = A[q] - '0';
int t = B[q] - '0';
for(int j = 0; j < 3; j++){
for(int a = 0; a < 2; a++){
dp[i][j][a] = INF;
for(int k = 0; k < 3; k++){
for(int b = 0; b < 2; b++){
int c = w;
if(j < 2) c = j;
if(a) c = 1 - c;
if(c != t) continue;
int cost = 0;
if(j != k && j != 2) cost++;
if(a && !b) cost++;
dp[i][j][a] = min(dp[i][j][a], dp[i - 1][k][b] + cost);
}
}
}
}
}
int ans = INF;
for(int i = 0; i < 3; i++)for(int j = 0; j < 2; j++) ans = min(ans, dp[n][i][j]);
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |