Submission #107685

# Submission time Handle Problem Language Result Execution time Memory
107685 2019-04-25T12:44:26 Z Saboon Lamps (JOI19_lamps) C++14
100 / 100
554 ms 259148 KB
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
 
const int maxn = 1e6 + 10;
 
int dp[maxn][65];
 
int mab(int fi, int se){
	return fi + se * 4;
}
 
int transform(int x, int query){
	if (query == 0)
		return x;
	else if (query == 1)
		return 0;
	else if (query == 2)
		return 1;
	else
		return 1 ^ x;
}
 
int transfer(int q, int fi, int se){
	q = transform(q, fi);
	q = transform(q, se);
	return q;
}
 
bool C(int x){
	return x > 0;
}
 
int lcs[5][5];
int pd[257];
 
int cost(int fi, int se, int Fi, int Se){
	if (pd[fi + 4 * se + 16 * Fi + 64 * Se] != -1)
		return pd[fi + 4 * se + 16 * Fi + 64 * Se];
	vector<int> a = {fi, se};
	vector<int> b = {Fi, Se};
	int cnt = C(Fi) + C(Se);
	for (int i = 1; i <= 2; i++){
		for (int j = 1; j <= 2; j++){
			lcs[i][j] = max(lcs[i - 1][j], lcs[i][j - 1]);
			if (a[i - 1] == 0 or b[i - 1] == 0)
				continue;
			lcs[i][j] = max(lcs[i][j], (lcs[i - 1][j - 1] + 1) * (a[i - 1] == b[j - 1]));
		}
	}
	return pd[fi + 4 * se + 16 * Fi + 64 * Se] = cnt - lcs[2][2];
}
 
vector<int> go[2][2]; 
vector<pair<int,int> > vec[65];

