Submission #129163

# Submission time Handle Problem Language Result Execution time Memory
129163 2019-07-11T18:33:01 Z mohammedehab2002 Lamps (JOI19_lamps) C++11
100 / 100
248 ms 75080 KB
#include <iostream>
using namespace std;
int dp[4][4][1000005],tpt[2][1000005];
int main()
{
	int n;
	string a,b;
	cin >> n >> a >> b;
	for (int j=0;j<4;j++)
	{
		for (int k=0;k<4;k++)
		dp[j][k][0]=1e9;
	}
	dp[3][3][0]=0;
	tpt[0][0]=1e9;
	tpt[1][0]=1e9;
	for (int i=0;i<=n;i++)
	{
		int mn=min(tpt[0][i],tpt[1][i]),md[4];
		for (int j=0;j<4;j++)
		md[j]=1e9;
		md[2]=min(md[2],mn);
		md[0]=min(md[0],tpt[0][i]);
		md[1]=min(md[1],tpt[1][i]);
		for (int j=0;j<4;j++)
		{
			for (int k=0;k<4;k++)
			{
				dp[j][k][i+1]=1e9;
				mn=min(mn,dp[j][k][i]);
				md[j]=min(md[j],dp[j][k][i]);
				md[k]=min(md[k],dp[j][k][i]);
			}
		}
		if (i==n)
		{
			printf("%d",mn);
			return 0;
		}
		if (a[i]==b[i])
		dp[3][3][i+1]=mn;
		else
		dp[2][3][i+1]=min(mn+1,md[2]);
		bool cur=b[i]-'0';
		dp[!cur][2][i+1]=min(min(min(md[!cur]+1,md[2]+1),min(dp[!cur][2][i],mn+2)),tpt[!cur][i]);
		dp[2][cur][i+1]=min(min(min(md[2]+1,md[cur]+1),min(dp[2][cur][i],mn+2)),tpt[cur][i]);
		dp[cur][3][i+1]=min(md[cur],mn+1);
		tpt[cur][i+1]=1e9;
		tpt[!cur][i+1]=min(min(min(tpt[!cur][i],mn+3),min(md[2],md[!cur])+2),min(min(dp[2][!cur][i],dp[!cur][2][i]),tpt[cur][i])+1);
	}
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 508 KB Output is correct
14 Correct 2 ms 524 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 524 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 504 KB Output is correct
21 Correct 2 ms 504 KB Output is correct
22 Correct 2 ms 504 KB Output is correct
23 Correct 2 ms 504 KB Output is correct
24 Correct 2 ms 504 KB Output is correct
25 Correct 2 ms 504 KB Output is correct
26 Correct 2 ms 380 KB Output is correct
27 Correct 2 ms 504 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 2 ms 504 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 508 KB Output is correct
32 Correct 2 ms 504 KB Output is correct
33 Correct 2 ms 504 KB Output is correct
34 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 508 KB Output is correct
14 Correct 2 ms 524 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 524 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 504 KB Output is correct
21 Correct 2 ms 504 KB Output is correct
22 Correct 2 ms 504 KB Output is correct
23 Correct 2 ms 504 KB Output is correct
24 Correct 2 ms 504 KB Output is correct
25 Correct 2 ms 504 KB Output is correct
26 Correct 2 ms 380 KB Output is correct
27 Correct 2 ms 504 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 2 ms 504 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 508 KB Output is correct
32 Correct 2 ms 504 KB Output is correct
33 Correct 2 ms 504 KB Output is correct
34 Correct 2 ms 504 KB Output is correct
35 Correct 3 ms 632 KB Output is correct
36 Correct 3 ms 632 KB Output is correct
37 Correct 3 ms 632 KB Output is correct
38 Correct 3 ms 632 KB Output is correct
39 Correct 3 ms 632 KB Output is correct
40 Correct 3 ms 632 KB Output is correct
41 Correct 3 ms 632 KB Output is correct
42 Correct 3 ms 632 KB Output is correct
43 Correct 3 ms 632 KB Output is correct
44 Correct 3 ms 632 KB Output is correct
45 Correct 3 ms 632 KB Output is correct
46 Correct 3 ms 636 KB Output is correct
47 Correct 8 ms 628 KB Output is correct
48 Correct 3 ms 632 KB Output is correct
49 Correct 3 ms 632 KB Output is correct
50 Correct 3 ms 632 KB Output is correct
51 Correct 3 ms 632 KB Output is correct
52 Correct 3 ms 632 KB Output is correct
53 Correct 3 ms 632 KB Output is correct
54 Correct 3 ms 632 KB Output is correct
55 Correct 3 ms 632 KB Output is correct
56 Correct 2 ms 632 KB Output is correct
57 Correct 3 ms 632 KB Output is correct
58 Correct 3 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 229 ms 73316 KB Output is correct
8 Correct 227 ms 73316 KB Output is correct
9 Correct 229 ms 73168 KB Output is correct
10 Correct 228 ms 73240 KB Output is correct
11 Correct 227 ms 73364 KB Output is correct
12 Correct 231 ms 73304 KB Output is correct
13 Correct 228 ms 73328 KB Output is correct
14 Correct 228 ms 73148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 508 KB Output is correct
14 Correct 2 ms 524 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 524 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 504 KB Output is correct
21 Correct 2 ms 504 KB Output is correct
22 Correct 2 ms 504 KB Output is correct
23 Correct 2 ms 504 KB Output is correct
24 Correct 2 ms 504 KB Output is correct
25 Correct 2 ms 504 KB Output is correct
26 Correct 2 ms 380 KB Output is correct
27 Correct 2 ms 504 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 2 ms 504 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 508 KB Output is correct
32 Correct 2 ms 504 KB Output is correct
33 Correct 2 ms 504 KB Output is correct
34 Correct 2 ms 504 KB Output is correct
35 Correct 3 ms 632 KB Output is correct
36 Correct 3 ms 632 KB Output is correct
37 Correct 3 ms 632 KB Output is correct
38 Correct 3 ms 632 KB Output is correct
39 Correct 3 ms 632 KB Output is correct
40 Correct 3 ms 632 KB Output is correct
41 Correct 3 ms 632 KB Output is correct
42 Correct 3 ms 632 KB Output is correct
43 Correct 3 ms 632 KB Output is correct
44 Correct 3 ms 632 KB Output is correct
45 Correct 3 ms 632 KB Output is correct
46 Correct 3 ms 636 KB Output is correct
47 Correct 8 ms 628 KB Output is correct
48 Correct 3 ms 632 KB Output is correct
49 Correct 3 ms 632 KB Output is correct
50 Correct 3 ms 632 KB Output is correct
51 Correct 3 ms 632 KB Output is correct
52 Correct 3 ms 632 KB Output is correct
53 Correct 3 ms 632 KB Output is correct
54 Correct 3 ms 632 KB Output is correct
55 Correct 3 ms 632 KB Output is correct
56 Correct 2 ms 632 KB Output is correct
57 Correct 3 ms 632 KB Output is correct
58 Correct 3 ms 632 KB Output is correct
59 Correct 2 ms 504 KB Output is correct
60 Correct 2 ms 384 KB Output is correct
61 Correct 3 ms 504 KB Output is correct
62 Correct 2 ms 504 KB Output is correct
63 Correct 2 ms 504 KB Output is correct
64 Correct 2 ms 504 KB Output is correct
65 Correct 229 ms 73316 KB Output is correct
66 Correct 227 ms 73316 KB Output is correct
67 Correct 229 ms 73168 KB Output is correct
68 Correct 228 ms 73240 KB Output is correct
69 Correct 227 ms 73364 KB Output is correct
70 Correct 231 ms 73304 KB Output is correct
71 Correct 228 ms 73328 KB Output is correct
72 Correct 228 ms 73148 KB Output is correct
73 Correct 233 ms 74972 KB Output is correct
74 Correct 234 ms 74820 KB Output is correct
75 Correct 228 ms 74852 KB Output is correct
76 Correct 228 ms 74856 KB Output is correct
77 Correct 228 ms 74980 KB Output is correct
78 Correct 229 ms 74812 KB Output is correct
79 Correct 227 ms 74852 KB Output is correct
80 Correct 228 ms 74864 KB Output is correct
81 Correct 228 ms 74800 KB Output is correct
82 Correct 228 ms 74868 KB Output is correct
83 Correct 240 ms 74852 KB Output is correct
84 Correct 240 ms 74908 KB Output is correct
85 Correct 235 ms 74980 KB Output is correct
86 Correct 235 ms 74848 KB Output is correct
87 Correct 235 ms 74784 KB Output is correct
88 Correct 235 ms 74980 KB Output is correct
89 Correct 235 ms 74856 KB Output is correct
90 Correct 235 ms 74980 KB Output is correct
91 Correct 241 ms 74816 KB Output is correct
92 Correct 243 ms 74768 KB Output is correct
93 Correct 243 ms 74988 KB Output is correct
94 Correct 243 ms 74804 KB Output is correct
95 Correct 247 ms 74852 KB Output is correct
96 Correct 244 ms 74980 KB Output is correct
97 Correct 247 ms 75080 KB Output is correct
98 Correct 245 ms 75064 KB Output is correct
99 Correct 244 ms 74852 KB Output is correct
100 Correct 248 ms 74836 KB Output is correct
101 Correct 247 ms 74804 KB Output is correct
102 Correct 243 ms 74980 KB Output is correct