5551 | 2023-07-24 18:22:47 | Valaki2 | Széfnyitás | cpp17 | Accepted 100/100 | 4ms | 4824 KiB |
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second
int n;
struct subset {
vector<bool> inout;
subset() {
inout.assign(1 + n, false);
}
bool operator < (const subset & other) const {
return inout < other.inout;
}
};
subset DEF;
struct ansrow {
int b;
int t[2];
};
int k;
vector<int> a;
vector<vector<int> > s;
map<subset, int> sbs; // subsets
vector<ansrow> ans;
subset step(subset nodes, bool bit) {
subset res = DEF;
for(int i = 1; i <= n; i++) {
if(nodes.inout[i]) {
res.inout[s[i][bit]] = true;
}
}
return res;
}
pair<bool, int> create_for(subset nodes) {
int partialresult = sbs[nodes];
/*cout << "???: ";
for(int i = 1; i <= n; i++) {
cout << nodes.inout[i];
}
cout << "\n";*/
if(partialresult) {
return mp(false, partialresult);
}
int idx = ans.size();
sbs[nodes] = idx;
ans.pb(ansrow());
return mp(true, idx);
}
void solve_for(subset nodes, int idx) {
vector<bool> has(2, false);
for(int i = 1; i <= n; i++) {
if(nodes.inout[i]) {
has[a[i]] = true;
}
}
if(!has[0] && !has[1]) {
exit(1);
}
if(has[0] && has[1]) {
bool which = false;
subset with_0 = DEF;
subset with_1 = DEF;
for(int i = 1; i <= n; i++) {
if(nodes.inout[i]) {
if(a[i] == 0) {
with_0.inout[i] = true;
} else if(a[i] == 1) {
with_1.inout[i] = true;
}
}
}
//cout << idx << " " << with_0.inout[1] << with_0.inout[2] << with_1.inout[1] << with_1.inout[2] << "!!!\n";
ans[idx].b = which;
subset nw0 = step(with_0, which);
pair<bool, int> res0 = create_for(nw0);
//cout << "res: " << res0.fi << " " << res0.se << "\n";
ans[idx].t[false] = res0.se;
if(res0.fi) {
solve_for(nw0, res0.se);
}
subset nw1 = step(with_1, which);
pair<bool, int> res1 = create_for(nw1);
ans[idx].t[true] = res1.se;
if(res1.fi) {
solve_for(nw1, res1.se);
}
} else {
bool which = has[1];
subset nw = step(nodes, which);
pair<bool, int> res = create_for(nw);
ans[idx] = {which, res.se, res.se};
if(res.fi) {
solve_for(nw, res.se);
}
}
}
void solve() {
cin >> n;
DEF.inout.assign(1 + n, false);
a.assign(1 + n, 0);
s.assign(1 + n, vector<int> (2, 0));
for(int i = 1; i <= n; i++) {
cin >> a[i] >> s[i][0] >> s[i][1];
}
cin >> k;
subset all = DEF;
for(int i = 1; i <= n; i++) {
all.inout[i] = true;
}
//cout << all.inout.size() << "\n";
ans.resize(1);
create_for(all);
solve_for(all, 1);
cout << (ans.size() - 1) << " " << 1 << "\n";
for(int i = 1; i < ans.size(); i++) {
cout << ans[i].b << " " << ans[i].t[0] << " " << ans[i].t[1] << "\n";
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1888 KiB | ||||
2 | Accepted | 3ms | 1952 KiB | ||||
subtask2 | 16/16 | ||||||
3 | Accepted | 3ms | 2168 KiB | ||||
4 | Accepted | 3ms | 2388 KiB | ||||
5 | Accepted | 3ms | 2604 KiB | ||||
6 | Accepted | 3ms | 3088 KiB | ||||
7 | Accepted | 3ms | 3032 KiB | ||||
8 | Accepted | 3ms | 3240 KiB | ||||
9 | Accepted | 3ms | 3328 KiB | ||||
10 | Accepted | 2ms | 3368 KiB | ||||
11 | Accepted | 3ms | 3472 KiB | ||||
12 | Accepted | 3ms | 3704 KiB | ||||
13 | Accepted | 3ms | 3736 KiB | ||||
subtask3 | 24/24 | ||||||
14 | Accepted | 3ms | 3812 KiB | ||||
15 | Accepted | 3ms | 3828 KiB | ||||
16 | Accepted | 2ms | 3840 KiB | ||||
17 | Accepted | 2ms | 3836 KiB | ||||
18 | Accepted | 3ms | 3976 KiB | ||||
19 | Accepted | 3ms | 4064 KiB | ||||
20 | Accepted | 3ms | 4220 KiB | ||||
21 | Accepted | 3ms | 4180 KiB | ||||
subtask4 | 23/23 | ||||||
22 | Accepted | 3ms | 4304 KiB | ||||
23 | Accepted | 2ms | 4396 KiB | ||||
24 | Accepted | 3ms | 4404 KiB | ||||
25 | Accepted | 3ms | 4492 KiB | ||||
26 | Accepted | 3ms | 4508 KiB | ||||
27 | Accepted | 3ms | 4780 KiB | ||||
28 | Accepted | 3ms | 4324 KiB | ||||
29 | Accepted | 3ms | 4420 KiB | ||||
subtask5 | 37/37 | ||||||
30 | Accepted | 3ms | 2168 KiB | ||||
31 | Accepted | 3ms | 2388 KiB | ||||
32 | Accepted | 3ms | 2604 KiB | ||||
33 | Accepted | 3ms | 3088 KiB | ||||
34 | Accepted | 3ms | 3032 KiB | ||||
35 | Accepted | 3ms | 3240 KiB | ||||
36 | Accepted | 3ms | 3328 KiB | ||||
37 | Accepted | 2ms | 3368 KiB | ||||
38 | Accepted | 3ms | 3472 KiB | ||||
39 | Accepted | 3ms | 3704 KiB | ||||
40 | Accepted | 3ms | 3736 KiB | ||||
41 | Accepted | 3ms | 3812 KiB | ||||
42 | Accepted | 3ms | 3828 KiB | ||||
43 | Accepted | 2ms | 3840 KiB | ||||
44 | Accepted | 2ms | 3836 KiB | ||||
45 | Accepted | 3ms | 3976 KiB | ||||
46 | Accepted | 3ms | 4064 KiB | ||||
47 | Accepted | 3ms | 4220 KiB | ||||
48 | Accepted | 3ms | 4180 KiB | ||||
49 | Accepted | 3ms | 4304 KiB | ||||
50 | Accepted | 2ms | 4396 KiB | ||||
51 | Accepted | 3ms | 4404 KiB | ||||
52 | Accepted | 3ms | 4492 KiB | ||||
53 | Accepted | 3ms | 4508 KiB | ||||
54 | Accepted | 3ms | 4780 KiB | ||||
55 | Accepted | 3ms | 4324 KiB | ||||
56 | Accepted | 3ms | 4420 KiB | ||||
57 | Accepted | 3ms | 4460 KiB | ||||
58 | Accepted | 3ms | 4540 KiB | ||||
59 | Accepted | 3ms | 4632 KiB | ||||
60 | Accepted | 3ms | 4708 KiB | ||||
61 | Accepted | 4ms | 4736 KiB | ||||
62 | Accepted | 4ms | 4716 KiB | ||||
63 | Accepted | 4ms | 4668 KiB | ||||
64 | Accepted | 4ms | 4792 KiB | ||||
65 | Accepted | 4ms | 4812 KiB | ||||
66 | Accepted | 4ms | 4812 KiB | ||||
67 | Accepted | 4ms | 4820 KiB | ||||
68 | Accepted | 4ms | 4824 KiB |