-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20699.cpp
More file actions
103 lines (80 loc) · 1.86 KB
/
20699.cpp
File metadata and controls
103 lines (80 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
using namespace std;
const ll INF = 1e9 + 7;
const ll DIV = 987654321;
int A, B; // 2만 짝수개면 망함
array<int,3> ans[102020];
int cnt = 1;
int need[101010];
pair<int,int> di[101010];
bool go(int cur, int a, int b){
if(need[b] > a) return 0;
if(b){
b--;
ans[cur][0] = 2;
}
else{
ans[cur][0] = 1;
a--;
}
int lb = di[b].first, rb = di[b].second;
int la = (lb < rb ? (rb - lb) * 2 - 1 : 0), ra = (lb > rb ? (lb - rb) * 2 - 1 : 0);
if(la && a){
la++;
a--;
}
else if(ra && a){
ra++;
a--;
}
la += a /2;
ra += (a + 1)/2;
bool ret = 1;
if(la || lb){
cnt++;
ans[cur][1] = cnt;
ret &= go(cnt, la, lb);
}
if(ra || rb){
cnt++;
ans[cur][2] = cnt;
ret &= go(cnt ,ra, rb);
}
return ret;
}
int main()
{
fastio;
cin >> A >> B;
need[1] = 0;
need[2] = 1;
need[0] = 0;
di[1] = {0, 1};
di[2] = {1, 1};
for(int i = 3;i<= B;i++){
int a = (i - 1) / 2, b = i / 2;
need[i] = need[a] + need[b];
if(i% 2 == 0) need[i]++;
di[i] = {a, b};
int t = need[i];
for(int j = i - t;j<=i + t;j++){
int k = i - 1 - j;
if(j >=0 && k >=0){
int val = need[j] + need[k] + abs(j - k) * 2 - 1;
if(val < need[i]){
need[i] = need[j] + need[k] + abs(j - k) * 2 - 1;
di[i] = {j, k};
}
}
}
}
if(go(1, A, B)){
for(int i = 1;i<=A + B;i++){
cout << ans[i][0] << " " << ans[i][1] << " " << ans[i][2] << "\n";
}
}
else cout << -1;
return 0;
}