Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
60 lines (57 loc) · 1.41 KB

File metadata and controls

60 lines (57 loc) · 1.41 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#include "common.h"
namespace {
int p1(const std::vector<std::string> &in) {
int r{0};
for (const auto &l : in) {
bool fail{false};
const auto gid = gb::split(l, ": ").at(0);
const auto g = gb::split(l, ": ").at(1);
for (const auto &s : gb::split(g, "; ")) {
for (const auto &c : gb::split(s, ", ")) {
int n;
std::string col;
gb::sscanf(c, "%d %[^,;]", n, col);
if (col == "blue" && n > 14)
fail = fail || true;
if (col == "red" && n > 12)
fail = fail || true;
if (col == "green" && n > 13)
fail = fail || true;
}
}
if (!fail) {
int n;
gb::sscanf(gid, "Game %d", n);
r += n;
}
}
return r;
}
int64_t p2(const std::vector<std::string> &in) {
int64_t t{0};
for (const auto &l : in) {
int r{1}, b{1}, g{1};
const auto gm = gb::split(l, ": ").at(1);
for (const auto &s : gb::split(gm, "; ")) {
for (const auto &c : gb::split(s, ", ")) {
int n;
std::string col;
gb::sscanf(c, "%d %[^,;]", n, col);
if (col == "blue")
b = std::max(n, b);
if (col == "red")
r = std::max(n, r);
if (col == "green")
g = std::max(n, g);
}
}
t += static_cast<int64_t>(r * b * g);
}
return t;
}
} // namespace
int main() {
const auto &in = gb::readIn();
gb::writeOut(p1(in));
gb::writeOut(p2(in));
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.