Submission #562656

# Submission time Handle Problem Language Result Execution time Memory
562656 2022-05-14T21:30:07 Z aryan12 Lamps (JOI19_lamps) C++17
100 / 100
111 ms 59296 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 = 1e6 + 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 58 ms 55056 KB Output is correct
2 Correct 60 ms 55104 KB Output is correct
3 Correct 57 ms 55096 KB Output is correct
4 Correct 56 ms 55060 KB Output is correct
5 Correct 53 ms 55024 KB Output is correct
6 Correct 55 ms 55044 KB Output is correct
7 Correct 60 ms 55036 KB Output is correct
8 Correct 57 ms 55136 KB Output is correct
9 Correct 71 ms 55024 KB Output is correct
10 Correct 59 ms 55104 KB Output is correct
11 Correct 55 ms 55116 KB Output is correct
12 Correct 56 ms 54984 KB Output is correct
13 Correct 55 ms 55048 KB Output is correct
14 Correct 58 ms 55012 KB Output is correct
15 Correct 56 ms 55028 KB Output is correct
16 Correct 56 ms 55036 KB Output is correct
17 Correct 68 ms 55004 KB Output is correct
18 Correct 63 ms 54988 KB Output is correct
19 Correct 69 ms 54996 KB Output is correct
20 Correct 53 ms 55096 KB Output is correct
21 Correct 54 ms 55144 KB Output is correct
22 Correct 55 ms 55048 KB Output is correct
23 Correct 60 ms 55076 KB Output is correct
24 Correct 59 ms 55052 KB Output is correct
25 Correct 56 ms 55116 KB Output is correct
26 Correct 57 ms 55108 KB Output is correct
27 Correct 55 ms 55064 KB Output is correct
28 Correct 56 ms 55000 KB Output is correct
29 Correct 58 ms 55088 KB Output is correct
30 Correct 57 ms 55060 KB Output is correct
31 Correct 57 ms 55060 KB Output is correct
32 Correct 56 ms 55044 KB Output is correct
33 Correct 59 ms 55032 KB Output is correct
34 Correct 69 ms 55044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 55056 KB Output is correct
2 Correct 60 ms 55104 KB Output is correct
3 Correct 57 ms 55096 KB Output is correct
4 Correct 56 ms 55060 KB Output is correct
5 Correct 53 ms 55024 KB Output is correct
6 Correct 55 ms 55044 KB Output is correct
7 Correct 60 ms 55036 KB Output is correct
8 Correct 57 ms 55136 KB Output is correct
9 Correct 71 ms 55024 KB Output is correct
10 Correct 59 ms 55104 KB Output is correct
11 Correct 55 ms 55116 KB Output is correct
12 Correct 56 ms 54984 KB Output is correct
13 Correct 55 ms 55048 KB Output is correct
14 Correct 58 ms 55012 KB Output is correct
15 Correct 56 ms 55028 KB Output is correct
16 Correct 56 ms 55036 KB Output is correct
17 Correct 68 ms 55004 KB Output is correct
18 Correct 63 ms 54988 KB Output is correct
19 Correct 69 ms 54996 KB Output is correct
20 Correct 53 ms 55096 KB Output is correct
21 Correct 54 ms 55144 KB Output is correct
22 Correct 55 ms 55048 KB Output is correct
23 Correct 60 ms 55076 KB Output is correct
24 Correct 59 ms 55052 KB Output is correct
25 Correct 56 ms 55116 KB Output is correct
26 Correct 57 ms 55108 KB Output is correct
27 Correct 55 ms 55064 KB Output is correct
28 Correct 56 ms 55000 KB Output is correct
29 Correct 58 ms 55088 KB Output is correct
30 Correct 57 ms 55060 KB Output is correct
31 Correct 57 ms 55060 KB Output is correct
32 Correct 56 ms 55044 KB Output is correct
33 Correct 59 ms 55032 KB Output is correct
34 Correct 69 ms 55044 KB Output is correct
35 Correct 57 ms 55124 KB Output is correct
36 Correct 57 ms 55060 KB Output is correct
37 Correct 56 ms 55080 KB Output is correct
38 Correct 60 ms 55000 KB Output is correct
39 Correct 58 ms 55092 KB Output is correct
40 Correct 54 ms 55104 KB Output is correct
41 Correct 59 ms 55056 KB Output is correct
42 Correct 63 ms 55040 KB Output is correct
43 Correct 54 ms 55104 KB Output is correct
44 Correct 55 ms 55024 KB Output is correct
45 Correct 53 ms 55116 KB Output is correct
46 Correct 57 ms 55068 KB Output is correct
47 Correct 59 ms 55116 KB Output is correct
48 Correct 56 ms 55068 KB Output is correct
49 Correct 58 ms 55004 KB Output is correct
50 Correct 60 ms 55096 KB Output is correct
51 Correct 64 ms 55116 KB Output is correct
52 Correct 73 ms 55020 KB Output is correct
53 Correct 56 ms 55044 KB Output is correct
54 Correct 56 ms 55032 KB Output is correct
55 Correct 56 ms 55132 KB Output is correct
56 Correct 58 ms 55116 KB Output is correct
57 Correct 65 ms 55164 KB Output is correct
58 Correct 71 ms 55072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 55000 KB Output is correct
2 Correct 56 ms 55012 KB Output is correct
3 Correct 61 ms 55020 KB Output is correct
4 Correct 56 ms 55112 KB Output is correct
5 Correct 57 ms 55012 KB Output is correct
6 Correct 59 ms 55064 KB Output is correct
7 Correct 89 ms 57556 KB Output is correct
8 Correct 89 ms 59168 KB Output is correct
9 Correct 93 ms 59260 KB Output is correct
10 Correct 89 ms 59128 KB Output is correct
11 Correct 88 ms 59180 KB Output is correct
12 Correct 84 ms 59200 KB Output is correct
13 Correct 98 ms 59256 KB Output is correct
14 Correct 93 ms 59168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 55056 KB Output is correct
2 Correct 60 ms 55104 KB Output is correct
3 Correct 57 ms 55096 KB Output is correct
4 Correct 56 ms 55060 KB Output is correct
5 Correct 53 ms 55024 KB Output is correct
6 Correct 55 ms 55044 KB Output is correct
7 Correct 60 ms 55036 KB Output is correct
8 Correct 57 ms 55136 KB Output is correct
9 Correct 71 ms 55024 KB Output is correct
10 Correct 59 ms 55104 KB Output is correct
11 Correct 55 ms 55116 KB Output is correct
12 Correct 56 ms 54984 KB Output is correct
13 Correct 55 ms 55048 KB Output is correct
14 Correct 58 ms 55012 KB Output is correct
15 Correct 56 ms 55028 KB Output is correct
16 Correct 56 ms 55036 KB Output is correct
17 Correct 68 ms 55004 KB Output is correct
18 Correct 63 ms 54988 KB Output is correct
19 Correct 69 ms 54996 KB Output is correct
20 Correct 53 ms 55096 KB Output is correct
21 Correct 54 ms 55144 KB Output is correct
22 Correct 55 ms 55048 KB Output is correct
23 Correct 60 ms 55076 KB Output is correct
24 Correct 59 ms 55052 KB Output is correct
25 Correct 56 ms 55116 KB Output is correct
26 Correct 57 ms 55108 KB Output is correct
27 Correct 55 ms 55064 KB Output is correct
28 Correct 56 ms 55000 KB Output is correct
29 Correct 58 ms 55088 KB Output is correct
30 Correct 57 ms 55060 KB Output is correct
31 Correct 57 ms 55060 KB Output is correct
32 Correct 56 ms 55044 KB Output is correct
33 Correct 59 ms 55032 KB Output is correct
34 Correct 69 ms 55044 KB Output is correct
35 Correct 57 ms 55124 KB Output is correct
36 Correct 57 ms 55060 KB Output is correct
37 Correct 56 ms 55080 KB Output is correct
38 Correct 60 ms 55000 KB Output is correct
39 Correct 58 ms 55092 KB Output is correct
40 Correct 54 ms 55104 KB Output is correct
41 Correct 59 ms 55056 KB Output is correct
42 Correct 63 ms 55040 KB Output is correct
43 Correct 54 ms 55104 KB Output is correct
44 Correct 55 ms 55024 KB Output is correct
45 Correct 53 ms 55116 KB Output is correct
46 Correct 57 ms 55068 KB Output is correct
47 Correct 59 ms 55116 KB Output is correct
48 Correct 56 ms 55068 KB Output is correct
49 Correct 58 ms 55004 KB Output is correct
50 Correct 60 ms 55096 KB Output is correct
51 Correct 64 ms 55116 KB Output is correct
52 Correct 73 ms 55020 KB Output is correct
53 Correct 56 ms 55044 KB Output is correct
54 Correct 56 ms 55032 KB Output is correct
55 Correct 56 ms 55132 KB Output is correct
56 Correct 58 ms 55116 KB Output is correct
57 Correct 65 ms 55164 KB Output is correct
58 Correct 71 ms 55072 KB Output is correct
59 Correct 57 ms 55000 KB Output is correct
60 Correct 56 ms 55012 KB Output is correct
61 Correct 61 ms 55020 KB Output is correct
62 Correct 56 ms 55112 KB Output is correct
63 Correct 57 ms 55012 KB Output is correct
64 Correct 59 ms 55064 KB Output is correct
65 Correct 89 ms 57556 KB Output is correct
66 Correct 89 ms 59168 KB Output is correct
67 Correct 93 ms 59260 KB Output is correct
68 Correct 89 ms 59128 KB Output is correct
69 Correct 88 ms 59180 KB Output is correct
70 Correct 84 ms 59200 KB Output is correct
71 Correct 98 ms 59256 KB Output is correct
72 Correct 93 ms 59168 KB Output is correct
73 Correct 84 ms 59128 KB Output is correct
74 Correct 85 ms 59148 KB Output is correct
75 Correct 88 ms 59172 KB Output is correct
76 Correct 94 ms 59192 KB Output is correct
77 Correct 96 ms 59228 KB Output is correct
78 Correct 85 ms 59172 KB Output is correct
79 Correct 86 ms 59160 KB Output is correct
80 Correct 85 ms 59196 KB Output is correct
81 Correct 84 ms 59196 KB Output is correct
82 Correct 93 ms 59168 KB Output is correct
83 Correct 95 ms 59168 KB Output is correct
84 Correct 87 ms 59164 KB Output is correct
85 Correct 89 ms 59172 KB Output is correct
86 Correct 99 ms 59148 KB Output is correct
87 Correct 98 ms 59128 KB Output is correct
88 Correct 89 ms 59216 KB Output is correct
89 Correct 91 ms 59192 KB Output is correct
90 Correct 89 ms 59240 KB Output is correct
91 Correct 101 ms 59232 KB Output is correct
92 Correct 98 ms 59120 KB Output is correct
93 Correct 100 ms 59220 KB Output is correct
94 Correct 96 ms 59180 KB Output is correct
95 Correct 101 ms 59296 KB Output is correct
96 Correct 111 ms 59264 KB Output is correct
97 Correct 95 ms 59172 KB Output is correct
98 Correct 95 ms 59164 KB Output is correct
99 Correct 108 ms 59168 KB Output is correct
100 Correct 106 ms 59196 KB Output is correct
101 Correct 95 ms 59256 KB Output is correct
102 Correct 95 ms 59136 KB Output is correct