# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
376150 | 2021-03-11T02:03:07 Z | daniel920712 | Lamps (JOI19_lamps) | C++14 | 1000 ms | 3052 KB |
#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; //printf("vv %d %d\n",tt,vis[tt]); if(!vis[tt]) { vis[tt]=1; 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; if(!vis[tt]) { vis[tt]=1; 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; if(!vis[tt]) { vis[tt]=1; BFS.push(make_pair(tt,aa+1)); } } } } //printf("%d\n",F(0)); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 464 ms | 1644 KB | Output is correct |
9 | Correct | 479 ms | 1644 KB | Output is correct |
10 | Correct | 214 ms | 876 KB | Output is correct |
11 | Correct | 208 ms | 1068 KB | Output is correct |
12 | Correct | 37 ms | 1388 KB | Output is correct |
13 | Correct | 110 ms | 1004 KB | Output is correct |
14 | Correct | 79 ms | 1516 KB | Output is correct |
15 | Correct | 133 ms | 1056 KB | Output is correct |
16 | Correct | 307 ms | 1644 KB | Output is correct |
17 | Correct | 143 ms | 1132 KB | Output is correct |
18 | Correct | 40 ms | 1388 KB | Output is correct |
19 | Correct | 27 ms | 876 KB | Output is correct |
20 | Correct | 299 ms | 1772 KB | Output is correct |
21 | Correct | 11 ms | 748 KB | Output is correct |
22 | Correct | 35 ms | 1388 KB | Output is correct |
23 | Correct | 75 ms | 1004 KB | Output is correct |
24 | Correct | 2 ms | 748 KB | Output is correct |
25 | Correct | 4 ms | 620 KB | Output is correct |
26 | Correct | 257 ms | 1644 KB | Output is correct |
27 | Correct | 96 ms | 1004 KB | Output is correct |
28 | Correct | 37 ms | 748 KB | Output is correct |
29 | Correct | 393 ms | 1772 KB | Output is correct |
30 | Correct | 182 ms | 1004 KB | Output is correct |
31 | Correct | 3 ms | 508 KB | Output is correct |
32 | Correct | 48 ms | 1388 KB | Output is correct |
33 | Correct | 152 ms | 1024 KB | Output is correct |
34 | Correct | 32 ms | 748 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 464 ms | 1644 KB | Output is correct |
9 | Correct | 479 ms | 1644 KB | Output is correct |
10 | Correct | 214 ms | 876 KB | Output is correct |
11 | Correct | 208 ms | 1068 KB | Output is correct |
12 | Correct | 37 ms | 1388 KB | Output is correct |
13 | Correct | 110 ms | 1004 KB | Output is correct |
14 | Correct | 79 ms | 1516 KB | Output is correct |
15 | Correct | 133 ms | 1056 KB | Output is correct |
16 | Correct | 307 ms | 1644 KB | Output is correct |
17 | Correct | 143 ms | 1132 KB | Output is correct |
18 | Correct | 40 ms | 1388 KB | Output is correct |
19 | Correct | 27 ms | 876 KB | Output is correct |
20 | Correct | 299 ms | 1772 KB | Output is correct |
21 | Correct | 11 ms | 748 KB | Output is correct |
22 | Correct | 35 ms | 1388 KB | Output is correct |
23 | Correct | 75 ms | 1004 KB | Output is correct |
24 | Correct | 2 ms | 748 KB | Output is correct |
25 | Correct | 4 ms | 620 KB | Output is correct |
26 | Correct | 257 ms | 1644 KB | Output is correct |
27 | Correct | 96 ms | 1004 KB | Output is correct |
28 | Correct | 37 ms | 748 KB | Output is correct |
29 | Correct | 393 ms | 1772 KB | Output is correct |
30 | Correct | 182 ms | 1004 KB | Output is correct |
31 | Correct | 3 ms | 508 KB | Output is correct |
32 | Correct | 48 ms | 1388 KB | Output is correct |
33 | Correct | 152 ms | 1024 KB | Output is correct |
34 | Correct | 32 ms | 748 KB | Output is correct |
35 | Runtime error | 1 ms | 492 KB | Execution killed with signal 11 |
36 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 11 ms | 2284 KB | Output is correct |
8 | Execution timed out | 1088 ms | 3052 KB | Time limit exceeded |
9 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 464 ms | 1644 KB | Output is correct |
9 | Correct | 479 ms | 1644 KB | Output is correct |
10 | Correct | 214 ms | 876 KB | Output is correct |
11 | Correct | 208 ms | 1068 KB | Output is correct |
12 | Correct | 37 ms | 1388 KB | Output is correct |
13 | Correct | 110 ms | 1004 KB | Output is correct |
14 | Correct | 79 ms | 1516 KB | Output is correct |
15 | Correct | 133 ms | 1056 KB | Output is correct |
16 | Correct | 307 ms | 1644 KB | Output is correct |
17 | Correct | 143 ms | 1132 KB | Output is correct |
18 | Correct | 40 ms | 1388 KB | Output is correct |
19 | Correct | 27 ms | 876 KB | Output is correct |
20 | Correct | 299 ms | 1772 KB | Output is correct |
21 | Correct | 11 ms | 748 KB | Output is correct |
22 | Correct | 35 ms | 1388 KB | Output is correct |
23 | Correct | 75 ms | 1004 KB | Output is correct |
24 | Correct | 2 ms | 748 KB | Output is correct |
25 | Correct | 4 ms | 620 KB | Output is correct |
26 | Correct | 257 ms | 1644 KB | Output is correct |
27 | Correct | 96 ms | 1004 KB | Output is correct |
28 | Correct | 37 ms | 748 KB | Output is correct |
29 | Correct | 393 ms | 1772 KB | Output is correct |
30 | Correct | 182 ms | 1004 KB | Output is correct |
31 | Correct | 3 ms | 508 KB | Output is correct |
32 | Correct | 48 ms | 1388 KB | Output is correct |
33 | Correct | 152 ms | 1024 KB | Output is correct |
34 | Correct | 32 ms | 748 KB | Output is correct |
35 | Runtime error | 1 ms | 492 KB | Execution killed with signal 11 |
36 | Halted | 0 ms | 0 KB | - |