This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
return ((mov%3)-1==y);
return ((x^y)==mov/3);
}
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;
}
# | 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... |