int main(){
	ios_base::sync_with_stdio(false);
	memset(pd, -1, sizeof pd);
	int n;
	string s, t;
	cin >> n >> s >> t;
	memset(dp, 63, sizeof dp);
	dp[0][0] = 0;
	int answer = n;
	for (int i = 0; i <= 3; i++){
		for (int j = 0; j <= 3; j++){
			int nex = transfer(0, i, j);
			go[0][nex].push_back(mab(i, j));
 
			nex = transfer(1, i, j);
			go[1][nex].push_back(mab(i, j));
		}
	}
	for (int i = 0; i <= 3; i++)
		for (int j = 0; j <= 3; j++)
			for (int x = 0; x <= 3; x++)
				for (int y = 0; y <= 3; y++)
					vec[mab(i, j)].push_back({mab(x, y), cost(x, y, i, j)});
	for (int i = 1; i <= n; i++){
		int me = (int)(s[i - 1] - '0');
		int nex = (int)(t[i - 1] - '0');
		for (auto it : go[me][nex])
			for (auto to : vec[it])
				dp[i][it] = min(dp[i][it], dp[i - 1][to.first] + to.second);
	}
	for (int i = 0; i < 65; i++)
		answer = min(answer, dp[n][i]);
	cout << answer << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 207 ms 254840 KB Output is correct
2 Correct 208 ms 254808 KB Output is correct
3 Correct 222 ms 254840 KB Output is correct
4 Correct 219 ms 254840 KB Output is correct
5 Correct 205 ms 254712 KB Output is correct
6 Correct 210 ms 254816 KB Output is correct
7 Correct 202 ms 254832 KB Output is correct
8 Correct 194 ms 254712 KB Output is correct
9 Correct 190 ms 254776 KB Output is correct
10 Correct 200 ms 254712 KB Output is correct
11 Correct 221 ms 254712 KB Output is correct
12 Correct 190 ms 254712 KB Output is correct
13 Correct 211 ms 254668 KB Output is correct
14 Correct 189 ms 254672 KB Output is correct
15 Correct 197 ms 254788 KB Output is correct
16 Correct 187 ms 254684 KB Output is correct
17 Correct 190 ms 254724 KB Output is correct
18 Correct 206 ms 254712 KB Output is correct
19 Correct 194 ms 254744 KB Output is correct
20 Correct 196 ms 254788 KB Output is correct
21 Correct 211 ms 254716 KB Output is correct
22 Correct 193 ms 254864 KB Output is correct
23 Correct 208 ms 254880 KB Output is correct
24 Correct 202 ms 254840 KB Output is correct
25 Correct 195 ms 254736 KB Output is correct
26 Correct 205 ms 254784 KB Output is correct
27 Correct 204 ms 254712 KB Output is correct
28 Correct 203 ms 254684 KB Output is correct
29 Correct 197 ms 254736 KB Output is correct
30 Correct 204 ms 254780 KB Output is correct
31 Correct 195 ms 254712 KB Output is correct
32 Correct 194 ms 254712 KB Output is correct
33 Correct 208 ms 254712 KB Output is correct
34 Correct 187 ms 254712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 207 ms 254840 KB Output is correct
2 Correct 208 ms 254808 KB Output is correct
3 Correct 222 ms 254840 KB Output is correct
4 Correct 219 ms 254840 KB Output is correct
5 Correct 205 ms 254712 KB Output is correct
6 Correct 210 ms 254816 KB Output is correct
7 Correct 202 ms 254832 KB Output is correct
8 Correct 194 ms 254712 KB Output is correct
9 Correct 190 ms 254776 KB Output is correct
10 Correct 200 ms 254712 KB Output is correct
11 Correct 221 ms 254712 KB Output is correct
12 Correct 190 ms 254712 KB Output is correct
13 Correct 211 ms 254668 KB Output is correct
14 Correct 189 ms 254672 KB Output is correct
15 Correct 197 ms 254788 KB Output is correct
16 Correct 187 ms 254684 KB Output is correct
17 Correct 190 ms 254724 KB Output is correct
18 Correct 206 ms 254712 KB Output is correct
19 Correct 194 ms 254744 KB Output is correct
20 Correct 196 ms 254788 KB Output is correct
21 Correct 211 ms 254716 KB Output is correct
22 Correct 193 ms 254864 KB Output is correct
23 Correct 208 ms 254880 KB Output is correct
24 Correct 202 ms 254840 KB Output is correct
25 Correct 195 ms 254736 KB Output is correct
26 Correct 205 ms 254784 KB Output is correct
27 Correct 204 ms 254712 KB Output is correct
28 Correct 203 ms 254684 KB Output is correct
29 Correct 197 ms 254736 KB Output is correct
30 Correct 204 ms 254780 KB Output is correct
31 Correct 195 ms 254712 KB Output is correct
32 Correct 194 ms 254712 KB Output is correct
33 Correct 208 ms 254712 KB Output is correct
34 Correct 187 ms 254712 KB Output is correct
35 Correct 209 ms 254764 KB Output is correct
36 Correct 210 ms 254716 KB Output is correct
37 Correct 207 ms 254776 KB Output is correct
38 Correct 211 ms 254784 KB Output is correct
39 Correct 195 ms 254728 KB Output is correct
40 Correct 190 ms 254712 KB Output is correct
41 Correct 189 ms 254712 KB Output is correct
42 Correct 193 ms 254968 KB Output is correct
43 Correct 203 ms 254760 KB Output is correct
44 Correct 206 ms 254832 KB Output is correct
45 Correct 235 ms 254768 KB Output is correct
46 Correct 213 ms 254756 KB Output is correct
47 Correct 218 ms 254860 KB Output is correct
48 Correct 210 ms 254760 KB Output is correct
49 Correct 204 ms 254840 KB Output is correct
50 Correct 228 ms 254840 KB Output is correct
51 Correct 217 ms 254716 KB Output is correct
52 Correct 189 ms 254824 KB Output is correct
53 Correct 189 ms 254872 KB Output is correct
54 Correct 190 ms 254688 KB Output is correct
55 Correct 265 ms 254840 KB Output is correct
56 Correct 236 ms 254812 KB Output is correct
57 Correct 236 ms 254712 KB Output is correct
58 Correct 214 ms 254784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 226 ms 254840 KB Output is correct
2 Correct 215 ms 254844 KB Output is correct
3 Correct 220 ms 254772 KB Output is correct
4 Correct 219 ms 254780 KB Output is correct
5 Correct 208 ms 254712 KB Output is correct
6 Correct 204 ms 254780 KB Output is correct
7 Correct 411 ms 256840 KB Output is correct
8 Correct 429 ms 256968 KB Output is correct
9 Correct 376 ms 256848 KB Output is correct
10 Correct 467 ms 257076 KB Output is correct
11 Correct 436 ms 256964 KB Output is correct
12 Correct 421 ms 256836 KB Output is correct
13 Correct 447 ms 256972 KB Output is correct
14 Correct 421 ms 257160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 207 ms 254840 KB Output is correct
2 Correct 208 ms 254808 KB Output is correct
3 Correct 222 ms 254840 KB Output is correct
4 Correct 219 ms 254840 KB Output is correct
5 Correct 205 ms 254712 KB Output is correct
6 Correct 210 ms 254816 KB Output is correct
7 Correct 202 ms 254832 KB Output is correct
8 Correct 194 ms 254712 KB Output is correct
9 Correct 190 ms 254776 KB Output is correct
10 Correct 200 ms 254712 KB Output is correct
11 Correct 221 ms 254712 KB Output is correct
12 Correct 190 ms 254712 KB Output is correct
13 Correct 211 ms 254668 KB Output is correct
14 Correct 189 ms 254672 KB Output is correct
15 Correct 197 ms 254788 KB Output is correct
16 Correct 187 ms 254684 KB Output is correct
17 Correct 190 ms 254724 KB Output is correct
18 Correct 206 ms 254712 KB Output is correct
19 Correct 194 ms 254744 KB Output is correct
20 Correct 196 ms 254788 KB Output is correct
21 Correct 211 ms 254716 KB Output is correct
22 Correct 193 ms 254864 KB Output is correct
23 Correct 208 ms 254880 KB Output is correct
24 Correct 202 ms 254840 KB Output is correct
25 Correct 195 ms 254736 KB Output is correct
26 Correct 205 ms 254784 KB Output is correct
27 Correct 204 ms 254712 KB Output is correct
28 Correct 203 ms 254684 KB Output is correct
29 Correct 197 ms 254736 KB Output is correct
30 Correct 204 ms 254780 KB Output is correct
31 Correct 195 ms 254712 KB Output is correct
32 Correct 194 ms 254712 KB Output is correct
33 Correct 208 ms 254712 KB Output is correct
34 Correct 187 ms 254712 KB Output is correct
35 Correct 209 ms 254764 KB Output is correct
36 Correct 210 ms 254716 KB Output is correct
37 Correct 207 ms 254776 KB Output is correct
38 Correct 211 ms 254784 KB Output is correct
39 Correct 195 ms 254728 KB Output is correct
40 Correct 190 ms 254712 KB Output is correct
41 Correct 189 ms 254712 KB Output is correct
42 Correct 193 ms 254968 KB Output is correct
43 Correct 203 ms 254760 KB Output is correct
44 Correct 206 ms 254832 KB Output is correct
45 Correct 235 ms 254768 KB Output is correct
46 Correct 213 ms 254756 KB Output is correct
47 Correct 218 ms 254860 KB Output is correct
48 Correct 210 ms 254760 KB Output is correct
49 Correct 204 ms 254840 KB Output is correct
50 Correct 228 ms 254840 KB Output is correct
51 Correct 217 ms 254716 KB Output is correct
52 Correct 189 ms 254824 KB Output is correct
53 Correct 189 ms 254872 KB Output is correct
54 Correct 190 ms 254688 KB Output is correct
55 Correct 265 ms 254840 KB Output is correct
56 Correct 236 ms 254812 KB Output is correct
57 Correct 236 ms 254712 KB Output is correct
58 Correct 214 ms 254784 KB Output is correct
59 Correct 226 ms 254840 KB Output is correct
60 Correct 215 ms 254844 KB Output is correct
61 Correct 220 ms 254772 KB Output is correct
62 Correct 219 ms 254780 KB Output is correct
63 Correct 208 ms 254712 KB Output is correct
64 Correct 204 ms 254780 KB Output is correct
65 Correct 411 ms 256840 KB Output is correct
66 Correct 429 ms 256968 KB Output is correct
67 Correct 376 ms 256848 KB Output is correct
68 Correct 467 ms 257076 KB Output is correct
69 Correct 436 ms 256964 KB Output is correct
70 Correct 421 ms 256836 KB Output is correct
71 Correct 447 ms 256972 KB Output is correct
72 Correct 421 ms 257160 KB Output is correct
73 Correct 483 ms 258884 KB Output is correct
74 Correct 402 ms 258872 KB Output is correct
75 Correct 495 ms 258828 KB Output is correct
76 Correct 402 ms 258840 KB Output is correct
77 Correct 462 ms 258760 KB Output is correct
78 Correct 381 ms 258892 KB Output is correct
79 Correct 417 ms 259020 KB Output is correct
80 Correct 407 ms 258780 KB Output is correct
81 Correct 431 ms 259148 KB Output is correct
82 Correct 376 ms 258816 KB Output is correct
83 Correct 480 ms 258936 KB Output is correct
84 Correct 497 ms 258752 KB Output is correct
85 Correct 424 ms 258764 KB Output is correct
86 Correct 388 ms 258884 KB Output is correct
87 Correct 474 ms 258760 KB Output is correct
88 Correct 554 ms 258960 KB Output is correct
89 Correct 512 ms 258972 KB Output is correct
90 Correct 534 ms 258756 KB Output is correct
91 Correct 425 ms 258888 KB Output is correct
92 Correct 435 ms 258860 KB Output is correct
93 Correct 433 ms 259012 KB Output is correct
94 Correct 448 ms 258832 KB Output is correct
95 Correct 451 ms 258892 KB Output is correct
96 Correct 399 ms 258780 KB Output is correct
97 Correct 425 ms 258808 KB Output is correct
98 Correct 404 ms 259020 KB Output is correct
99 Correct 431 ms 258752 KB Output is correct
100 Correct 496 ms 258892 KB Output is correct
101 Correct 383 ms 258764 KB Output is correct
102 Correct 431 ms 258892 KB Output is correct