Submission #977216

# Submission time Handle Problem Language Result Execution time Memory
977216 2024-05-07T14:17:26 Z happy_node Lamps (JOI19_lamps) C++17
100 / 100
387 ms 77960 KB
#include <bits/stdc++.h>
using namespace std;

const int MX=2e6+5;
int N;
string A,B;

int dp[MX][8];
vector<pair<int,int>> adj[8];

bool can(int k, char s, char t) {
	if(s=='#') return true;
	assert(t!='#');
	int a=s-'0',b=t-'0';

	if(k==0) {
		return a==b;
	}
	if(k==1) {
		a^=1;
		return a==b;
	}
	if(k==2) {
		a=0;
		a^=1;
		return a==b;
	}
	if(k==3) {
		a^=1;
		a=0;
		return a==b;
	}
	if(k==4) {
		a=1;
		a^=1;
		return a==b;
	}
	if(k==5) {
		a^=1;
		a=1;
		return a==b;
	}
	if(k==6) {
		a=0;
		return a==b;
	}
	if(k==7) {
		a=1;
		return a==b;
	}
	assert(0);
	return 0;
}

void edge(int u, int v, int w) {
	adj[u].push_back({v,w});
}

int main() {
	cin.tie(0); ios_base::sync_with_stdio(0);

	for(int i=0;i<MX;i++) {
		for(int j=0;j<8;j++) {
			dp[i][j]=1e9;
		}
	}

	edge(0,0,0);
	edge(1,1,0);
	edge(2,2,0);
	edge(3,3,0);
	edge(4,4,0);
	edge(5,5,0);
	edge(6,6,0);
	edge(7,7,0);

	edge(0,1,1);
	edge(0,2,2);
	edge(0,3,2);
	edge(0,4,2);
	edge(0,5,2);
	edge(0,6,1);
	edge(0,7,1);

	edge(1,0,0);
	edge(2,0,0);
	edge(3,0,0);
	edge(4,0,0);
	edge(5,0,0);
	edge(6,0,0);
	edge(7,0,0);

	edge(1,2,1);
	edge(1,3,1);
	edge(1,4,1);
	edge(1,5,1);
	edge(2,1,0);
	edge(3,1,0);
	edge(4,1,0);
	edge(5,1,0);

	edge(6,2,1);
	edge(6,3,1);
	edge(2,6,0);
	edge(3,6,0);

	edge(7,4,1);
	edge(7,5,1);
	edge(4,7,0);
	edge(5,7,0);

	cin>>N;

	cin>>A>>B;

	string S="",T="";
	for(int i=0;i<N;i++) {
		S+=A[i];
		S+='#';
	}
	for(int i=0;i<N;i++) {
		T+=B[i];
		T+='#';
	}
	N*=2;

	dp[0][0]=0;

	for(int i=0;i<N;i++) {
		for(int j=0;j<8;j++) {
			for(auto [k,w]:adj[j]) {
				if(can(k,S[i],T[i])) {
					dp[i+1][k]=min(dp[i+1][k],dp[i][j]+w);
				}
			}		
		}
	}

	cout<<dp[N][0]<<'\n';
}
# Verdict Execution time Memory Grader output
1 Correct 27 ms 63068 KB Output is correct
2 Correct 13 ms 63064 KB Output is correct
3 Correct 12 ms 63080 KB Output is correct
4 Correct 14 ms 63324 KB Output is correct
5 Correct 14 ms 63068 KB Output is correct
6 Correct 12 ms 63064 KB Output is correct
7 Correct 12 ms 63064 KB Output is correct
8 Correct 12 ms 62944 KB Output is correct
9 Correct 12 ms 63068 KB Output is correct
10 Correct 13 ms 63068 KB Output is correct
11 Correct 13 ms 63064 KB Output is correct
12 Correct 13 ms 63064 KB Output is correct
13 Correct 12 ms 63068 KB Output is correct
14 Correct 12 ms 63068 KB Output is correct
15 Correct 12 ms 63068 KB Output is correct
16 Correct 13 ms 62892 KB Output is correct
17 Correct 12 ms 62932 KB Output is correct
18 Correct 12 ms 62896 KB Output is correct
19 Correct 12 ms 63064 KB Output is correct
20 Correct 12 ms 63068 KB Output is correct
21 Correct 13 ms 63068 KB Output is correct
22 Correct 12 ms 62940 KB Output is correct
23 Correct 12 ms 63068 KB Output is correct
24 Correct 12 ms 63080 KB Output is correct
25 Correct 12 ms 62936 KB Output is correct
26 Correct 12 ms 63324 KB Output is correct
27 Correct 12 ms 62932 KB Output is correct
28 Correct 12 ms 62924 KB Output is correct
29 Correct 13 ms 62936 KB Output is correct
30 Correct 12 ms 63068 KB Output is correct
31 Correct 12 ms 62948 KB Output is correct
32 Correct 14 ms 63064 KB Output is correct
33 Correct 14 ms 63068 KB Output is correct
34 Correct 13 ms 63068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 63068 KB Output is correct
2 Correct 13 ms 63064 KB Output is correct
3 Correct 12 ms 63080 KB Output is correct
4 Correct 14 ms 63324 KB Output is correct
5 Correct 14 ms 63068 KB Output is correct
6 Correct 12 ms 63064 KB Output is correct
7 Correct 12 ms 63064 KB Output is correct
8 Correct 12 ms 62944 KB Output is correct
9 Correct 12 ms 63068 KB Output is correct
10 Correct 13 ms 63068 KB Output is correct
11 Correct 13 ms 63064 KB Output is correct
12 Correct 13 ms 63064 KB Output is correct
13 Correct 12 ms 63068 KB Output is correct
14 Correct 12 ms 63068 KB Output is correct
15 Correct 12 ms 63068 KB Output is correct
16 Correct 13 ms 62892 KB Output is correct
17 Correct 12 ms 62932 KB Output is correct
18 Correct 12 ms 62896 KB Output is correct
19 Correct 12 ms 63064 KB Output is correct
20 Correct 12 ms 63068 KB Output is correct
21 Correct 13 ms 63068 KB Output is correct
22 Correct 12 ms 62940 KB Output is correct
23 Correct 12 ms 63068 KB Output is correct
24 Correct 12 ms 63080 KB Output is correct
25 Correct 12 ms 62936 KB Output is correct
26 Correct 12 ms 63324 KB Output is correct
27 Correct 12 ms 62932 KB Output is correct
28 Correct 12 ms 62924 KB Output is correct
29 Correct 13 ms 62936 KB Output is correct
30 Correct 12 ms 63068 KB Output is correct
31 Correct 12 ms 62948 KB Output is correct
32 Correct 14 ms 63064 KB Output is correct
33 Correct 14 ms 63068 KB Output is correct
34 Correct 13 ms 63068 KB Output is correct
35 Correct 13 ms 63068 KB Output is correct
36 Correct 13 ms 63064 KB Output is correct
37 Correct 13 ms 63068 KB Output is correct
38 Correct 13 ms 62876 KB Output is correct
39 Correct 14 ms 63068 KB Output is correct
40 Correct 14 ms 63068 KB Output is correct
41 Correct 13 ms 63068 KB Output is correct
42 Correct 13 ms 63068 KB Output is correct
43 Correct 13 ms 62876 KB Output is correct
44 Correct 13 ms 63068 KB Output is correct
45 Correct 13 ms 62888 KB Output is correct
46 Correct 13 ms 63068 KB Output is correct
47 Correct 14 ms 63068 KB Output is correct
48 Correct 14 ms 63068 KB Output is correct
49 Correct 13 ms 62888 KB Output is correct
50 Correct 13 ms 63068 KB Output is correct
51 Correct 13 ms 63068 KB Output is correct
52 Correct 14 ms 63068 KB Output is correct
53 Correct 13 ms 62960 KB Output is correct
54 Correct 13 ms 63064 KB Output is correct
55 Correct 14 ms 63068 KB Output is correct
56 Correct 13 ms 62948 KB Output is correct
57 Correct 13 ms 63076 KB Output is correct
58 Correct 13 ms 62900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 63068 KB Output is correct
2 Correct 13 ms 62848 KB Output is correct
3 Correct 12 ms 63068 KB Output is correct
4 Correct 12 ms 63084 KB Output is correct
5 Correct 13 ms 63232 KB Output is correct
6 Correct 12 ms 63068 KB Output is correct
7 Correct 331 ms 76576 KB Output is correct
8 Correct 345 ms 74816 KB Output is correct
9 Correct 344 ms 77860 KB Output is correct
10 Correct 348 ms 77344 KB Output is correct
11 Correct 344 ms 75480 KB Output is correct
12 Correct 336 ms 76424 KB Output is correct
13 Correct 338 ms 77604 KB Output is correct
14 Correct 338 ms 76320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 63068 KB Output is correct
2 Correct 13 ms 63064 KB Output is correct
3 Correct 12 ms 63080 KB Output is correct
4 Correct 14 ms 63324 KB Output is correct
5 Correct 14 ms 63068 KB Output is correct
6 Correct 12 ms 63064 KB Output is correct
7 Correct 12 ms 63064 KB Output is correct
8 Correct 12 ms 62944 KB Output is correct
9 Correct 12 ms 63068 KB Output is correct
10 Correct 13 ms 63068 KB Output is correct
11 Correct 13 ms 63064 KB Output is correct
12 Correct 13 ms 63064 KB Output is correct
13 Correct 12 ms 63068 KB Output is correct
14 Correct 12 ms 63068 KB Output is correct
15 Correct 12 ms 63068 KB Output is correct
16 Correct 13 ms 62892 KB Output is correct
17 Correct 12 ms 62932 KB Output is correct
18 Correct 12 ms 62896 KB Output is correct
19 Correct 12 ms 63064 KB Output is correct
20 Correct 12 ms 63068 KB Output is correct
21 Correct 13 ms 63068 KB Output is correct
22 Correct 12 ms 62940 KB Output is correct
23 Correct 12 ms 63068 KB Output is correct
24 Correct 12 ms 63080 KB Output is correct
25 Correct 12 ms 62936 KB Output is correct
26 Correct 12 ms 63324 KB Output is correct
27 Correct 12 ms 62932 KB Output is correct
28 Correct 12 ms 62924 KB Output is correct
29 Correct 13 ms 62936 KB Output is correct
30 Correct 12 ms 63068 KB Output is correct
31 Correct 12 ms 62948 KB Output is correct
32 Correct 14 ms 63064 KB Output is correct
33 Correct 14 ms 63068 KB Output is correct
34 Correct 13 ms 63068 KB Output is correct
35 Correct 13 ms 63068 KB Output is correct
36 Correct 13 ms 63064 KB Output is correct
37 Correct 13 ms 63068 KB Output is correct
38 Correct 13 ms 62876 KB Output is correct
39 Correct 14 ms 63068 KB Output is correct
40 Correct 14 ms 63068 KB Output is correct
41 Correct 13 ms 63068 KB Output is correct
42 Correct 13 ms 63068 KB Output is correct
43 Correct 13 ms 62876 KB Output is correct
44 Correct 13 ms 63068 KB Output is correct
45 Correct 13 ms 62888 KB Output is correct
46 Correct 13 ms 63068 KB Output is correct
47 Correct 14 ms 63068 KB Output is correct
48 Correct 14 ms 63068 KB Output is correct
49 Correct 13 ms 62888 KB Output is correct
50 Correct 13 ms 63068 KB Output is correct
51 Correct 13 ms 63068 KB Output is correct
52 Correct 14 ms 63068 KB Output is correct
53 Correct 13 ms 62960 KB Output is correct
54 Correct 13 ms 63064 KB Output is correct
55 Correct 14 ms 63068 KB Output is correct
56 Correct 13 ms 62948 KB Output is correct
57 Correct 13 ms 63076 KB Output is correct
58 Correct 13 ms 62900 KB Output is correct
59 Correct 13 ms 63068 KB Output is correct
60 Correct 13 ms 62848 KB Output is correct
61 Correct 12 ms 63068 KB Output is correct
62 Correct 12 ms 63084 KB Output is correct
63 Correct 13 ms 63232 KB Output is correct
64 Correct 12 ms 63068 KB Output is correct
65 Correct 331 ms 76576 KB Output is correct
66 Correct 345 ms 74816 KB Output is correct
67 Correct 344 ms 77860 KB Output is correct
68 Correct 348 ms 77344 KB Output is correct
69 Correct 344 ms 75480 KB Output is correct
70 Correct 336 ms 76424 KB Output is correct
71 Correct 338 ms 77604 KB Output is correct
72 Correct 338 ms 76320 KB Output is correct
73 Correct 343 ms 76324 KB Output is correct
74 Correct 349 ms 76404 KB Output is correct
75 Correct 348 ms 76336 KB Output is correct
76 Correct 347 ms 75680 KB Output is correct
77 Correct 346 ms 77732 KB Output is correct
78 Correct 354 ms 76356 KB Output is correct
79 Correct 337 ms 74748 KB Output is correct
80 Correct 350 ms 76320 KB Output is correct
81 Correct 344 ms 76320 KB Output is correct
82 Correct 360 ms 77084 KB Output is correct
83 Correct 344 ms 74740 KB Output is correct
84 Correct 344 ms 76324 KB Output is correct
85 Correct 351 ms 77960 KB Output is correct
86 Correct 344 ms 76072 KB Output is correct
87 Correct 387 ms 75300 KB Output is correct
88 Correct 348 ms 77140 KB Output is correct
89 Correct 352 ms 77348 KB Output is correct
90 Correct 349 ms 74848 KB Output is correct
91 Correct 360 ms 76604 KB Output is correct
92 Correct 355 ms 75492 KB Output is correct
93 Correct 357 ms 76296 KB Output is correct
94 Correct 356 ms 75976 KB Output is correct
95 Correct 362 ms 76272 KB Output is correct
96 Correct 360 ms 76616 KB Output is correct
97 Correct 373 ms 76680 KB Output is correct
98 Correct 349 ms 75052 KB Output is correct
99 Correct 366 ms 75700 KB Output is correct
100 Correct 348 ms 75332 KB Output is correct
101 Correct 360 ms 76444 KB Output is correct
102 Correct 349 ms 76188 KB Output is correct