# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
204062 | ics0503 | Lamps (JOI19_lamps) | C++17 | 259 ms | 65020 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<stdio.h>
char a[1212121], b[1212121];
int D[1212121][4][4];
int min(int a, int b) { if (a < b)return a; return b; }
bool oper(int type, int type2, int w) {
if (type == 0)return b[w] == '0';
if (type == 1)return b[w] == '1';
if (type == 2 && type2 == 3)return b[w] != a[w];
if (type == 2 && type2 == 2)return b[w] == a[w];
if (type == 2 && type2 == 1)return b[w] == '0';
if (type == 2 && type2 == 0)return b[w] == '1';
if (type == 3 && type2 == 3)return a[w] == b[w];
return oper(type2, 3, w);
}
int main() {
int n, i, j, k, p; scanf("%d%s%s", &n, a + 1, b + 1);
for (i = 0; i < 4; i++)for (j = 0; j < 4; j++)D[0][i][j] = 1e9;
D[0][3][3] = 0;
for (i = 1; i <= n; i++) {
for (j = 0; j < 3; j++) {
for (k = 0; k < 4; k++) {
D[i][j][k] = 1e9;
if (oper(j, k, i)) {
D[i][j][k] = D[i - 1][j][k];
for (p = 0; p < 4; p++)
D[i][j][k] = min(D[i][j][k], D[i - 1][p][k] + (j != 3));
if (k == 3) {
for (p = 0; p < 4; p++)
D[i][j][3] = min(D[i][j][3], D[i - 1][p][j] + (p == 3));
}
for (p = 0; p < 4; p++)
D[i][j][k] = min(D[i][j][k], D[i - 1][k][p] + (j != 3));
}
}
}
for (j = 0; j < 4; j++)D[i][3][j] = 1e9;
D[i][3][3] = 1e9;
for (j = 0; j < 4; j++) for (k = 0; k < 4; k++) {
if (oper(3, 3, i)) D[i][3][3] = min(D[i][3][3], D[i - 1][j][k]);
}
}
int ans = 1e9;
for (i = 0; i < 4; i++)for (j = 0; j < 4; j++)ans = min(ans, D[n][i][j]);
printf("%d", ans);
return 0;
}
컴파일 시 표준 에러 (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... |