#include <iostream>
#include <fstream>
using namespace std;
int dp[2][10];
int cst,i,j,k,n,use,x,y,ans;
string a,b;
bool valid(int x,int y,int mov)
{
if(mov/3)
{
mov-=3;
if(mov)return ((mov-1)^y);
return (x^y);
}
return ((mov%3)-1==y);
}
int main()
{
//freopen("data.in","r",stdin);
ios_base::sync_with_stdio(false);
cin>>n;
cin>>a>>b;
for(i=1;i<6;i++)
dp[0][i]=(1<<30);
for(i=0;i<n;i++)
{
use=1-use;
x=a[i]-'0';y=b[i]-'0';
for(j=0;j<6;j++)
dp[use][j]=(1<<30);
for(j=0;j<6;j++)
if(valid(x,y,j))
for(k=0;k<6;k++)
{
cst=(((j%3)!=(k%3)&&(j%3!=0))+((j/3)>(k/3)));
dp[use][j]=min(dp[use][j],dp[1-use][k]+cst);
}
}
ans=(1<<30);
for(j=0;j<6;j++)
ans=min(ans,dp[use][j]);
cout<<ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |