Submission #562655

# Submission time Handle Problem Language Result Execution time Memory
562655 2022-05-14T21:29:38 Z aryan12 Lamps (JOI19_lamps) C++17
47 / 100
25 ms 17720 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5 + 5, INF = 1e14;
vector<vector<int> > dp(N, vector<int> (3, INF));

// 0 - OFF
// 1 - ON
// 2 - UNUSED

char getvalue(char a, int x)
{
	if(x == 0) return '0';
	if(x == 1) return '1';
	return a;
}

void Solve() 
{
	int n;
	cin >> n;
	string a, b;
	cin >> a >> b;
	dp[0][2] = 0;
	for(int i = 1; i <= n; i++)
	{
		// cout << "i = " << i << endl;
		char cur_a = a[i - 1], cur_b = b[i - 1];
		for(int j = 0; j < 3; j++)
		{
			for(int k = 0; k < 3; k++)
			{
				int value = dp[i - 1][k];
				// if the last value had an operation and the current value has a diff / no operation
				if(j != k && j != 2)
				{
					value++;
				}
				// if the answer after the operation is not consistent with b[i]
				if((i == 1 || getvalue(a[i - 2], k) == b[i - 2]) && getvalue(cur_a, j) != cur_b)
				{
					value++;
				}
				dp[i][j] = min(dp[i][j], value);
			}
		}
	}
	// for(int i = 0; i <= n; i++)
	// {
	// 	for(int j = 0; j < 3; j++)
	// 	{
	// 		cout << dp[i][j] << " ";
	// 	}
	// 	cout << "\n";
	// }
	int ans = INF;
	for(int i = 0; i < 3; i++)
	{
		ans = min(ans, dp[n][i]);
	}
	cout << ans << "\n";
}

int32_t main() 
{
	auto begin = std::chrono::high_resolution_clock::now();
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	// cin >> t;
	for(int i = 1; i <= t; i++) 
	{
		//cout << "Case #" << i << ": ";
		Solve();
	}
	auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5716 KB Output is correct
2 Correct 6 ms 5716 KB Output is correct
3 Correct 6 ms 5824 KB Output is correct
4 Correct 6 ms 5716 KB Output is correct
5 Correct 7 ms 5828 KB Output is correct
6 Correct 6 ms 5820 KB Output is correct
7 Correct 6 ms 5716 KB Output is correct
8 Correct 6 ms 5812 KB Output is correct
9 Correct 8 ms 5716 KB Output is correct
10 Correct 6 ms 5844 KB Output is correct
11 Correct 7 ms 5816 KB Output is correct
12 Correct 7 ms 5800 KB Output is correct
13 Correct 6 ms 5820 KB Output is correct
14 Correct 6 ms 5760 KB Output is correct
15 Correct 7 ms 5716 KB Output is correct
16 Correct 6 ms 5716 KB Output is correct
17 Correct 7 ms 5812 KB Output is correct
18 Correct 8 ms 5716 KB Output is correct
19 Correct 6 ms 5820 KB Output is correct
20 Correct 9 ms 5736 KB Output is correct
21 Correct 9 ms 5824 KB Output is correct
22 Correct 6 ms 5716 KB Output is correct
23 Correct 7 ms 5716 KB Output is correct
24 Correct 8 ms 5812 KB Output is correct
25 Correct 7 ms 5716 KB Output is correct
26 Correct 8 ms 5716 KB Output is correct
27 Correct 7 ms 5764 KB Output is correct
28 Correct 7 ms 5716 KB Output is correct
29 Correct 6 ms 5816 KB Output is correct
30 Correct 6 ms 5716 KB Output is correct
31 Correct 7 ms 5808 KB Output is correct
32 Correct 6 ms 5768 KB Output is correct
33 Correct 10 ms 5824 KB Output is correct
34 Correct 7 ms 5716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5716 KB Output is correct
2 Correct 6 ms 5716 KB Output is correct
3 Correct 6 ms 5824 KB Output is correct
4 Correct 6 ms 5716 KB Output is correct
5 Correct 7 ms 5828 KB Output is correct
6 Correct 6 ms 5820 KB Output is correct
7 Correct 6 ms 5716 KB Output is correct
8 Correct 6 ms 5812 KB Output is correct
9 Correct 8 ms 5716 KB Output is correct
10 Correct 6 ms 5844 KB Output is correct
11 Correct 7 ms 5816 KB Output is correct
12 Correct 7 ms 5800 KB Output is correct
13 Correct 6 ms 5820 KB Output is correct
14 Correct 6 ms 5760 KB Output is correct
15 Correct 7 ms 5716 KB Output is correct
16 Correct 6 ms 5716 KB Output is correct
17 Correct 7 ms 5812 KB Output is correct
18 Correct 8 ms 5716 KB Output is correct
19 Correct 6 ms 5820 KB Output is correct
20 Correct 9 ms 5736 KB Output is correct
21 Correct 9 ms 5824 KB Output is correct
22 Correct 6 ms 5716 KB Output is correct
23 Correct 7 ms 5716 KB Output is correct
24 Correct 8 ms 5812 KB Output is correct
25 Correct 7 ms 5716 KB Output is correct
26 Correct 8 ms 5716 KB Output is correct
27 Correct 7 ms 5764 KB Output is correct
28 Correct 7 ms 5716 KB Output is correct
29 Correct 6 ms 5816 KB Output is correct
30 Correct 6 ms 5716 KB Output is correct
31 Correct 7 ms 5808 KB Output is correct
32 Correct 6 ms 5768 KB Output is correct
33 Correct 10 ms 5824 KB Output is correct
34 Correct 7 ms 5716 KB Output is correct
35 Correct 6 ms 5716 KB Output is correct
36 Correct 6 ms 5820 KB Output is correct
37 Correct 6 ms 5820 KB Output is correct
38 Correct 6 ms 5820 KB Output is correct
39 Correct 6 ms 5716 KB Output is correct
40 Correct 7 ms 5764 KB Output is correct
41 Correct 6 ms 5820 KB Output is correct
42 Correct 6 ms 5820 KB Output is correct
43 Correct 8 ms 5760 KB Output is correct
44 Correct 7 ms 5812 KB Output is correct
45 Correct 7 ms 5716 KB Output is correct
46 Correct 6 ms 5716 KB Output is correct
47 Correct 7 ms 5844 KB Output is correct
48 Correct 8 ms 5820 KB Output is correct
49 Correct 6 ms 5828 KB Output is correct
50 Correct 9 ms 5816 KB Output is correct
51 Correct 7 ms 5716 KB Output is correct
52 Correct 7 ms 5716 KB Output is correct
53 Correct 9 ms 5716 KB Output is correct
54 Correct 8 ms 5812 KB Output is correct
55 Correct 6 ms 5824 KB Output is correct
56 Correct 6 ms 5716 KB Output is correct
57 Correct 6 ms 5716 KB Output is correct
58 Correct 6 ms 5812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5824 KB Output is correct
2 Correct 9 ms 5716 KB Output is correct
3 Correct 6 ms 5716 KB Output is correct
4 Correct 8 ms 5716 KB Output is correct
5 Correct 6 ms 5820 KB Output is correct
6 Correct 6 ms 5816 KB Output is correct
7 Runtime error 25 ms 17720 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5716 KB Output is correct
2 Correct 6 ms 5716 KB Output is correct
3 Correct 6 ms 5824 KB Output is correct
4 Correct 6 ms 5716 KB Output is correct
5 Correct 7 ms 5828 KB Output is correct
6 Correct 6 ms 5820 KB Output is correct
7 Correct 6 ms 5716 KB Output is correct
8 Correct 6 ms 5812 KB Output is correct
9 Correct 8 ms 5716 KB Output is correct
10 Correct 6 ms 5844 KB Output is correct
11 Correct 7 ms 5816 KB Output is correct
12 Correct 7 ms 5800 KB Output is correct
13 Correct 6 ms 5820 KB Output is correct
14 Correct 6 ms 5760 KB Output is correct
15 Correct 7 ms 5716 KB Output is correct
16 Correct 6 ms 5716 KB Output is correct
17 Correct 7 ms 5812 KB Output is correct
18 Correct 8 ms 5716 KB Output is correct
19 Correct 6 ms 5820 KB Output is correct
20 Correct 9 ms 5736 KB Output is correct
21 Correct 9 ms 5824 KB Output is correct
22 Correct 6 ms 5716 KB Output is correct
23 Correct 7 ms 5716 KB Output is correct
24 Correct 8 ms 5812 KB Output is correct
25 Correct 7 ms 5716 KB Output is correct
26 Correct 8 ms 5716 KB Output is correct
27 Correct 7 ms 5764 KB Output is correct
28 Correct 7 ms 5716 KB Output is correct
29 Correct 6 ms 5816 KB Output is correct
30 Correct 6 ms 5716 KB Output is correct
31 Correct 7 ms 5808 KB Output is correct
32 Correct 6 ms 5768 KB Output is correct
33 Correct 10 ms 5824 KB Output is correct
34 Correct 7 ms 5716 KB Output is correct
35 Correct 6 ms 5716 KB Output is correct
36 Correct 6 ms 5820 KB Output is correct
37 Correct 6 ms 5820 KB Output is correct
38 Correct 6 ms 5820 KB Output is correct
39 Correct 6 ms 5716 KB Output is correct
40 Correct 7 ms 5764 KB Output is correct
41 Correct 6 ms 5820 KB Output is correct
42 Correct 6 ms 5820 KB Output is correct
43 Correct 8 ms 5760 KB Output is correct
44 Correct 7 ms 5812 KB Output is correct
45 Correct 7 ms 5716 KB Output is correct
46 Correct 6 ms 5716 KB Output is correct
47 Correct 7 ms 5844 KB Output is correct
48 Correct 8 ms 5820 KB Output is correct
49 Correct 6 ms 5828 KB Output is correct
50 Correct 9 ms 5816 KB Output is correct
51 Correct 7 ms 5716 KB Output is correct
52 Correct 7 ms 5716 KB Output is correct
53 Correct 9 ms 5716 KB Output is correct
54 Correct 8 ms 5812 KB Output is correct
55 Correct 6 ms 5824 KB Output is correct
56 Correct 6 ms 5716 KB Output is correct
57 Correct 6 ms 5716 KB Output is correct
58 Correct 6 ms 5812 KB Output is correct
59 Correct 6 ms 5824 KB Output is correct
60 Correct 9 ms 5716 KB Output is correct
61 Correct 6 ms 5716 KB Output is correct
62 Correct 8 ms 5716 KB Output is correct
63 Correct 6 ms 5820 KB Output is correct
64 Correct 6 ms 5816 KB Output is correct
65 Runtime error 25 ms 17720 KB Execution killed with signal 11
66 Halted 0 ms 0 KB -