이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define nl "\n"
#define all(v) v.begin(),v.end()
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
int main() {
fast
ll n;
cin>>n;
string a,b;
cin>>a>>b;
ll dp[n+10][3][2];
memset(dp,0x3f, sizeof(dp));
dp[n][0][0]=0;
for(ll i=n-1;i>=0;i--){
for(ll j=0;j<3;j++){
for(ll k=0;k<2;k++){
ll val=a[i]-'0';
if(j==1)val=0;
if(j==2)val=1;
if(k==1)val^=1;
if(val!=(b[i]-'0'))continue;
for(ll j2=0;j2<3;j2++){
for(ll k2=0;k2<2;k2++){
dp[i][j][k]=min(dp[i][j][k],dp[i+1][j2][k2]+(j>0&&j!=j2)+(k>0&&k2!=k));
}
}
}
}
}
ll ans=1e18;
for(ll j=0;j<3;j++)
for(ll k=0;k<2;k++)ans=min(ans,dp[0][j][k]);
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... |