Submission #914137

#TimeUsernameProblemLanguageResultExecution timeMemory
914137Shayan86Lamps (JOI19_lamps)C++14
100 / 100
29 ms51460 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3,unroll-loops") // #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") // Ofast, O0, O1, O2, O3, unroll-loops, fast-math, trapv typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; #define Mp make_pair #define sep ' ' #define endl '\n' #define F first #define S second #define pb push_back #define all(x) (x).begin(),(x).end() #define kill(res) cout << res << '\n', exit(0); #define set_dec(x) cout << fixed << setprecision(x); #define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define file_io freopen("input.txt", "r", stdin) ; freopen("output.txt", "w", stdout); const ll N = 1e6 + 50; const ll inf = 1e9 + 7; ll n, dp[N][6]; string s, t; int main(){ fast_io; cin >> n >> s >> t; s = "$" + s; t = "$" + t; for(int i = 0; i <= n; i++) for(int j = 0; j < 6; j++) dp[i][j] = inf; dp[0][0] = 0; for(int i = 1; i <= n; i++){ if(t[i] == '0') dp[i][5] = min({dp[i-1][0] + 2, dp[i-1][1] + 1, dp[i-1][4] + 1, dp[i-1][5]}); if(t[i] == '1') dp[i][4] = min(dp[i-1][0] + 1, dp[i-1][4]); dp[i][4] = min(dp[i][4], dp[i][5]); // hame 0 with c if(t[i] == '1') dp[i][3] = min({dp[i][0] + 2, dp[i-1][1] + 1, dp[i-1][2] + 1, dp[i-1][3]}); // hame 0 without if(t[i] == '0') dp[i][2] = min(dp[i-1][0] + 1, dp[i-1][2]); dp[i][2] = min({dp[i][2], dp[i][3]}); if(s[i] != t[i]) dp[i][1] = min(dp[i-1][1], dp[i-1][0] + 1); dp[i][1] = min({dp[i][1], dp[i][3], dp[i][5]}); if(s[i] == t[i]) dp[i][0] = dp[i-1][0]; dp[i][0] = min({dp[i][0], dp[i][1], dp[i][2], dp[i][3], dp[i][4], dp[i][5]}); } cout << dp[n][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...