Submission #937580

#TimeUsernameProblemLanguageResultExecution timeMemory
937580WonderfulWhaleLamps (JOI19_lamps)C++17
0 / 100
1071 ms112368 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][14]; int dis[14][3] = { {-1, -1, -1}, {0, -1, -1}, {1, -1, -1}, {2, -1, -1}, {0, 2, -1}, {1, 2, -1}, {2, 0, -1}, {2, 1, -1}, {2, 0, 1}, {0, 2, 1}, {0, 1, 2}, {2, 1, 0}, {1, 2, 0}, {1, 0, 2} }; int f(int a, int b) { for(int i=0;i<3;i++) { if(dis[a][i]!=dis[b][i]) { for(int j=0;j<4;j++) { if(j==3||dis[b][j]==-1) return j-i; } } } return 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<14;j++) { dp[i][j] = 1e9; } } dp[0][0] = 0; string A, B; cin >> A >> B; //for(int i=0;i<14;i++) { //for(int j=0;j<14;j++) { //cout << f(i, j) << " "; //} //cout << "\n"; //} for(int i=1;i<=n;i++) { for(int j=0;j<14;j++) { for(int k=0;k<14;k++) { int New = A[i-1]-'0'; for(int I=0;I<3;I++) { if(dis[k][I]==0) New = 0; if(dis[k][I]==1) New = 1; if(dis[k][I]==2) New = 1-New; } if(New!=B[i-1]-'0') continue; dp[i][k] = min(dp[i][k], dp[i-1][j]+f(j, k)); } } //for(int j=0;j<14;j++) { //cout << i << " " << j << ": " << dp[i][j] << "\n"; //} } int ans = 1e9; for(int i=0;i<=n;i++) { for(int j=0;j<14;j++) { ans = min(ans, dp[n][j]); } } 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...