Submission #219293

#TimeUsernameProblemLanguageResultExecution timeMemory
219293rama_pangLamps (JOI19_lamps)C++14
0 / 100
1101 ms65092 KiB
#include <bits/stdc++.h> using namespace std; const int INF = 1e7; int N; string A, B; void Read() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); cin >> N >> A >> B; } int NaiveDP() { vector<array<array<int, 4>, 4>> dp(N + 1); // dp[pos][second_last_operation][last_operation] // dp[pos] means A[pos...N] = B[pos...N] // operation 0 = skip operation // operation 1 = off operation // operation 2 = on operation // operation 3 = xor operation for (int pos = N - 1; pos >= 0; pos--) { for (int second_last = 0; second_last < 4; second_last++) { for (int last = 0; last < 4; last++) { int &res = dp[pos][second_last][last] = INF; // operation skip (0) for (int nxt = pos; nxt < N; nxt++) { if (A[nxt] != B[nxt]) break; res = min(res, dp[nxt + 1][last][0]); } // operation off (1) for (int nxt = pos; nxt < N; nxt++) { if (B[nxt] != '0') break; res = min(res, 1 + dp[nxt + 1][last][1]); res = min(res, 1 - (second_last == 1 && last != 0 && last != 3) + dp[nxt + 1][0][1]); } // operation on (2) for (int nxt = pos; nxt < N; nxt++) { if (B[nxt] != '1') break; res = min(res, 1 + dp[nxt + 1][last][2]); res = min(res, 1 - (second_last == 2 && last != 0 && last != 3) + dp[nxt + 1][0][2]); } // operation xor (3) for (int nxt = pos; nxt < N; nxt++) { if (A[nxt] == B[nxt]) break; res = min(res, 1 - (second_last == 1 && last == 2) + dp[nxt + 1][last][3]); res = min(res, 1 - (second_last == 2 && last == 1) + dp[nxt + 1][last][3]); } } } } return dp[0][0][0]; } int main() { Read(); cout << NaiveDP() << "\n"; 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...