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>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
#define ull unsigned ll
using namespace std;
const int nmax = 1001;
int32_t main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int n; cin >> n;
char a[n + 1], b[n + 1];
for(int i = 1; i <= n; i++)
cin >> a[i];
for(int j = 1; j <= n; j++){
cin >> b[j];
}
int dp[n + 1][8];
for(int i = 0; i <= n; ++i){
for(int j = 0; j < 8; j++)
dp[i][j] = 1e9;
}
dp[0][0] = 0;
for(int i =1 ; i <= n; i++){
for(int x = 0; x < 8; x++){
if((x & 3) == 3) continue;
for(int y = 0; y < 8; y++){
if((y & 3) == 3) continue;
int cost = __builtin_popcount((x ^ y) & y);
int nw = a[i] - '0';
if(y & 1) nw = 0;
if(y & 2) nw = 1;
if(y & 4) nw ^= 1;
if(nw == (b[i] - '0'))
dp[i][y] = min(dp[i][y], dp[i - 1][x] + cost);
}
}
}
int ans = 1e9;
for(int j = 0; j < 8; j++)
ans = min(ans, dp[n][j]);
cout << ans;
return 0;
}
# | 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... |