# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
373127 | 2021-03-03T13:27:59 Z | luciocf | Lamps (JOI19_lamps) | C++14 | 2 ms | 364 KB |
#include <bits/stdc++.h> using namespace std; const int maxn = 2e3+10; char a[maxn], b[maxn]; int solve[maxn][maxn][2]; int dp[maxn]; int main(void) { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf(" %c", &a[i]); for (int i = 1; i <= n; i++) scanf(" %c", &b[i]); for (int l = 1; l <= n; l++) { solve[l][l][0] = (b[l] == '0' ? 0 : 1); for (int r = l+1; r <= n; r++) { if (b[r] == '0' || b[r-1] == '1') solve[l][r][0] = solve[l][r-1][0]; else solve[l][r][0] = solve[l][r-1][0]+1; } solve[l][l][1] = (b[l] == '1' ? 0 : 1); for (int r = l+1; r <= n; r++) { if (b[r] == '1' || b[r-1] == '0') solve[l][r][1] = solve[l][r-1][1]; else solve[l][r][1] = solve[l][r-1][1]+1; } } for (int i = 1; i <= n; i++) { dp[i] = n+1; if (a[i] == b[i]) dp[i] = min(dp[i], dp[i-1]); for (int j = i-1; j >= 0 && a[j+1] != b[j+1]; j--) dp[i] = min(dp[i], 1 + dp[j]); bool zero = 0, um = 1; for (int j = i-1; j >= 0; j--) { zero |= (a[j+1] == '0'); um |= (a[j+1] == '1'); dp[i] = min(dp[i], (zero ? 1 : 0) + solve[j+1][i][1] + dp[j]); dp[i] = min(dp[i], (um ? 1 : 0) + solve[j+1][i][0] + dp[j]); } } printf("%d\n", dp[n]); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 0 ms | 364 KB | Output is correct |
6 | Correct | 0 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 364 KB | Output is correct |
13 | Incorrect | 1 ms | 364 KB | Output isn't correct |
14 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 0 ms | 364 KB | Output is correct |
6 | Correct | 0 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 364 KB | Output is correct |
13 | Incorrect | 1 ms | 364 KB | Output isn't correct |
14 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Execution timed out | 2 ms | 364 KB | Time limit exceeded (wall clock) |
8 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 0 ms | 364 KB | Output is correct |
6 | Correct | 0 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 364 KB | Output is correct |
13 | Incorrect | 1 ms | 364 KB | Output isn't correct |
14 | Halted | 0 ms | 0 KB | - |