Submission #632004

#TimeUsernameProblemLanguageResultExecution timeMemory
632004radalLamps (JOI19_lamps)C++17
0 / 100
9 ms5364 KiB
#include <bits/stdc++.h> #define rep(i,l,r) for (int i = l; i < r; i++) #define repr(i,r,l) for (int i = r; i >= l; i--) #define pb push_back #define X first #define Y second #define debug(x) cerr << #x << " : " << x << endl; #define all(x) x.begin() , x.end() using namespace std; typedef pair<int,int> pll; typedef long long ll; constexpr int N = 2e3+10; int cal[N][5],a[N][3],dp[N],pd[N][N][3]; int main(){ ios_base :: sync_with_stdio(0); cin.tie(0); int n; cin >> n; string s,t; cin >> s >> t; s = '#'+s; t = '#'+t; cal[0][0] = 1; cal[0][1] = 1; cal[0][2] = 1; rep(i,1,n+1){ rep(j,0,5){ if (j == 3) continue; if (j == 4){ if (s[i] == t[i]){ cal[i][j] = cal[i-1][3]; continue; } cal[i][j] = min(cal[i-1][2],cal[i-1][t[i]-'0']); continue; } if (j == 2){ if (s[i] == t[i]){ cal[i][j] = min({cal[i-1][s[i]-'0']+1,cal[i-1][j]+1,2+cal[i-1][3]}); continue; } cal[i][j] = min(cal[i-1][j],cal[i-1][3]+1); continue; } else{ if (j+'0' == t[i]){ cal[i][j] = min(cal[i-1][j],cal[i-1][3]+1); continue; } cal[i][j] = min(cal[i-1][j]+1,cal[i-1][3]+2); continue; } } cal[i][3] = min({cal[i][0],cal[i][1],cal[i][2],cal[i][4]}); } rep(i,1,n+1){ if (t[i] == '1') a[i][1] = 1+a[i-1][1]; else a[i][0] = 1+a[i-1][0]; } repr(l,n,1){ rep(r,l,n+1){ if (t[r] == '1'){ pd[l][r][1] = pd[l][r-1][1]; if (a[r][1] >= r-l+1){ pd[l][r][0] = 1; continue; } pd[l][r][0] = pd[l][r-a[r][1]][0]+1; } else{ pd[l][r][0] = pd[l][r-1][0]; if (a[r][0] >= r-l+1){ pd[l][r][1] = 1; continue; } pd[l][r][1] = pd[l][r-a[r][0]][1]+1; } } } rep(i,1,n+1){ if (s[i] == t[i]){ dp[i] = dp[i-1]; continue; } dp[i] = 1+dp[i-1]; bool fl = 1; repr(j,i-1,1){ fl &= (s[j] != t[j]); dp[i] = min(dp[i],dp[j-1]+min(pd[j][i][0],pd[j][i][1])+1); if (fl) dp[i] = min(dp[i],dp[j-1]+1); } } cout << min(dp[n],cal[n][3]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...