Submission #376148

#TimeUsernameProblemLanguageResultExecution timeMemory
376148daniel920712Lamps (JOI19_lamps)C++14
0 / 100
612 ms262148 KiB
#include <iostream> #include <stdio.h> #include <stdlib.h> #include <queue> using namespace std; char a[1000005]; char b[1000005]; bool have[1000005]={0}; int DP[1000005],N; bool vis[1000005]={0}; queue < pair < int , int > > BFS; int F(int here) { int i,tt; if(here==N) return 0; if(have[here]) return DP[here]; have[here]=1; if(a[here]==b[here]) DP[here]=F(here+1); else DP[here]=F(here+1)+1; tt=0; for(i=here;i<N;i++) { if(b[i]=='1'&&(i==here||b[i-1]=='0')) tt++; DP[here]=min(DP[here],F(i+1)+tt+1); } tt=0; for(i=here;i<N;i++) { if(b[i]=='0'&&(i==here||b[i-1]=='1')) tt++; DP[here]=min(DP[here],F(i+1)+tt+1); } tt=0; for(i=here;i<N;i++) { if(a[i]==b[i]&&(i==here||a[i-1]!=b[i-1])) tt++; DP[here]=min(DP[here],F(i+1)+tt+1); } return DP[here]; } int main() { int M,ans=0,i,j,x=0,y=0,aa,tt; scanf("%d",&N); scanf("%s %s",a,b); x=y=0; for(i=0;i<N;i++) { x*=2; x+=a[i]-'0'; y*=2; y+=b[i]-'0'; } BFS.push(make_pair(x,0)); while(!BFS.empty()) { x=BFS.front().first; aa=BFS.front().second; BFS.pop(); if(vis[x]) continue; vis[x]=1; //printf("%d %d %d\n",x,y,aa); if(x==y) { printf("%d\n",aa); return 0; } tt=0; for(i=0;i<N;i++) { tt=x; for(j=i;j<N;j++) { if(tt&(1<<j)) tt-=1<<j; BFS.push(make_pair(tt,aa+1)); } } for(i=0;i<N;i++) { tt=x; for(j=i;j<N;j++) { if(!(tt&(1<<j))) tt+=1<<j; BFS.push(make_pair(tt,aa+1)); } } for(i=0;i<N;i++) { tt=x; for(j=i;j<N;j++) { if(!(tt&(1<<j))) tt+=1<<j; else tt-=1<<j; BFS.push(make_pair(tt,aa+1)); } } } //printf("%d\n",F(0)); return 0; }

Compilation message (stderr)

lamp.cpp: In function 'int main()':
lamp.cpp:45:9: warning: unused variable 'M' [-Wunused-variable]
   45 |     int M,ans=0,i,j,x=0,y=0,aa,tt;
      |         ^
lamp.cpp:45:11: warning: unused variable 'ans' [-Wunused-variable]
   45 |     int M,ans=0,i,j,x=0,y=0,aa,tt;
      |           ^~~
lamp.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   46 |     scanf("%d",&N);
      |     ~~~~~^~~~~~~~~
lamp.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   47 |     scanf("%s %s",a,b);
      |     ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...