Submission #105168

#TimeUsernameProblemLanguageResultExecution timeMemory
105168realityLamps (JOI19_lamps)C++17
4 / 100
77 ms18040 KiB
#include "bits/stdc++.h" using namespace std; #define fi first #define se second #define ll long long #define dbg(v) cerr<<#v<<" = "<<v<<'\n' #define vi vector<int> #define vl vector <ll> #define pii pair<int,int> #define vii vector < pii > #define mp make_pair #define db long double #define pb push_back #define all(s) s.begin(),s.end() template < class P , class Q > ostream& operator<<(ostream& stream, pair < P , Q > v){ stream << "(" << v.fi << ',' << v.se << ")"; return stream;} template < class T > ostream& operator<<(ostream& stream, const vector<T> v){ stream << "[ "; for (int i=0; i<(int)v.size(); i++) stream << v[i] << " "; stream << "]"; return stream;} template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;} template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;} const int N = 1e6 + 5; const int oo = 1e9; char A[N]; char B[N]; int dp[N][2]; int d1[N],d2[N]; int main(void) { int n; cin>>n; cin>>(A+1)>>(B+1); dp[0][0] = 0; dp[0][1] = 1; for (int i = 1;i <= n;++i) dp[i][0] = dp[i][1] = oo; for (int i = 1;i <= n;++i) { d1[i] = B[i] == '1' ? d1[i - 1] : i; d2[i] = B[i] == '0' ? d2[i - 1] : i; } for (int i = 1;i <= n;++i) { smin(dp[i][0],min(dp[i - 1][0],dp[i - 1][1]) + (A[i] != B[i])); smin(dp[i][1],min(dp[i - 1][0] + 1,dp[i - 1][1]) + (A[i] == B[i])); int Ind = B[i] == '1' ? d1[i] - 1 : d2[i] - 1; int NInd = B[i] == '1' ? d2[d1[i] - 1] : d1[d2[i] - 1]; smin(dp[i][0],min(dp[Ind][0],dp[Ind][1]) + 1); smin(dp[i][1],min(dp[Ind][0] + 1,dp[Ind][1]) + 1); if (NInd >= 0) smin(dp[i][1],dp[NInd][0] + 2); } cout << min(dp[n][0],dp[n][1]) << '\n'; 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...