Submission #398470

#TimeUsernameProblemLanguageResultExecution timeMemory
398470qwerasdfzxclLamps (JOI19_lamps)C++14
4 / 100
34 ms12184 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; string x, y; int dp[1001000][2]; int main(){ cin.tie(NULL); ios_base::sync_with_stdio(false); int n; string tmpx, tmpy; cin >> n >> tmpx >> tmpy; int idx1=0, idx2=n; for (;idx1<n && tmpx[idx1]==tmpy[idx1];idx1++); for (;idx2 && tmpx[idx2-1]==tmpy[idx2-1];idx2--); for (int i=idx1;i<idx2;i++) x.push_back(tmpx[i]); for (int i=idx1;i<idx2;i++) y.push_back(tmpy[i]); n = idx2-idx1; //cout << n << '\n' << x << '\n' << y << '\n'; int pt[2] = {-2, -2}, pt2=-2; if (x[0]!=y[0]) dp[0][0]=1, pt2=0; dp[0][1] = 1; pt[y[0]-'0']=0; for (int i=1;i<n;i++){ if (x[i]==y[i]) dp[i][0]=min(dp[i-1][0], dp[i-1][1]); else{ if (x[i-1]!=y[i-1]) dp[i][0] = min(dp[i-1][0], dp[i-1][1]+1); else if (pt2==-2) dp[i][0] = 1; else dp[i][0] = min(min(dp[i-1][0], dp[i-1][1]), dp[pt2][0])+1; pt2=i; } if (y[i-1]==y[i]) dp[i][1] = min(dp[i-1][1], dp[i-1][0]+1), pt[y[i]-'0']=i; else{ if (pt[y[i]-'0']==-2) dp[i][1] = min(dp[i-1][0], dp[i-1][1])+1; else dp[i][1] = min(min(dp[i-1][0], dp[i-1][1]), dp[pt[y[i]-'0']][1])+1; pt[y[i]-'0']=i; } dp[i][1] = min(dp[i][1], dp[i][0]+1); } /*for (int i=0;i<n;i++) cout << dp[i][0] << ' '; cout << '\n'; for (int i=0;i<n;i++) cout << dp[i][1] << ' '; cout << '\n';*/ if (n>=1) cout << min(dp[n-1][0], dp[n-1][1]); else cout << 0; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...