# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
373181 | luciocf | Lamps (JOI19_lamps) | C++14 | 73 ms | 23276 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3+10;
char a[maxn], b[maxn];
int comp[maxn][maxn][2];
int dp[maxn][2];
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++)
{
comp[l][l][0] = (b[l] == '0' ? 0 : 1);
for (int r = l+1; r <= n; r++)
{
if (b[r] == '0' || b[r-1] == '1') comp[l][r][0] = comp[l][r-1][0];
else comp[l][r][0] = comp[l][r-1][0]+1;
}
comp[l][l][1] = (b[l] == '1' ? 0 : 1);
for (int r = l+1; r <= n; r++)
{
if (b[r] == '1' || b[r-1] == '0') comp[l][r][1] = comp[l][r-1][1];
else comp[l][r][1] = comp[l][r-1][1]+1;
}
}
for (int i = 1; i <= n; i++)
{
dp[i][0] = dp[i][1] = n+1;
int um = 0;
for (int j = i-1; j >= 0; j--)
{
um |= (a[j+1] == '1');
int add = (j > 0 && b[j] == '0' && b[j+1] == '1');
dp[i][0] = min(dp[i][0], um + comp[j+1][i][0] - add + dp[j][1]);
}
int zero = 0;
for (int j = i-1; j >= 0; j--)
{
zero |= (a[j+1] == '0');
int add = (j > 0 && b[j] == '1' && b[j+1] == '0');
dp[i][1] = min(dp[i][1], zero + comp[j+1][i][1] - add + dp[j][0]);
}
}
printf("%d\n", min(dp[n][0], dp[n][1]));
}
컴파일 시 표준 에러 (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... |