Skip to content

Commit 6e754bb

Browse files
committed
atcoder/abc001C (feedback from editorial)
1 parent 765f6bf commit 6e754bb

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

atcoder/abc001/C/main.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,32 @@ using namespace std;
44
using ll = long long;
55

66
int power(int dis) {
7-
double v = round(double(dis * 10) / 60);
8-
vector<int> ps = { 2, 15, 33, 54, 79, 107, 138, 171, 207, 244, 284, 326 };
7+
vector<int> ps = { 24, 154, 334, 544, 794, 1074, 1384, 1714, 2074, 2444, 2844, 3264 };
8+
assert(ps.size() == 12);
99
for (int i = 0; i < 12; ++i) {
10-
if (v <= ps[i]) return i;
10+
if (dis * 100 <= ps[i] * 60) return i;
1111
}
1212
return 12;
1313
}
1414

15-
string direction(int deg, int wp) {
16-
if (wp == 0) return "C";
17-
if (deg <= 112 || deg >= 3488) return "N";
18-
vector<int> ds = { 337, 562, 787, 1012, 1237, 1462, 1687, 1912, 2137, 2362, 2587, 2812, 3037, 3262, 3487 };
19-
vector<string> ss = { "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW" };
15+
string direction(int deg) {
16+
vector<int> ds = {
17+
112, 337, 562, 787, 1012, 1237, 1462, 1687, 1912, 2137, 2362, 2587, 2812, 3037, 3262, 3487
18+
};
19+
vector<string> ss = {
20+
"N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"
21+
};
2022
assert(ds.size() == ss.size());
2123
for (int i = 0; i < ds.size(); ++i) {
2224
if (deg <= ds[i]) return ss[i];
2325
}
24-
throw;
26+
return "N";
2527
}
2628

2729
vector<string> solve(int deg, int dis) {
2830
string ans;
2931
int wp = power(dis);
30-
string dir = direction(deg, wp);
32+
string dir = wp > 0 ? direction(deg) : "C";
3133
return { dir, to_string(wp) };
3234
}
3335

0 commit comments

Comments
 (0)