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 <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
using namespace std;
int n, m, k, u, v, x, y, t, a, b, ans, inf=1000000010;
int dp[10], W[10][10], F[10];
string A, B;
inline void upd(int &x, int y){ if (x>y) x=y;}
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
W[0][1]=W[0][2]=1;
W[0][3]=W[0][4]=2;
W[1][2]=W[1][3]=1;
W[1][4]=2;
W[2][1]=W[2][4]=1;
W[2][3]=2;
W[3][4]=W[4][3]=2;
for (int i=0; i<5; i++) for (int j=0; j<5; j++){
W[i][j+5]=W[i][j]+1;
W[i+5][j+5]=W[i+5][j]=W[i][j];
}
F[2]=F[3]=F[6]=F[9]=1;
cin>>n>>A>>B;
for (int i=0; i<10; i++) dp[i]=W[0][i];
for (int i=1; i<=n; i++){
if (A[i-1]==B[i-1]) dp[5]=inf;
else dp[0]=inf;
for (int j=0; j<10; j++) if (j%5 && F[j]!=B[i-1]-'0') dp[j]=inf;
for (int u=0; u<10; u++) for (int v=0; v<10; v++) upd(dp[v], dp[u]+W[u][v]);
}
ans=inf;
for (int i=0; i<10; i++) upd(ans, dp[i]);
cout<<ans<<"\n";
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... |