# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
105055 | antimirage | Lamps (JOI19_lamps) | C++14 | 106 ms | 67064 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
# include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, dp[N][4][4];
char a[N], b[N];
main(){
memset( dp, 0x3f3f3f3f, sizeof(dp) );
cin >> n;
scanf("\n%s", a + 1);
scanf("\n%s", b + 1);
dp[0][2][0] = 0;
for (int i = 1; i <= n; i++){
for (int j = 0; j < 3; j++){
if (b[i] - 48 == j){
dp[i][j][0] = min(dp[i - 1][j][1], dp[i - 1][j][0]);
for (int l = 0; l < 3; l++){
dp[i][j][0] = min( dp[i][j][0], dp[i - 1][l][0] + 1);
dp[i][j][0] = min( dp[i][j][0], dp[i - 1][l][1] + 1);
}
}
if (b[i] - 48 == (j ^ 1) ){
dp[i][j][1] = min( dp[i - 1][j][0] + 1, dp[i - 1][j][1]);
for (int l = 0; l < 3; l++){
dp[i][j][1] = min( dp[i][j][1], dp[i - 1][l][1] + 1);
}
}
if (j == 2 && b[i] == a[i]){
for (int l = 0; l < 3; l++){
dp[i][j][0] = min( dp[i][j][0], dp[i - 1][l][0]);
dp[i][j][0] = min( dp[i][j][0], dp[i - 1][l][1]);
}
}
if (j == 2 && b[i] != a[i]){
for (int l = 0; l < 3; l++){
dp[i][j][1] = min( dp[i][j][1], dp[i - 1][l][1]);
dp[i][j][1] = min( dp[i][j][1], dp[i - 1][l][0] + 1);
}
}
}
}
int ans = n + 1;
for (int i = 0; i < 3; i++)
for (int j = 0; j < 2; j++)
ans = min(ans, dp[n][i][j]);
cout << ans << endl;
}
/**
13
0101100101001
1011111000000
13
0001101001101
0101100011011
8
11011100
01101001
**/
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |