Submission #892014

#TimeUsernameProblemLanguageResultExecution timeMemory
892014serifefedartarLamps (JOI19_lamps)C++17
0 / 100
24 ms28836 KiB
#include <bits/stdc++.h> using namespace std; #define fast ios::sync_with_stdio(0);cin.tie(0); typedef long long ll; #define f first #define s second #define MOD 998244353 #define LOGN 21 const ll MAXN = 1e6 + 100; int dp[MAXN][6]; // 0 : değişiklik yok // 1 : hepsi 0 // 2 : hepsi 1 // 3 : ters çevir // 4 : önce sıfırla sonra çevir // 5 : önce birle sonra çevir int main() { fast int N; string S, T; cin >> N >> S >> T; for (int i = 0; i < N; i++) S[i] = (S[i] != T[i] ? '1' : '0'); for (int i = 0; i < MAXN; i++) { for (int j = 0; j < 6; j++) dp[i][j] = 1e9; } dp[0][0] = 0; S = "#" + S; for (int i = 1; i <= N; i++) { if (S[i] == '1') { dp[i][3] = min({dp[i-1][0] + 1, dp[i-1][1] + 1, dp[i-1][2] + 1, dp[i-1][3], dp[i-1][4], dp[i-1][5]}); if (T[i-1] == '1') { dp[i][2] = min({dp[i-1][0] + 1, dp[i-1][1] + 1, dp[i-1][2], dp[i-1][3] + 1, dp[i-1][4] + 1, dp[i-1][5]}); dp[i][4] = min({dp[i-1][0] + 2, dp[i-1][1] + 1, dp[i-1][2] + 2, dp[i-1][3] + 1, dp[i-1][4], dp[i-1][5] + 1}); } else { dp[i][1] = min({dp[i-1][0] + 1, dp[i-1][1], dp[i-1][2] + 1, dp[i-1][3] + 1, dp[i-1][4], dp[i-1][5] + 1}); dp[i][5] = min({dp[i-1][0] + 2, dp[i-1][1] + 2, dp[i-1][2] + 1, dp[i-1][3] + 1, dp[i-1][4] + 1, dp[i-1][5]}); } } else { dp[i][0] = min({dp[i-1][0], dp[i-1][1], dp[i-1][2], dp[i-1][3], dp[i-1][4], dp[i-1][5]}); if (T[i-1] == '1') { dp[i][2] = min({dp[i-1][0] + 1, dp[i-1][1] + 1, dp[i-1][2], dp[i-1][3] + 1, dp[i-1][4] + 1, dp[i-1][5]}); dp[i][4] = min({dp[i-1][0] + 2, dp[i-1][1] + 1, dp[i-1][2] + 2, dp[i-1][3] + 1, dp[i-1][4], dp[i-1][5] + 1}); } else { dp[i][2] = min({dp[i-1][0] + 1, dp[i-1][1] + 1, dp[i-1][2], dp[i-1][3] + 1, dp[i-1][4] + 1, dp[i-1][5]}); dp[i][5] = min({dp[i-1][0] + 2, dp[i-1][1] + 2, dp[i-1][2] + 1, dp[i-1][3] + 1, dp[i-1][4] + 1, dp[i-1][5]}); } } } cout << min({dp[N][0], dp[N][1], dp[N][2], dp[N][3], dp[N][4]}) << "\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...