Submission #377173

# Submission time Handle Problem Language Result Execution time Memory
377173 2021-03-13T07:44:42 Z 8e7 Lamps (JOI19_lamps) C++14
0 / 100
1000 ms 24252 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];

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];
		for (int j = 0;j < i;j++) {
			if (j < i - 1 && a[j + 1] == a[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));
			}
			dp[i] = min(dp[i], dp[j] + pdif[i] - pdif[j]);
		}
		//cout << dp[i] << " ";
	}
	//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 364 KB Output is correct
2 Correct 1 ms 396 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 512 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 492 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Incorrect 1 ms 364 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 396 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 512 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 492 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Incorrect 1 ms 364 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 404 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 1087 ms 24252 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 396 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 512 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 492 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Incorrect 1 ms 364 KB Output isn't correct
16 Halted 0 ms 0 KB -