Submission #384437

# Submission time Handle Problem Language Result Execution time Memory
384437 2021-04-01T16:43:39 Z ogibogi2004 Lamps (JOI19_lamps) C++14
100 / 100
504 ms 72952 KB
#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e6+6;
int dp[MAXN][4][4];
/*
 * 0 - nothing
 * 1 - flip
 * 2 - 0
 * 3 - 1
*/
int a[MAXN],b[MAXN];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		char c;
		cin>>c;
		a[i]=c-'0';
	}
	for(int i=1;i<=n;i++)
	{
		char c;
		cin>>c;
		b[i]=c-'0';
	}
	for(int i=0;i<MAXN;i++)
	{
		for(int i1=0;i1<4;i1++)
		for(int i2=0;i2<4;i2++)
		{
			dp[i][i1][i2]=MAXN+1;
		}
	}
	dp[0][0][0]=0;
	for(int i=1;i<=n;i++)
	{
		for(int i1=0;i1<4;i1++)
		for(int i2=0;i2<4;i2++)
		{
			if(i1==0&&i2!=0)continue;
			int a1=a[i];
			if(i1==1)a1=1-a1;
			if(i1==2)a1=0;
			if(i1==3)a1=1;
			if(i2==1)a1=1-a1;
			if(i2==2)a1=0;
			if(i2==3)a1=1;
			if(a1!=b[i])continue;
			dp[i][i1][i2]=min(dp[i][i1][i2],dp[i-1][i1][i2]);
			for(int j=0;j<4;j++)dp[i][i1][i2]=min(dp[i][i1][i2],dp[i-1][i1][j]+(i2>0));
			for(int j=0;j<4;j++)dp[i][i1][i2]=min(dp[i][i1][i2],dp[i-1][j][i1]+(i2>0));
			for(int j=0;j<4;j++)dp[i][i1][i2]=min(dp[i][i1][i2],dp[i-1][i2][j]+(i1>0));
			for(int j=0;j<4;j++)dp[i][i1][i2]=min(dp[i][i1][i2],dp[i-1][j][i2]+(i1>0));
			for(int j1=0;j1<4;j1++)for(int j2=0;j2<4;j2++)dp[i][i1][i2]=min(dp[i][i1][i2],dp[i-1][j1][j2]+(i1>0)+(i2>0));
		}
		/*cout<<i<<":\n";
		for(int i1=0;i1<2;i1++)
		for(int i2=0;i2<2;i2++)
		for(int i3=0;i3<2;i3++)
		{
			cout<<i1<<" "<<i2<<" "<<i3<<" "<<dp[i][i1][i2][i3]<<endl;
		}*/
	}
	int ans=MAXN;
	for(int i1=0;i1<4;i1++)
	for(int i2=0;i2<4;i2++)
	{
		ans=min(ans,dp[n][i1][i2]);
	}
	cout<<ans<<endl;
