Submission #377175

# Submission time Handle Problem Language Result Execution time Memory
377175 2021-03-13T07:51:22 Z 8e7 Lamps (JOI19_lamps) C++14
47 / 100
1000 ms 22460 KB
//Challenge: Accepted
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#define ll long long
#define maxn 1000005
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
string sa, sb;

int a[maxn], b[maxn], pref[maxn], diff[maxn], pdif[maxn];
int dp[maxn];
int m1[maxn];

inline int seg(int l, int r) {
	if (l > r) return 0;
	return pref[r] - (l ? pref[l - 1] : 0);
}
int main() {
	io
	int n;
	cin >> n;
	cin >> sa >> sb;
	sa += '0', sb += '0';
	reverse(sa.begin(), sa.end());
	reverse(sb.begin(), sb.end());
	sa += '0', sb += '0';
	n += 2;
	for (int i = 0;i < n;i++) {
		a[i] = (sa[i] == '1') ^ (i ? (sa[i - 1] == '1') : 0);
		b[i] = (sb[i] == '1') ^ (i ? (sb[i - 1] == '1') : 0);
		diff[i] = a[i] ^ b[i];
		pref[i] = (b[i] == 1 ? 1 : 0) + (i ? pref[i - 1] : 0);
		pdif[i] = diff[i] + (i ? pdif[i - 1] : 0);
		//cout << pref[i] << " " << pdif[i] << endl;
	}
	for (int i = 0;i < n;i++) {
		dp[i] = pdif[i] + (i ? m1[i - 1] : 0);
		for (int j = 0;j < i;j++) {
			if (j < i - 1 && sa[j + 1] == sa[i - 1]) { //l == j + 1, r == i - 1;
				dp[i] = min(dp[i], dp[j] + 4 - (diff[i] + diff[j + 1]) + seg(j + 2, i - 1));
			}
		}
		//cout << dp[i] << " ";
		m1[i] = min(dp[i] - pdif[i], i ? m1[i - 1] : 1<<30);

	}
	//cout << endl;
	cout << (dp[n - 1] + 1) / 2 << "\n";
}
/*
8
11011100
01101001


13
1010010010100
0000111001011

18
001100010010000110
110110001000100101


 */
# Verdict Execution time Memory Grader output
1 Correct 1 ms 372 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 0 ms 236 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 372 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 0 ms 236 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 9 ms 492 KB Output is correct
36 Correct 9 ms 512 KB Output is correct
37 Correct 8 ms 512 KB Output is correct
38 Correct 9 ms 492 KB Output is correct
39 Correct 5 ms 492 KB Output is correct
40 Correct 5 ms 492 KB Output is correct
41 Correct 5 ms 492 KB Output is correct
42 Correct 5 ms 492 KB Output is correct
43 Correct 5 ms 492 KB Output is correct
44 Correct 5 ms 492 KB Output is correct
45 Correct 5 ms 492 KB Output is correct
46 Correct 5 ms 492 KB Output is correct
47 Correct 5 ms 492 KB Output is correct
48 Correct 5 ms 492 KB Output is correct
49 Correct 5 ms 492 KB Output is correct
50 Correct 5 ms 492 KB Output is correct
51 Correct 5 ms 492 KB Output is correct
52 Correct 5 ms 492 KB Output is correct
53 Correct 5 ms 492 KB Output is correct
54 Correct 5 ms 492 KB Output is correct
55 Correct 5 ms 492 KB Output is correct
56 Correct 5 ms 512 KB Output is correct
57 Correct 5 ms 492 KB Output is correct
58 Correct 5 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Execution timed out 1098 ms 22460 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 372 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 0 ms 236 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 9 ms 492 KB Output is correct
36 Correct 9 ms 512 KB Output is correct
37 Correct 8 ms 512 KB Output is correct
38 Correct 9 ms 492 KB Output is correct
39 Correct 5 ms 492 KB Output is correct
40 Correct 5 ms 492 KB Output is correct
41 Correct 5 ms 492 KB Output is correct
42 Correct 5 ms 492 KB Output is correct
43 Correct 5 ms 492 KB Output is correct
44 Correct 5 ms 492 KB Output is correct
45 Correct 5 ms 492 KB Output is correct
46 Correct 5 ms 492 KB Output is correct
47 Correct 5 ms 492 KB Output is correct
48 Correct 5 ms 492 KB Output is correct
49 Correct 5 ms 492 KB Output is correct
50 Correct 5 ms 492 KB Output is correct
51 Correct 5 ms 492 KB Output is correct
52 Correct 5 ms 492 KB Output is correct
53 Correct 5 ms 492 KB Output is correct
54 Correct 5 ms 492 KB Output is correct
55 Correct 5 ms 492 KB Output is correct
56 Correct 5 ms 512 KB Output is correct
57 Correct 5 ms 492 KB Output is correct
58 Correct 5 ms 492 KB Output is correct
59 Correct 1 ms 364 KB Output is correct
60 Correct 1 ms 364 KB Output is correct
61 Correct 1 ms 364 KB Output is correct
62 Correct 1 ms 364 KB Output is correct
63 Correct 1 ms 364 KB Output is correct
64 Correct 1 ms 364 KB Output is correct
65 Execution timed out 1098 ms 22460 KB Time limit exceeded
66 Halted 0 ms 0 KB -