이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int nmax=1e6+42;
int dp[nmax][3][2];
/*dp[pos][type_1][type_2]
type_1: 0->set 0, 1->set 1, 2->nothing
type_2: 0->nothing, 1-> flip
*/
int n;
string a,b;
int rec(int pos,int type_1,int type_2)
{
if(pos==n)return 0;
if(dp[pos][type_1][type_2]!=-1)return dp[pos][type_1][type_2];
int ret=2*n;
for(int type_1_new=0;type_1_new<3;type_1_new++)
for(int type_2_new=0;type_2_new<2;type_2_new++)
{
char cur=a[pos];
if(type_1_new==0)cur='0';
if(type_1_new==1)cur='1';
if(type_2_new==1)cur='1'-cur+'0';
if(cur==b[pos])
{
int add=0;
if(type_1_new!=2&&type_1_new!=type_1)add++;
if(type_2==0&&type_2_new==1)add++;
ret=min(ret,add+rec(pos+1,type_1_new,type_2_new));
}
}
dp[pos][type_1][type_2]=ret;
//cout<<pos<<" "<<type_1<<" "<<type_2<<" -> "<<ret<<endl;
return ret;
}
int main()
{
memset(dp,-1,sizeof(dp));
ios_base::sync_with_stdio(false);
cin>>n;
cin>>a>>b;
cout<<rec(0,2,0)<<endl;
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... |