제출 #1158547

#제출 시각아이디문제언어결과실행 시간메모리
1158547dostsLamps (JOI19_lamps)C++20
100 / 100
14 ms2788 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2") using namespace std; //#define int long long #define pii pair<int,int> #define ff first #define ss second #define sp << " " << #define all(cont) cont.begin(),cont.end() #define vi vector<int> const int inf = 2e9,N = 4e5+1,MOD = 1e9+7; #define chmin(a,b) a = min(a,b); string a,b; inline int now(const int& p,const int& t) { if (t < 2) return t; if (!p) return (int)(t==1); return (int)a[p-1]; }; void solve() { int n; cin >> n; cin >> a >> b; for (auto& it : a) it-='0'; for (auto& it : b) it-='0'; int dp[3],dp2[3]; dp[0] = dp[1] = dp[2] = dp2[0] = dp2[1] = inf; dp2[2] = 0; for (int i = 0;i<n;i++) { for (int j = 0;j<=2;j++) { if (dp2[j] == inf) continue; int swi = (i && (now(i,j) != b[i-1])); if (!swi) { for (int jj = 0;jj<3;jj++) chmin(dp[jj],dp2[j]+(jj<2 && j!=jj)+(now(i+1,jj)!=b[i])); } else { for (int jj = 0;jj<3;jj++) chmin(dp[jj],dp2[j]+(jj<2 && j!=jj)); } } for (int j = 0;j<3;j++) { dp2[j] = dp[j]; dp[j] = inf; } } int ans = inf; for (int j = 0;j<3;j++) ans = min(ans,dp2[j]); cout << ans << '\n'; } int32_t main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #ifdef Dodi freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif int t = 1; //cin >> t; while (t --> 0) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...