#include<bits/stdc++.h>
using namespace std;
#define int int64_t
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
int dp[2009][2][2][2009];
int dis[5][5] = {
{0, 1, 1, 2, 2},
{0, 0, 1, 1, 2},
{0, 1, 0, 2, 1},
{0, 0, 0, 0, 1},
{0, 0, 0, 1, 0}
};
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
for(int i=0;i<=n;i++) {
for(int j=0;j<=n;j++) {
dp[i][0][0][j] = dp[i][1][0][j] = 1e9;
dp[i][0][1][j] = dp[i][1][1][j] = 1e9;
}
}
dp[0][0][0][0] = 0;
dp[0][0][1][0] = 0;
string A, B;
cin >> A >> B;
for(int i=1;i<=n;i++) {
for(int j1=0;j1<2;j1++) {
for(int j2=0;j2<2;j2++) {
for(int j3=0;j3<=n;j3++) {
for(int k1=0;k1<2;k1++) {
for(int k2=0;k2<2;k2++) {
for(int k3=0;k3<=n;k3++) {
int New = A[i-1]-'0';
if(k1) New = 1-New;
if(k3)
New = (k2+k3)%2;
if(New!=B[i-1]-'0') continue;
bool is = k1&&(!j1);
int is2 = 0;
if(j2==k2) is2 = max(is2, k3-j3);
else is2 = k3;
dp[i][k1][k2][k3] = min(dp[i][k1][k2][k3],
dp[i-1][j1][j2][j3]+is+is2);
}
}
}
}
}
}
}
int ans = 1e9;
for(int i=0;i<5;i++) {
ans = min({ans, dp[n][0][0][i], dp[n][1][0][i]});
ans = min({ans, dp[n][0][1][i], dp[n][1][1][i]});
}
cout << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |