Submission #138145

#TimeUsernameProblemLanguageResultExecution timeMemory
138145Bodo171Lamps (JOI19_lamps)C++14
0 / 100
2 ms376 KiB
#include <iostream> #include <fstream> using namespace std; int dp[2][10]; int cst,i,j,k,n,use,x,y,ans; string a,b; bool valid(int x,int y,int mov) { if(mov/3) { mov-=3; if(mov)return ((mov-1)^y); return (x^y); } return ((mov%3)-1==y); } int main() { //freopen("data.in","r",stdin); ios_base::sync_with_stdio(false); cin>>n; cin>>a>>b; for(i=1;i<6;i++) dp[0][i]=(1<<30); for(i=0;i<n;i++) { use=1-use; x=a[i]-'0';y=b[i]-'0'; for(j=0;j<6;j++) dp[use][j]=(1<<30); for(j=0;j<6;j++) if(valid(x,y,j)) for(k=0;k<6;k++) { cst=(((j%3)!=(k%3)&&(j%3!=0))+((j/3)>(k/3))); dp[use][j]=min(dp[use][j],dp[1-use][k]+cst); } } ans=(1<<30); for(j=0;j<6;j++) ans=min(ans,dp[use][j]); cout<<ans; 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...