Submission #937559

#TimeUsernameProblemLanguageResultExecution timeMemory
937559WonderfulWhaleLamps (JOI19_lamps)C++17
4 / 100
342 ms81188 KiB
#include<bits/stdc++.h> using namespace std; #define int int64_t #define pb push_back #define pii pair<int, int> #define st first #define nd second #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() int dp[1000009][2][5]; int dis[5][5] = { {0, 1, 1, 2, 2}, {0, 0, 1, 1, 2}, {0, 1, 0, 2, 1}, {0, 0, 0, 0, 1}, {0, 0, 0, 1, 0} }; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; for(int i=0;i<=n;i++) { for(int j=0;j<5;j++) { dp[i][0][j] = dp[i][1][j] = 1e9; } } dp[0][0][0] = 0; string A, B; cin >> A >> B; for(int i=1;i<=n;i++) { for(int j1=0;j1<2;j1++) { for(int j2=0;j2<5;j2++) { for(int k1=0;k1<2;k1++) { for(int k2=0;k2<5;k2++) { int New = A[i-1]-'0'; if(k1) New = 1-New; if(k2==2||k2==3) New = 1; if(k2==1||k2==4) New = 0; if(New!=B[i-1]-'0') continue; bool is = k1&&(!j1); dp[i][k1][k2] = min(dp[i][k1][k2], dp[i-1][j1][j2]+is+dis[j2][k2]); } } } } } int ans = 1e9; for(int i=0;i<5;i++) ans = min({ans, dp[n][0][i], dp[n][1][i]}); cout << ans << "\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...