제출 #107552

#제출 시각아이디문제언어결과실행 시간메모리
107552shoemakerjoLamps (JOI19_lamps)C++14
100 / 100
225 ms24040 KiB
#include <bits/stdc++.h> using namespace std; int n; string a, b; const int maxn = 1000010; int dp[maxn][5]; //0 is nothing on me //1 is a '0' on me //2 is a '1' on me //3 is a '0' on top of a '1' //4 is a '1' on top of a '0' const int cost[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}}; bool issame(int u, int tp) { if (u == 0) return true; if (tp == 0) { return a[u] == b[u]; } if (tp == 2 || tp == 4) { return b[u] == '1'; } if (tp == 1 || tp == 3) { return b[u] == '0'; } return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; cin >> a >> b; a = " " + a; b = " " + b; for (int i = 1; i < 5; i++) { dp[0][i] = n; } for (int i = 1; i <= n; i++) { for (int j = 0; j < 5; j++) { dp[i][j] = n; for (int k = 0; k < 5; k++) { //get to j from k dp[i][j] = min(dp[i][j], dp[i-1][k] + cost[k][j] + ((!issame(i, j) && issame(i-1, k)) ? 1 : 0) ); } } // cout << i << " : " ; // for (int j = 0; j < 5; j++) { // cout << dp[i][j] << " "; // } // cout << endl; } // cout << "v : " << issame(1, 0) << endl; int res = n; for (int i = 0; i < 5; i++) { res = min(res, dp[n][i]); } cout << res << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...