제출 #210832

#제출 시각아이디문제언어결과실행 시간메모리
210832amiratouLamps (JOI19_lamps)C++14
4 / 100
50 ms16200 KiB
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define rando mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) #define fi first #define se second #define debug(x) cerr << " - " << #x << ": " << x << endl; #define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl; #define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl; #define sep() cerr << "--------------------" << endl; #define all(x) (x).begin(),(x).end() #define sz(x) (ll)x.size() #define ld long double #define ll long long //#define int ll #define ii pair<int,int> #define v vector<int> #define vii vector<ii> #define vv vector<vector<int> > #define mp make_pair #define INF 1000000000 #define pb push_back #define EPS 1e-9 const int MOD = 1000000007; // 998244353 int t[1000002],pre[1000002],dp[1000002]; int n; string A,B; void pro(){ for (int i = n-1; i >= 0; i--) { int h=(int)(A[i]-'0')^(int)(B[i]-'0'); if(!h)t[i]=-1; else if(i==(n-1)||t[i+1]==-1)t[i]=i; else t[i]=t[i+1]; if(i==(n-1)||(B[i]!=B[i+1]))pre[i]=i; else pre[i]=pre[i+1]; dp[i+1]=INF; } } int solve(){ dp[0]=0; for (int i = 0; i < n; ++i) { if(A[i]==B[i])dp[i+1]=min(dp[i+1],dp[i]); else{ dp[t[i]+1]=min(dp[t[i]+1],dp[i]+1); dp[pre[i]+1]=min(dp[pre[i]+1],dp[i]+1); } } return dp[n]; } int32_t main(){ boost; //freopen(".in","r",stdin); cin>>n; cin>>A>>B; pro(); int ans=solve(); for (int i = 0; i < n; ++i) A[i]=(char)(1-(int)(A[i]-'0')+'0'),pre[i]=t[i]=0; pro(); cout<<min(ans,solve()+1); return 0; } //long long //array bounds //special cases //binary search
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...