Submission #877349

#TimeUsernameProblemLanguageResultExecution timeMemory
877349winter0101Lamps (JOI19_lamps)C++14
100 / 100
85 ms51500 KiB
#include<bits/stdc++.h> using namespace std; #define all(fl) fl.begin(),fl.end() #define pb push_back #define fi first #define se second #define for1(i,j,k) for(int i=j;i<=k;i++) #define for2(i,j,k) for(int i=j;i>=k;i--) #define for3(i,j,k,l) for(int i=j;i<=k;i+=l) #define lb lower_bound #define ub upper_bound #define sz(a) (int)a.size() #define pii pair<int,int> #define pli pair<long long,int> #define gcd __gcd #define lcm(x,y) x*y/__gcd(x,y) #define pil pair<int,long long> const int maxn=1e6+9; int f[maxn][10]; int a[maxn],b[maxn]; vector<int> state[10]={{0},{1},{2},{3},{1,2},{1,3},{2,1},{2,3},{3,1},{3,2}}; int nxt[2][10]; int cost[10][10]; signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); //freopen("temp.INP","r",stdin); //freopen("temp.OUT","w",stdout); int n; cin>>n; string s,t; cin>>s>>t; s=" "+s; t=" "+t; for1(i,1,n){ if (s[i]=='1')a[i]=1; if (t[i]=='1')b[i]=1; } for1(i,0,1){ for1(j,0,9){ int ni=i; for(auto v:state[j]){ if (v==0)continue; if (v==1)ni=1; if (v==2)ni=0; if (v==3)ni=1-ni; } nxt[i][j]=ni; } } for1(i,0,9){ for1(j,0,9){ if (i==0)cost[i][j]=sz(state[j]); if (j==0)cost[i][j]=0; if (i!=0&&j!=0&&i!=j){ if (sz(state[i])==1&&sz(state[j])==1){ cost[i][j]=1; } if (sz(state[i])==1&&sz(state[j])==2){ bool fl=1; for (auto v:state[j]){ if (v==state[i][0]){ fl=0; break; } } cost[i][j]=fl+1; } if (sz(state[i])==2&&sz(state[j])==1){ bool fl=1; for (auto v:state[i]){ if (v==state[j][0]){ fl=0; break; } } cost[i][j]=fl; } if (sz(state[i])==2&&sz(state[j])==2){ cost[i][j]=1; } } } } for1(i,0,n){ for1(j,0,9){ f[i][j]=n+1; } } f[0][0]=0; for1(i,1,n){ for1(j,0,9){ if (nxt[a[i]][j]==b[i]){ for1(k,0,9){ f[i][j]=min(f[i][j],f[i-1][k]+cost[k][j]); } } } } int ans=n+1; for1(i,0,9)ans=min(ans,f[n][i]); cout<<ans; //for1(i,0,9)for1(j,0,9)cout<<i<<" "<<j<<" "<<cost[i][j]<<'\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...