This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define rep(a,b) for(int a = 0; a < (b); ++a)
#define all(t) t.begin(), t.end()
#define pb push_back
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
const int N = 1e6+54321, INF = 2e9+54321;
const ll INF_L = (ll)2e18+54321;
int n,wyn;
string A,B;
int dp[N];
void solve()
{
cin >> n >> A >> B;
wyn = 0;
if(A[0] == B[0]) dp[0] = 0;
else dp[0] = 1;
for(int i = 1; i < n; ++i)
{
if(A[i] == B[i]) dp[i] = dp[i-1];
else
{
dp[i] = dp[i-1] + 1;
int idx = i;
while(idx-1 >= 0 and A[idx-1] != B[idx-1]) --idx;
if(idx == 0) dp[i] = min(dp[i],1);
else dp[i] = min(dp[i],dp[idx-1]+1);
int zer = 0, jed = 0;
if(B[i] == '0') zer = 1;
else jed = 1;
for(int j = i; j >= 0; --j)
{
if(j != i and B[j] != B[j+1])
{
if(B[j] == '0') ++zer;
else ++jed;
}
int po = 0;
if(j-1 >= 0) po = dp[j-1];
dp[i] = min(dp[i],po+min(zer,jed)+1);
}
}
}
cout << dp[n-1] << '\n';
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int T = 1;
//cin >> T;
while(T--) solve();
return 0;
}
Compilation message (stderr)
lamp.cpp:10: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
10 | #pragma GCC optimization ("O3")
|
lamp.cpp:11: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
11 | #pragma GCC optimization ("unroll-loops")
|
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |