This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("Ofast,unroll-loops,O3")
//#pragma GCC optimize("avx,avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,fma,tune=native")
#include<bits/stdc++.h>
//#include<bits/extc++.h>
//#pragma pack(1)
#define fast ios::sync_with_stdio(0); cin.tie(0);
#define int long long
#define pii pair<int,int>
#define x first
#define y second
#define N 2015
using namespace std;
//using namespace __gnu_pbds;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//typedef tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> order_multiset;
//typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> order_set;
int n,dp[N][10];
int dis[10][10];
char a[N],b[N];
/*
前 i 個都是處理好的
00 沒影響
01 有設為 0
02 有設為 1
10 有 ^ 一次
11 先設為 0 再 ^
12 先設為 1 再 ^
*/
signed main(){
fast
for (int i=0;i<10;i++){
for (int j=0;j<10;j++){
int x1=i%3,y1=i/3;
int x2=j%3,y2=j/3;
dis[i][j]=(y2-y1>0);
if (x1!=x2){
if (x2!=0) dis[i][j]++;
}
}
}
cin>>n;
for (int i=1;i<=n;i++)
cin>>a[i];
for (int i=1;i<=n;i++)
cin>>b[i];
for (int i=0;i<=n+1;i++)
for (int j=0;j<9;j++)
dp[i][j]=1e9;
dp[0][0]=0;
for (int i=0;i<n;i++){
for (int j=0;j<6;j++){
if (dp[i][j]>1e8) continue;
for (int k=0;k<6;k++){
int goal=b[i+1]-'0';
int now=a[i+1]-'0';
if (k%3==1) now=0;
else if (k%3==2) now=1;
if (k/3) now^=1;
if (now==goal){
dp[i+1][k]=min(dp[i+1][k],dp[i][j]+dis[j][k]);
}
}
}
}
int ans=1e9;
for (int i=0;i<6;i++)
ans=min(ans,dp[n][i]);
cout<<ans<<'\n';
}
# | 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... |