Submission #107671

# Submission time Handle Problem Language Result Execution time Memory
107671 2019-04-25T12:20:55 Z Saboon Lamps (JOI19_lamps) C++14
47 / 100
1000 ms 256816 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[4][4][4][4];

int cost(int fi, int se, int all){
	int Fi = (all / 1) % 4;
	int Se = (all / 4) % 4;
	if (pd[fi][se][Fi][Se] != -1)
		return pd[fi][se][Fi][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]));
		}
	}
	//	cout << fi << " " << se << " " << th << " ----- " << cnt - lcs[3][3] << " -----> " << Fi << " " << Se << " " << Th << endl;
	return pd[fi][se][Fi][Se] = cnt - lcs[2][2];
}

vector<int> go[2][2];

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 = 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 (int x = 0; x <= 3; x++){
				for (int y = 0; y <= 3; y++){
					dp[i][it] = min(dp[i][it], dp[i - 1][mab(x, y)] + cost(x, y, it));
				}
			}
			if (i == n)
				answer = min(answer, dp[i][it]);
		}
	}
	cout << answer << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 214 ms 254712 KB Output is correct
2 Correct 209 ms 254820 KB Output is correct
3 Correct 198 ms 254684 KB Output is correct
4 Correct 260 ms 254776 KB Output is correct
5 Correct 218 ms 254840 KB Output is correct
6 Correct 231 ms 254840 KB Output is correct
7 Correct 252 ms 254736 KB Output is correct
8 Correct 228 ms 254712 KB Output is correct
9 Correct 266 ms 254840 KB Output is correct
10 Correct 232 ms 254780 KB Output is correct
11 Correct 230 ms 254712 KB Output is correct
12 Correct 222 ms 254712 KB Output is correct
13 Correct 248 ms 254720 KB Output is correct
14 Correct 255 ms 254840 KB Output is correct
15 Correct 252 ms 254744 KB Output is correct
16 Correct 250 ms 254700 KB Output is correct
17 Correct 219 ms 254880 KB Output is correct
18 Correct 215 ms 254688 KB Output is correct
19 Correct 244 ms 254888 KB Output is correct
20 Correct 230 ms 254864 KB Output is correct
21 Correct 227 ms 254712 KB Output is correct
22 Correct 225 ms 254712 KB Output is correct
23 Correct 236 ms 254840 KB Output is correct
24 Correct 218 ms 254840 KB Output is correct
25 Correct 220 ms 254716 KB Output is correct
26 Correct 216 ms 254704 KB Output is correct
27 Correct 212 ms 254720 KB Output is correct
28 Correct 230 ms 254748 KB Output is correct
29 Correct 223 ms 254780 KB Output is correct
30 Correct 241 ms 254824 KB Output is correct
31 Correct 226 ms 254820 KB Output is correct
32 Correct 227 ms 254712 KB Output is correct
33 Correct 233 ms 254740 KB Output is correct
34 Correct 219 ms 254840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 214 ms 254712 KB Output is correct
2 Correct 209 ms 254820 KB Output is correct
3 Correct 198 ms 254684 KB Output is correct
4 Correct 260 ms 254776 KB Output is correct
5 Correct 218 ms 254840 KB Output is correct
6 Correct 231 ms 254840 KB Output is correct
7 Correct 252 ms 254736 KB Output is correct
8 Correct 228 ms 254712 KB Output is correct
9 Correct 266 ms 254840 KB Output is correct
10 Correct 232 ms 254780 KB Output is correct
11 Correct 230 ms 254712 KB Output is correct
12 Correct 222 ms 254712 KB Output is correct
13 Correct 248 ms 254720 KB Output is correct
14 Correct 255 ms 254840 KB Output is correct
15 Correct 252 ms 254744 KB Output is correct
16 Correct 250 ms 254700 KB Output is correct
17 Correct 219 ms 254880 KB Output is correct
18 Correct 215 ms 254688 KB Output is correct
19 Correct 244 ms 254888 KB Output is correct
20 Correct 230 ms 254864 KB Output is correct
21 Correct 227 ms 254712 KB Output is correct
22 Correct 225 ms 254712 KB Output is correct
23 Correct 236 ms 254840 KB Output is correct
24 Correct 218 ms 254840 KB Output is correct
25 Correct 220 ms 254716 KB Output is correct
26 Correct 216 ms 254704 KB Output is correct
27 Correct 212 ms 254720 KB Output is correct
28 Correct 230 ms 254748 KB Output is correct
29 Correct 223 ms 254780 KB Output is correct
30 Correct 241 ms 254824 KB Output is correct
31 Correct 226 ms 254820 KB Output is correct
32 Correct 227 ms 254712 KB Output is correct
33 Correct 233 ms 254740 KB Output is correct
34 Correct 219 ms 254840 KB Output is correct
35 Correct 208 ms 254864 KB Output is correct
36 Correct 228 ms 254736 KB Output is correct
37 Correct 203 ms 254892 KB Output is correct
38 Correct 233 ms 254844 KB Output is correct
39 Correct 229 ms 254892 KB Output is correct
40 Correct 218 ms 254840 KB Output is correct
41 Correct 225 ms 254712 KB Output is correct
42 Correct 225 ms 254844 KB Output is correct
43 Correct 203 ms 254852 KB Output is correct
44 Correct 199 ms 254684 KB Output is correct
45 Correct 214 ms 254844 KB Output is correct
46 Correct 218 ms 254848 KB Output is correct
47 Correct 241 ms 254748 KB Output is correct
48 Correct 231 ms 254840 KB Output is correct
49 Correct 229 ms 254892 KB Output is correct
50 Correct 218 ms 254712 KB Output is correct
51 Correct 252 ms 254784 KB Output is correct
52 Correct 207 ms 254712 KB Output is correct
53 Correct 199 ms 254712 KB Output is correct
54 Correct 226 ms 254692 KB Output is correct
55 Correct 223 ms 254840 KB Output is correct
56 Correct 215 ms 254840 KB Output is correct
57 Correct 208 ms 254760 KB Output is correct
58 Correct 226 ms 254712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 224 ms 254768 KB Output is correct
2 Correct 222 ms 254724 KB Output is correct
3 Correct 215 ms 254712 KB Output is correct
4 Correct 253 ms 254712 KB Output is correct
5 Correct 226 ms 254816 KB Output is correct
6 Correct 217 ms 254780 KB Output is correct
7 Execution timed out 1104 ms 256816 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 214 ms 254712 KB Output is correct
2 Correct 209 ms 254820 KB Output is correct
3 Correct 198 ms 254684 KB Output is correct
4 Correct 260 ms 254776 KB Output is correct
5 Correct 218 ms 254840 KB Output is correct
6 Correct 231 ms 254840 KB Output is correct
7 Correct 252 ms 254736 KB Output is correct
8 Correct 228 ms 254712 KB Output is correct
9 Correct 266 ms 254840 KB Output is correct
10 Correct 232 ms 254780 KB Output is correct
11 Correct 230 ms 254712 KB Output is correct
12 Correct 222 ms 254712 KB Output is correct
13 Correct 248 ms 254720 KB Output is correct
14 Correct 255 ms 254840 KB Output is correct
15 Correct 252 ms 254744 KB Output is correct
16 Correct 250 ms 254700 KB Output is correct
17 Correct 219 ms 254880 KB Output is correct
18 Correct 215 ms 254688 KB Output is correct
19 Correct 244 ms 254888 KB Output is correct
20 Correct 230 ms 254864 KB Output is correct
21 Correct 227 ms 254712 KB Output is correct
22 Correct 225 ms 254712 KB Output is correct
23 Correct 236 ms 254840 KB Output is correct
24 Correct 218 ms 254840 KB Output is correct
25 Correct 220 ms 254716 KB Output is correct
26 Correct 216 ms 254704 KB Output is correct
27 Correct 212 ms 254720 KB Output is correct
28 Correct 230 ms 254748 KB Output is correct
29 Correct 223 ms 254780 KB Output is correct
30 Correct 241 ms 254824 KB Output is correct
31 Correct 226 ms 254820 KB Output is correct
32 Correct 227 ms 254712 KB Output is correct
33 Correct 233 ms 254740 KB Output is correct
34 Correct 219 ms 254840 KB Output is correct
35 Correct 208 ms 254864 KB Output is correct
36 Correct 228 ms 254736 KB Output is correct
37 Correct 203 ms 254892 KB Output is correct
38 Correct 233 ms 254844 KB Output is correct
39 Correct 229 ms 254892 KB Output is correct
40 Correct 218 ms 254840 KB Output is correct
41 Correct 225 ms 254712 KB Output is correct
42 Correct 225 ms 254844 KB Output is correct
43 Correct 203 ms 254852 KB Output is correct
44 Correct 199 ms 254684 KB Output is correct
45 Correct 214 ms 254844 KB Output is correct
46 Correct 218 ms 254848 KB Output is correct
47 Correct 241 ms 254748 KB Output is correct
48 Correct 231 ms 254840 KB Output is correct
49 Correct 229 ms 254892 KB Output is correct
50 Correct 218 ms 254712 KB Output is correct
51 Correct 252 ms 254784 KB Output is correct
52 Correct 207 ms 254712 KB Output is correct
53 Correct 199 ms 254712 KB Output is correct
54 Correct 226 ms 254692 KB Output is correct
55 Correct 223 ms 254840 KB Output is correct
56 Correct 215 ms 254840 KB Output is correct
57 Correct 208 ms 254760 KB Output is correct
58 Correct 226 ms 254712 KB Output is correct
59 Correct 224 ms 254768 KB Output is correct
60 Correct 222 ms 254724 KB Output is correct
61 Correct 215 ms 254712 KB Output is correct
62 Correct 253 ms 254712 KB Output is correct
63 Correct 226 ms 254816 KB Output is correct
64 Correct 217 ms 254780 KB Output is correct
65 Execution timed out 1104 ms 256816 KB Time limit exceeded
66 Halted 0 ms 0 KB -