return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 38 ms 62956 KB Output is correct
2 Correct 38 ms 62956 KB Output is correct
3 Correct 38 ms 62956 KB Output is correct
4 Correct 38 ms 62956 KB Output is correct
5 Correct 38 ms 62956 KB Output is correct
6 Correct 38 ms 62956 KB Output is correct
7 Correct 38 ms 62956 KB Output is correct
8 Correct 38 ms 62956 KB Output is correct
9 Correct 38 ms 62956 KB Output is correct
10 Correct 42 ms 62956 KB Output is correct
11 Correct 38 ms 62956 KB Output is correct
12 Correct 37 ms 62956 KB Output is correct
13 Correct 40 ms 62956 KB Output is correct
14 Correct 39 ms 62956 KB Output is correct
15 Correct 38 ms 62956 KB Output is correct
16 Correct 39 ms 62956 KB Output is correct
17 Correct 38 ms 62956 KB Output is correct
18 Correct 38 ms 62956 KB Output is correct
19 Correct 39 ms 62956 KB Output is correct
20 Correct 38 ms 62988 KB Output is correct
21 Correct 38 ms 62956 KB Output is correct
22 Correct 38 ms 62956 KB Output is correct
23 Correct 38 ms 62956 KB Output is correct
24 Correct 38 ms 62956 KB Output is correct
25 Correct 38 ms 62956 KB Output is correct
26 Correct 38 ms 62956 KB Output is correct
27 Correct 42 ms 63084 KB Output is correct
28 Correct 39 ms 62988 KB Output is correct
29 Correct 38 ms 62956 KB Output is correct
30 Correct 38 ms 62956 KB Output is correct
31 Correct 39 ms 62972 KB Output is correct
32 Correct 38 ms 62956 KB Output is correct
33 Correct 38 ms 62956 KB Output is correct
34 Correct 38 ms 62956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 62956 KB Output is correct
2 Correct 38 ms 62956 KB Output is correct
3 Correct 38 ms 62956 KB Output is correct
4 Correct 38 ms 62956 KB Output is correct
5 Correct 38 ms 62956 KB Output is correct
6 Correct 38 ms 62956 KB Output is correct
7 Correct 38 ms 62956 KB Output is correct
8 Correct 38 ms 62956 KB Output is correct
9 Correct 38 ms 62956 KB Output is correct
10 Correct 42 ms 62956 KB Output is correct
11 Correct 38 ms 62956 KB Output is correct
12 Correct 37 ms 62956 KB Output is correct
13 Correct 40 ms 62956 KB Output is correct
14 Correct 39 ms 62956 KB Output is correct
15 Correct 38 ms 62956 KB Output is correct
16 Correct 39 ms 62956 KB Output is correct
17 Correct 38 ms 62956 KB Output is correct
18 Correct 38 ms 62956 KB Output is correct
19 Correct 39 ms 62956 KB Output is correct
20 Correct 38 ms 62988 KB Output is correct
21 Correct 38 ms 62956 KB Output is correct
22 Correct 38 ms 62956 KB Output is correct
23 Correct 38 ms 62956 KB Output is correct
24 Correct 38 ms 62956 KB Output is correct
25 Correct 38 ms 62956 KB Output is correct
26 Correct 38 ms 62956 KB Output is correct
27 Correct 42 ms 63084 KB Output is correct
28 Correct 39 ms 62988 KB Output is correct
29 Correct 38 ms 62956 KB Output is correct
30 Correct 38 ms 62956 KB Output is correct
31 Correct 39 ms 62972 KB Output is correct
32 Correct 38 ms 62956 KB Output is correct
33 Correct 38 ms 62956 KB Output is correct
34 Correct 38 ms 62956 KB Output is correct
35 Correct 38 ms 62956 KB Output is correct
36 Correct 40 ms 62956 KB Output is correct
37 Correct 39 ms 62956 KB Output is correct
38 Correct 41 ms 62956 KB Output is correct
39 Correct 38 ms 62956 KB Output is correct
40 Correct 39 ms 63084 KB Output is correct
41 Correct 42 ms 62956 KB Output is correct
42 Correct 39 ms 62956 KB Output is correct
43 Correct 39 ms 63084 KB Output is correct
44 Correct 39 ms 62956 KB Output is correct
45 Correct 40 ms 62956 KB Output is correct
46 Correct 45 ms 62956 KB Output is correct
47 Correct 39 ms 62956 KB Output is correct
48 Correct 40 ms 63104 KB Output is correct
49 Correct 38 ms 62956 KB Output is correct
50 Correct 38 ms 62956 KB Output is correct
51 Correct 39 ms 62956 KB Output is correct
52 Correct 39 ms 62956 KB Output is correct
53 Correct 39 ms 62956 KB Output is correct
54 Correct 39 ms 62956 KB Output is correct
55 Correct 41 ms 62956 KB Output is correct
56 Correct 39 ms 62956 KB Output is correct
57 Correct 40 ms 63084 KB Output is correct
58 Correct 39 ms 62956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 62956 KB Output is correct
2 Correct 38 ms 62956 KB Output is correct
3 Correct 39 ms 62956 KB Output is correct
4 Correct 39 ms 62956 KB Output is correct
5 Correct 38 ms 62956 KB Output is correct
6 Correct 38 ms 62956 KB Output is correct
7 Correct 475 ms 70820 KB Output is correct
8 Correct 464 ms 70892 KB Output is correct
9 Correct 482 ms 70924 KB Output is correct
10 Correct 481 ms 70764 KB Output is correct
11 Correct 467 ms 70916 KB Output is correct
12 Correct 431 ms 70764 KB Output is correct
13 Correct 465 ms 70792 KB Output is correct
14 Correct 456 ms 70764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 62956 KB Output is correct
2 Correct 38 ms 62956 KB Output is correct
3 Correct 38 ms 62956 KB Output is correct
4 Correct 38 ms 62956 KB Output is correct
5 Correct 38 ms 62956 KB Output is correct
6 Correct 38 ms 62956 KB Output is correct
7 Correct 38 ms 62956 KB Output is correct
8 Correct 38 ms 62956 KB Output is correct
9 Correct 38 ms 62956 KB Output is correct
10 Correct 42 ms 62956 KB Output is correct
11 Correct 38 ms 62956 KB Output is correct
12 Correct 37 ms 62956 KB Output is correct
13 Correct 40 ms 62956 KB Output is correct
14 Correct 39 ms 62956 KB Output is correct
15 Correct 38 ms 62956 KB Output is correct
16 Correct 39 ms 62956 KB Output is correct
17 Correct 38 ms 62956 KB Output is correct
18 Correct 38 ms 62956 KB Output is correct
19 Correct 39 ms 62956 KB Output is correct
20 Correct 38 ms 62988 KB Output is correct
21 Correct 38 ms 62956 KB Output is correct
22 Correct 38 ms 62956 KB Output is correct
23 Correct 38 ms 62956 KB Output is correct
24 Correct 38 ms 62956 KB Output is correct
25 Correct 38 ms 62956 KB Output is correct
26 Correct 38 ms 62956 KB Output is correct
27 Correct 42 ms 63084 KB Output is correct
28 Correct 39 ms 62988 KB Output is correct
29 Correct 38 ms 62956 KB Output is correct
30 Correct 38 ms 62956 KB Output is correct
31 Correct 39 ms 62972 KB Output is correct
32 Correct 38 ms 62956 KB Output is correct
33 Correct 38 ms 62956 KB Output is correct
34 Correct 38 ms 62956 KB Output is correct
35 Correct 38 ms 62956 KB Output is correct
36 Correct 40 ms 62956 KB Output is correct
37 Correct 39 ms 62956 KB Output is correct
38 Correct 41 ms 62956 KB Output is correct
39 Correct 38 ms 62956 KB Output is correct
40 Correct 39 ms 63084 KB Output is correct
41 Correct 42 ms 62956 KB Output is correct
42 Correct 39 ms 62956 KB Output is correct
43 Correct 39 ms 63084 KB Output is correct
44 Correct 39 ms 62956 KB Output is correct
45 Correct 40 ms 62956 KB Output is correct
46 Correct 45 ms 62956 KB Output is correct
47 Correct 39 ms 62956 KB Output is correct
48 Correct 40 ms 63104 KB Output is correct
49 Correct 38 ms 62956 KB Output is correct
50 Correct 38 ms 62956 KB Output is correct
51 Correct 39 ms 62956 KB Output is correct
52 Correct 39 ms 62956 KB Output is correct
53 Correct 39 ms 62956 KB Output is correct
54 Correct 39 ms 62956 KB Output is correct
55 Correct 41 ms 62956 KB Output is correct
56 Correct 39 ms 62956 KB Output is correct
57 Correct 40 ms 63084 KB Output is correct
58 Correct 39 ms 62956 KB Output is correct
59 Correct 38 ms 62956 KB Output is correct
60 Correct 38 ms 62956 KB Output is correct
61 Correct 39 ms 62956 KB Output is correct
62 Correct 39 ms 62956 KB Output is correct
63 Correct 38 ms 62956 KB Output is correct
64 Correct 38 ms 62956 KB Output is correct
65 Correct 475 ms 70820 KB Output is correct
66 Correct 464 ms 70892 KB Output is correct
67 Correct 482 ms 70924 KB Output is correct
68 Correct 481 ms 70764 KB Output is correct
69 Correct 467 ms 70916 KB Output is correct
70 Correct 431 ms 70764 KB Output is correct
71 Correct 465 ms 70792 KB Output is correct
72 Correct 456 ms 70764 KB Output is correct
73 Correct 462 ms 72684 KB Output is correct
74 Correct 487 ms 72684 KB Output is correct
75 Correct 454 ms 72684 KB Output is correct
76 Correct 452 ms 72812 KB Output is correct
77 Correct 504 ms 72728 KB Output is correct
78 Correct 468 ms 72812 KB Output is correct
79 Correct 494 ms 72952 KB Output is correct
80 Correct 470 ms 72684 KB Output is correct
81 Correct 464 ms 72684 KB Output is correct
82 Correct 465 ms 72812 KB Output is correct
83 Correct 463 ms 72832 KB Output is correct
84 Correct 460 ms 72812 KB Output is correct
85 Correct 456 ms 72684 KB Output is correct
86 Correct 461 ms 72684 KB Output is correct
87 Correct 465 ms 72792 KB Output is correct
88 Correct 462 ms 72812 KB Output is correct
89 Correct 461 ms 72916 KB Output is correct
90 Correct 477 ms 72812 KB Output is correct
91 Correct 474 ms 72772 KB Output is correct
92 Correct 480 ms 72684 KB Output is correct
93 Correct 496 ms 72684 KB Output is correct
94 Correct 492 ms 72812 KB Output is correct
95 Correct 481 ms 72812 KB Output is correct
96 Correct 474 ms 72684 KB Output is correct
97 Correct 469 ms 72800 KB Output is correct
98 Correct 470 ms 72684 KB Output is correct
99 Correct 468 ms 72792 KB Output is correct
100 Correct 476 ms 72812 KB Output is correct
101 Correct 469 ms 72800 KB Output is correct
102 Correct 468 ms 72940 KB Output is correct