Submission #471853

# Submission time Handle Problem Language Result Execution time Memory
471853 2021-09-11T07:56:44 Z prvocislo Lamps (JOI19_lamps) C++17
47 / 100
1000 ms 113808 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
typedef long long ll;
using namespace std;

const int inf = 1e9 + 5;
void upd(int& a, const int& b) { a = min(a, b); }
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	string sa, sb;
	cin >> n >> sa >> sb;
	vector<int> a, b;
	for (int i = 0; i < n; i++) a.push_back(sa[i] == '1');
	for (int i = 0; i < n; i++) b.push_back(sb[i] == '1');
	map<vector<int>, int> m;
	int cnt = 0;
	for (int i = 0; i < 8; i++)
	{
		vector<int> v;
		for (int j = 0; j < 3; j++) if (i & (1 << j)) v.push_back(j);
		do
		{
			if (!m.count(v)) m[v] = cnt++;
		} while (next_permutation(v.begin(), v.end()));
	}
	vector<vector<int> > dp(n + 1, vector<int>(cnt, inf));
	dp[0][m[{}]] = 0;
	for (int i = 0; i < n; i++)
	{
		// ideme ukoncit par zmien
		for (const pair<vector<int>, int>& p : m)
		{
			for (int j = 0; j < (1 << p.first.size()); j++)
			{
				vector<int> x;
				for (int k = 0; k < p.first.size(); k++) if (j & (1 << k))
					x.push_back(p.first[k]);
				upd(dp[i][m[x]], dp[i][p.second]);
			}
		}
		// ideme vytvorit par zmien
		for (const pair<vector<int>, int>& p : m)
		{
			for (int j = 0; j < (1 << p.first.size()); j++)
			{
				vector<int> x;
				for (int k = 0; k < p.first.size(); k++) if (j & (1 << k))
					x.push_back(p.first[k]);
				upd(dp[i][p.second], dp[i][m[x]] + p.first.size() - x.size());
			}
		}
		// ideme na dalsi prvok
		for (const pair<vector<int>, int>& p : m)
		{
			int val = a[i];
			for (int j : p.first)
			{
				if (j == 0) val = 0;
				if (j == 1) val = 1;
				if (j == 2) val = !val;
			}
			if (val == b[i]) upd(dp[i + 1][p.second], dp[i][p.second]);
		}
	}
	int ans = inf;
	for (int i = 0; i < dp[n].size(); i++) upd(ans, dp[n][i]);
	cout << ans << "\n";
	return 0;
}

Compilation message

lamp.cpp: In function 'int main()':
lamp.cpp:43:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for (int k = 0; k < p.first.size(); k++) if (j & (1 << k))
      |                     ~~^~~~~~~~~~~~~~~~
lamp.cpp:54:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     for (int k = 0; k < p.first.size(); k++) if (j & (1 << k))
      |                     ~~^~~~~~~~~~~~~~~~
lamp.cpp:73:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |  for (int i = 0; i < dp[n].size(); i++) upd(ans, dp[n][i]);
      |                  ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 308 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 2 ms 204 KB Output is correct
21 Correct 1 ms 312 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 316 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 316 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 308 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 2 ms 204 KB Output is correct
21 Correct 1 ms 312 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 316 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 316 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 29 ms 460 KB Output is correct
36 Correct 29 ms 544 KB Output is correct
37 Correct 29 ms 460 KB Output is correct
38 Correct 36 ms 528 KB Output is correct
39 Correct 32 ms 460 KB Output is correct
40 Correct 30 ms 460 KB Output is correct
41 Correct 33 ms 460 KB Output is correct
42 Correct 30 ms 460 KB Output is correct
43 Correct 29 ms 460 KB Output is correct
44 Correct 29 ms 460 KB Output is correct
45 Correct 29 ms 460 KB Output is correct
46 Correct 36 ms 460 KB Output is correct
47 Correct 29 ms 460 KB Output is correct
48 Correct 29 ms 544 KB Output is correct
49 Correct 29 ms 460 KB Output is correct
50 Correct 30 ms 540 KB Output is correct
51 Correct 32 ms 580 KB Output is correct
52 Correct 30 ms 440 KB Output is correct
53 Correct 31 ms 440 KB Output is correct
54 Correct 29 ms 444 KB Output is correct
55 Correct 30 ms 440 KB Output is correct
56 Correct 30 ms 460 KB Output is correct
57 Correct 29 ms 548 KB Output is correct
58 Correct 40 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Execution timed out 1076 ms 113808 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 308 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 2 ms 204 KB Output is correct
21 Correct 1 ms 312 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 316 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 316 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 29 ms 460 KB Output is correct
36 Correct 29 ms 544 KB Output is correct
37 Correct 29 ms 460 KB Output is correct
38 Correct 36 ms 528 KB Output is correct
39 Correct 32 ms 460 KB Output is correct
40 Correct 30 ms 460 KB Output is correct
41 Correct 33 ms 460 KB Output is correct
42 Correct 30 ms 460 KB Output is correct
43 Correct 29 ms 460 KB Output is correct
44 Correct 29 ms 460 KB Output is correct
45 Correct 29 ms 460 KB Output is correct
46 Correct 36 ms 460 KB Output is correct
47 Correct 29 ms 460 KB Output is correct
48 Correct 29 ms 544 KB Output is correct
49 Correct 29 ms 460 KB Output is correct
50 Correct 30 ms 540 KB Output is correct
51 Correct 32 ms 580 KB Output is correct
52 Correct 30 ms 440 KB Output is correct
53 Correct 31 ms 440 KB Output is correct
54 Correct 29 ms 444 KB Output is correct
55 Correct 30 ms 440 KB Output is correct
56 Correct 30 ms 460 KB Output is correct
57 Correct 29 ms 548 KB Output is correct
58 Correct 40 ms 460 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 1 ms 204 KB Output is correct
61 Correct 1 ms 204 KB Output is correct
62 Correct 1 ms 328 KB Output is correct
63 Correct 1 ms 204 KB Output is correct
64 Correct 1 ms 204 KB Output is correct
65 Execution timed out 1076 ms 113808 KB Time limit exceeded
66 Halted 0 ms 0 KB -