Skip to content

Commit e31d1ca

Browse files
authored
Merge pull request #397 from xirc/atcoder/abc020
AtCoder/ABC020{A,B,C}
2 parents b34867d + 7fbfca0 commit e31d1ca

File tree

4 files changed

+119
-0
lines changed

4 files changed

+119
-0
lines changed

atcoder/abc020/A/main.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
using ll = int64_t;
5+
using ff = long double;
6+
7+
int main() {
8+
ios_base::sync_with_stdio(false);
9+
cin.tie(0); cout.tie(0);
10+
11+
int Q;
12+
cin >> Q;
13+
if (Q == 1) {
14+
cout << "ABC" << endl;
15+
} else if (Q == 2) {
16+
cout << "chokudai" << endl;
17+
}
18+
19+
return 0;
20+
}

atcoder/abc020/B/main.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
using ll = int64_t;
5+
using ff = long double;
6+
7+
int main() {
8+
ios_base::sync_with_stdio(false);
9+
cin.tie(0); cout.tie(0);
10+
11+
string A, B;
12+
cin >> A >> B;
13+
stringstream ss(A + B);
14+
int C;
15+
ss >> C;
16+
cout << (C * 2) << endl;
17+
18+
return 0;
19+
}

atcoder/abc020/C/main.cpp

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#include <bits/stdc++.h>
2+
3+
inline int64_t binary_search(
4+
std::function<bool(int64_t)> const& predicate,
5+
int64_t ng,
6+
int64_t ok
7+
) {
8+
assert(!predicate(ng) && predicate(ok));
9+
while (abs(ok - ng) > 1) {
10+
auto m = (ok + ng) / 2;
11+
if (predicate(m)) ok = m;
12+
else ng = m;
13+
}
14+
return ok;
15+
}
16+
17+
using namespace std;
18+
using ll = int64_t;
19+
using ff = long double;
20+
21+
int H, W, T;
22+
vector<string> M;
23+
int sX, sY, gX, gY;
24+
25+
vector<int> dx = { 1, -1, 0, 0 };
26+
vector<int> dy = { 0, 0, 1, -1 };
27+
bool pass(ll XX) {
28+
priority_queue<array<ll,3>> Q;
29+
vector<vector<bool>> done(H, vector<bool>(W, false));
30+
Q.push({ 0, sX, sY });
31+
while (Q.size()) {
32+
auto entry = Q.top(); Q.pop();
33+
ll t = -entry[0];
34+
int x = entry[1], y = entry[2];
35+
if (done[y][x]) continue;
36+
done[y][x] = true;
37+
for (int i = 0; i < 4; ++i) {
38+
int nx = x + dx[i], ny = y + dy[i];
39+
if (nx < 0 || nx >= W) continue;
40+
if (ny < 0 || ny >= H) continue;
41+
if (done[ny][nx]) continue;
42+
if (nx == gX && ny == gY) {
43+
return t + 1 <= T;
44+
}
45+
ll nt = t + (M[ny][nx] == '.' ? 1 : XX);
46+
Q.push({ -nt, nx, ny });
47+
}
48+
}
49+
return false;
50+
}
51+
52+
ll solve() {
53+
for (int y = 0; y < H; y++) {
54+
for (int x = 0; x < W; x++) {
55+
if (M[y][x] == 'S') {
56+
sX = x, sY = y;
57+
}
58+
if (M[y][x] == 'G') {
59+
gX = x, gY = y;
60+
}
61+
}
62+
}
63+
ll ng = T + 1, ok = 1;
64+
return binary_search(pass, ng, ok);
65+
}
66+
67+
int main() {
68+
ios_base::sync_with_stdio(false);
69+
cin.tie(0); cout.tie(0);
70+
71+
cin >> H >> W >> T;
72+
M.assign(H, "");
73+
for (int y = 0; y < H; ++y) {
74+
cin >> M[y];
75+
}
76+
cout << solve() << endl;
77+
78+
return 0;
79+
}

lib/cpalgo/util/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ We can use this technique in many problems. It's a pretty powerful technique.
2626
- [食塩水](https://atcoder.jp/contests/abc034/tasks/abc034_d)
2727
- [Widespread](https://atcoder.jp/contests/abc063/tasks/arc075_b)
2828
- [射撃王](https://atcoder.jp/contests/abc023/tasks/abc023_d)
29+
- [壁抜け](https://atcoder.jp/contests/abc020/tasks/abc020_c)
2930

3031

3132
## Dice

0 commit comments

Comments
 (0)