Submission #364795

#TimeUsernameProblemLanguageResultExecution timeMemory
364795jainbot27Lamps (JOI19_lamps)C++17
100 / 100
293 ms10348 KiB
#include <bits/stdc++.h> using namespace std; #define f first #define s second #define pb push_back #define ar array #define all(x) x.begin(), x.end() #define siz(x) (int)x.size() #define FOR(x, y, z) for(int x = (y); x < (z); x++) #define ROF(x, z, y) for(int x = (y-1); x >= (z); x--) #define F0R(x, z) FOR(x, 0, z) #define R0F(x, z) ROF(x, 0, z) #define trav(x, y) for(auto&x:y) using ll = long long; using vi = vector<int>; using vl = vector<long long>; using pii = pair<int, int>; using vpii = vector<pair<int, int>>; template<class T> inline bool ckmin(T&a, T b) {return b < a ? a = b, 1 : 0;} template<class T> inline bool ckmax(T&a, T b) {return b > a ? a = b, 1 : 0;} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const char nl = '\n'; const int mxN = 1e6+10; const int MOD = 1e9 + 7; const long long infLL = 1e18; int a[mxN], b[mxN], n; ar<int, 8> dp, new_dp; char c; int get(int idx, int msk){ int res = a[idx]; if(msk&1) res = 0; if(msk&2) res = 1; if(msk&4) res ^= 1; return res; } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; F0R(i, n) cin >> c, a[i] = c - '0'; F0R(i, n) cin >> c, b[i] = c - '0'; FOR(i, 1, 8) dp[i] = n; F0R(i, n){ F0R(msk, 8){ new_dp[msk] = n; if(get(i, msk)==b[i]){ F0R(old_msk, 8){ ckmin(new_dp[msk], dp[old_msk]+__builtin_popcount(~old_msk&msk)); } } } swap(dp, new_dp); } int ans = n; F0R(i, 8) ckmin(ans, dp[i]); cout << ans << nl; 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...