Submission #108119

# Submission time Handle Problem Language Result Execution time Memory
108119 2019-04-27T13:51:56 Z hugo_pm Lamps (JOI19_lamps) C++17
4 / 100
151 ms 67072 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define form2(i, a, b) for (int i = (a); i < (b); ++i)
#define ford2(i, a, b) for (int i = (a-1); i >= (b); --i)
#define form(i, n) form2(i, 0, n)
#define ford(i, n) ford2(i, n, 0)

#define chmax(x, v) x = max(x, (v))
#define chmin(x, v) x = min(x, (v))
#define fi first
#define se second

const long long BIG = 1000000000000000000LL;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

void solve();
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	return 0;
}

const int borne = 1000*1000 + 5;
int dp[borne][2][3];
int len;
int cur[borne];
int cible[borne];

void calc(int dep, int isToggle, int set)
{
	int &rep = dp[dep][isToggle][set];
	rep = BIG;
	if (dep) {
		int vc = cur[dep];
		if (isToggle) vc ^= 1;
		if (set < 2) vc = set;
		if (vc != cible[dep]) { rep = BIG; return; }
	}
	
	if (dep == len) { rep = 0; return; }

	form(newTog, 2) form(newSet, 3) {
		int cx = dp[dep+1][newTog][newSet];
		if (newTog == 1 && isToggle == 0) ++cx;
		if (newSet != set && newSet != 2) ++cx;
		chmin(rep, cx);
	}
}

void solve()
{
	cin >> len;
	string s, t;
	cin >> s >> t;
	form(i, len) cur[i+1] = (s[i] == '0' ? 0 : 1);
	form(i, len) cible[i+1] = (t[i] == '0' ? 0 : 1);

	ford(i, len) form(a, 2) form(b, 3) calc(i+1,a,b);
	calc(0, 0, 2);
	cout << dp[0][0][2] << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Incorrect 2 ms 384 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Incorrect 2 ms 384 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 116 ms 66936 KB Output is correct
8 Correct 127 ms 66944 KB Output is correct
9 Correct 125 ms 66972 KB Output is correct
10 Correct 113 ms 67024 KB Output is correct
11 Correct 138 ms 67016 KB Output is correct
12 Correct 134 ms 67048 KB Output is correct
13 Correct 151 ms 67012 KB Output is correct
14 Correct 146 ms 67072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Incorrect 2 ms 384 KB Output isn't correct
17 Halted 0 ms 0 KB -