Submission #943486

#TimeUsernameProblemLanguageResultExecution timeMemory
943486Tuanlinh123Lamps (JOI19_lamps)C++17
100 / 100
77 ms9712 KiB
#include<bits/stdc++.h> #define ll int #define pll pair<ll, ll> #define pb push_back #define mp make_pair #define fi first #define se second #define ld long double #define sz(a) ((ll)(a).size()) using namespace std; const ll inf=1e9; ll a[1000005], b[1000005], dp[2][3][2]; ll costk[2][2]={{0, 1}, {0, 0}}, costj[3][3]={{0, 1, 0}, {1, 0, 0}, {1, 1, 0}}; ll read(){char c; cin >> c; return c-'0';} void upd(ll a, ll& b) {b=min(a, b);} int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n; cin >> n; for (ll i=1; i<=n; i++) a[i]=read(); for (ll i=1; i<=n; i++) b[i]=read(); for (ll i=0; i<2; i++) for (ll j=0; j<3; j++) for (ll k=0; k<2; k++) dp[i][j][k]=inf; dp[0][2][0]=0; for (ll i=1; i<=n; i++) { ll c=i&1, p=(i^1)&1; for (ll j=0; j<3; j++) for (ll k=0; k<2; k++) dp[c][j][k]=inf; for (ll j=0; j<3; j++) for (ll k=0; k<2; k++) for (ll jn=0; jn<3; jn++) for (ll kn=0; kn<2; kn++) upd(dp[p][j][k]+costj[j][jn]+costk[k][kn], dp[c][jn][kn]); for (ll j=0; j<3; j++) for (ll k=0; k<2; k++) if (((j<2?j:a[i])^k)!=b[i]) dp[c][j][k]=inf; } ll ans=inf; for (ll j=0; j<3; j++) for (ll k=0; k<2; k++) ans=min(ans, dp[n&1][j][k]); cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...