blob: f76787d038dfd8aff261afc582500d0b17b448b3 (
plain)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
#include <array>
#include <iostream>
#include <string>
#include <vector>
static const std::array<unsigned int, 5> pieces = {
0x3C, 0x081C08, 0x10101C, 0x04040404, 0x0C0C
};
static auto next = pieces.begin();
static auto current = *next;
static unsigned int currenty;
static void add(std::vector<unsigned char>& tet);
static bool move(std::vector<unsigned char>& tet, char dir);
static void show(const std::vector<unsigned char>& tet);
int main()
{
std::vector<unsigned char> tet;
std::string jet;
std::getline(std::cin, jet);
auto j = jet.cbegin();
for (int i = 0; i < 2022; ++i) {
add(tet);
while (move(tet, *j++)) {
if (tet.back() == 0)
tet.pop_back();
if (j >= jet.cend())
j = jet.cbegin();
}
}
std::cout << tet.size() << std::endl;
return 0;
}
void add(std::vector<unsigned char>& tet)
{
tet.push_back(0);
tet.push_back(0);
tet.push_back(0);
current = *next;
currenty = tet.size();
for (auto n = current; n; n >>= 8)
tet.push_back(n);
if (++next >= pieces.end())
next = pieces.begin();
}
bool move(std::vector<unsigned char>& tet, char dir)
{
auto tetcopy = tet;
if (dir == '<') {
if ((current & 0x0101) == 0) {
int i = currenty;
int shift = 1;
for (auto n = current; n; n >>= 8) {
auto t = tet[i] & ~n;
if (t & (n >> 1)) {
shift = 0;
tet = tetcopy;
break;
}
tet[i] = t | n >> 1;
++i;
}
if (shift)
current >>= 1;
}
} else if (dir == '>') {
if ((current & 0x4040) == 0) {
int i = currenty;
int shift = 1;
for (auto n = current; n; n >>= 8) {
auto t = tet[i] & ~n;
if (t & (n << 1)) {
shift = 0;
tet = tetcopy;
break;
}
tet[i] = t | n << 1;
++i;
}
if (shift)
current <<= 1;
}
} else {
return false;
}
if (currenty == 0)
return false;
tetcopy = tet;
int i = currenty;
for (auto n = current; n; n >>= 8) {
if (tet[i - 1] & n) {
tet = tetcopy;
return false;
}
tet[i] &= ~n;
tet[i - 1] |= n;
++i;
}
--currenty;
return true;
}
void show(const std::vector<unsigned char>& tet)
{
for (auto it = tet.rbegin(); it != tet.rend(); ++it) {
for (int i = 0; i < 7; ++i)
std::cout << ((*it & (1 << i)) ? '@' : '.');
std::cout << std::endl;
}
std::cout << std::endl;
}
|