#include <iostream>
using namespace std;
int dp[5][5][1000005];
int main()
{
int n;
string a,b;
cin >> n >> a >> b;
for (int j=0;j<4;j++)
{
for (int k=0;k<4;k++)
dp[j][k][0]=1e9;
}
dp[3][3][0]=0;
for (int i=0;i<=a.size();i++)
{
int mn=1e9,md[4];
for (int j=0;j<4;j++)
md[i]=1e9;
for (int j=0;j<4;j++)
{
for (int k=0;k<4;k++)
{
dp[j][k][i+1]=1e9;
mn=min(mn,dp[j][k][i]);
md[j]=min(md[j],dp[j][k][i]);
md[k]=min(md[k],dp[j][k][i]);
}
}
if (i==n)
{
printf("%d",mn);
return 0;
}
if (a[i]==b[i])
dp[3][3][i+1]=mn;
else
dp[2][3][i+1]=min(min(mn+1,md[2]),dp[2][3][i]);
bool cur=b[i]-'0';
dp[!cur][2][i+1]=min(min(md[!cur]+1,md[2]+1),min(dp[!cur][2][i],mn+2));
dp[2][cur][i+1]=min(min(md[2]+1,md[cur]+1),min(dp[2][cur][i],mn+2));
dp[cur][3][i+1]=min(min(md[cur]+1,md[3]+1),min(dp[cur][3][i],mn+2));
}
}
Compilation message
lamp.cpp: In function 'int main()':
lamp.cpp:15:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0;i<=a.size();i++)
~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
504 KB |
Output is correct |
8 |
Runtime error |
8 ms |
632 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
504 KB |
Output is correct |
8 |
Runtime error |
8 ms |
632 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
508 KB |
Output is correct |
7 |
Runtime error |
125 ms |
4924 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
504 KB |
Output is correct |
8 |
Runtime error |
8 ms |
632 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
9 |
Halted |
0 ms |
0 KB |
- |