-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathC.cpp
More file actions
executable file
·58 lines (51 loc) · 961 Bytes
/
C.cpp
File metadata and controls
executable file
·58 lines (51 loc) · 961 Bytes
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
#include <iostream>
#include <vector>
#include <queue>
#include <functional>
using namespace std;
void digit_blocks(int N, int B) {
int pos, curr = 0;
vector<int> towers(N);
queue<int> high_1, high_2;
// helper functions
auto push_1 = [&]() {
pos = high_1.front();
towers[pos]++;
high_1.pop();
};
auto push_2 = [&]() {
pos = high_2.front();
towers[pos]++;
high_1.push(pos);
high_2.pop();
};
for (int x = 1; x <= N * B; x++) {
int D;
cin >> D;
// greedy approach, passes 50% of the time
if (D == 9 && !high_1.empty())
push_1();
else if (D >= 7 && !high_2.empty())
push_2();
else if (curr < N) {
pos = curr;
if (++towers[pos] == B - 2) {
curr++;
high_2.push(pos);
}
}
else if (!high_2.empty())
push_2();
else
push_1();
cout << pos + 1 << endl;
}
}
int main() {
int64_t P;
int T, N, B;
cin >> T >> N >> B >> P;
for (int x = 1; x <= T; x++)
digit_blocks(N, B);
return 0;
}