-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdota649.cpp
64 lines (57 loc) · 1.49 KB
/
dota649.cpp
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
#include <algorithm>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using std::string, std::vector, std::numeric_limits;
template <typename... T>
void pln(T... args)
{
(std::cout << ... << args) << "\n";
}
void test(bool cond)
{
if (cond) pln("Passed!!");
else pln("Failed!!");
}
//----------------------------------------------------------------------------------
// #pragma GCC optimize("O3") // comment this line while debugging
namespace {
static const bool __booster = []() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
return true;
}();
} // namespace
class Solution {
public:
string predictPartyVictory(string senate)
{
std::queue<size_t> D, R;
size_t n = senate.size();
for (size_t i = 0; i < n; i++) {
if (senate[i] == 'R') R.push(i);
else D.push(i);
}
while (!D.empty() && !R.empty()) {
if (D.front() > R.front()) R.push(n++);
else D.push(n++);
D.pop(), R.pop();
}
return D.empty() ? "Radiant" : "Dire";
}
};
//----------------------------------------------------------------------------------
int main([[maybe_unused]] int argc, [[maybe_unused]] char **argv)
{
Solution s;
test(s.predictPartyVictory("DDDDRRDDDRDRDRRDDRDDDRDRRRRDRRRRRDRDDRDDRRDDRRRDDRRRDD"
"DDRRRRRRRDDRRRDDRDDDRRR"
"DRDDRDDDRRDRRDRRRDRDRDR") == "Dire");
return 0;
}