Skip to content

Commit b34867d

Browse files
authored
Merge pull request #396 from xirc/atcoder/abc023
AtCoder/ABC023
2 parents aa470c0 + 77bcd16 commit b34867d

File tree

5 files changed

+180
-0
lines changed

5 files changed

+180
-0
lines changed

atcoder/abc023/A/main.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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 X;
12+
cin >> X;
13+
14+
int sum = 0;
15+
while (X > 0) {
16+
sum += X % 10;
17+
X /= 10;
18+
}
19+
cout << sum << endl;
20+
21+
return 0;
22+
}

atcoder/abc023/B/main.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
using ll = int64_t;
5+
using ff = long double;
6+
7+
int solve(int const N, string const& S) {
8+
if (N % 2 == 0) {
9+
return -1;
10+
}
11+
int const M = N / 2;
12+
if (S[M] != 'b') return -1;
13+
14+
int l = M - 1, r = M + 1;
15+
int n = 1;
16+
vector<string> pairs = {
17+
"bb",
18+
"ac",
19+
"ca",
20+
};
21+
while (l >= 0 && r < N) {
22+
if (pairs[n%3][0] != S[l]) return -1;
23+
if (pairs[n%3][1] != S[r]) return -1;
24+
++n;
25+
--l;
26+
++r;
27+
}
28+
return n-1;
29+
}
30+
31+
int main() {
32+
ios_base::sync_with_stdio(false);
33+
cin.tie(0); cout.tie(0);
34+
35+
int N;
36+
string S;
37+
cin >> N >> S;
38+
cout << solve(N, S) << endl;
39+
40+
return 0;
41+
}

atcoder/abc023/C/main.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
using ll = int64_t;
5+
using ff = long double;
6+
7+
int R, C, K;
8+
int N;
9+
vector<int> rs, cs;
10+
11+
ll solve() {
12+
vector<vector<int>> G(R, vector<int>());
13+
vector<int> candies_by_row(R, 0);
14+
vector<int> candies_by_col(C, 0);
15+
for (int i = 0; i < N; ++i) {
16+
++candies_by_row[rs[i]];
17+
++candies_by_col[cs[i]];
18+
G[rs[i]].push_back(cs[i]);
19+
}
20+
21+
map<int,int> cols_by_candies;
22+
for (int c = 0; c < C; ++c) {
23+
++cols_by_candies[candies_by_col[c]];
24+
}
25+
26+
ll cells = 0;
27+
for (int r = 0; r < R; ++r) {
28+
for (auto c : G[r]) {
29+
int candies = candies_by_col[c];
30+
--cols_by_candies[candies];
31+
++cols_by_candies[candies-1];
32+
}
33+
34+
cells += cols_by_candies[K - candies_by_row[r]];
35+
36+
for (auto c : G[r]) {
37+
int candies = candies_by_col[c];
38+
++cols_by_candies[candies];
39+
--cols_by_candies[candies-1];
40+
}
41+
}
42+
return cells;
43+
}
44+
45+
int main() {
46+
ios_base::sync_with_stdio(false);
47+
cin.tie(0); cout.tie(0);
48+
49+
cin >> R >> C >> K;
50+
cin >> N;
51+
rs.assign(N, 0);
52+
cs.assign(N, 0);
53+
for (int i = 0; i < N; i++) {
54+
cin >> rs[i] >> cs[i];
55+
--rs[i], --cs[i];
56+
}
57+
cout << solve() << endl;
58+
59+
return 0;
60+
}

atcoder/abc023/D/main.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 N;
22+
vector<ll> H, S;
23+
24+
vector<ll> ts;
25+
bool pass(ll const X) {
26+
for (int i = 0; i < N; ++i) {
27+
if (X - H[i] < 0) return false;
28+
ts[i] = (X - H[i]) / S[i];
29+
}
30+
sort(ts.begin(), ts.end());
31+
for (int i = 0; i < N; ++i) {
32+
if (i > ts[i]) return false;
33+
}
34+
return true;
35+
}
36+
37+
ll solve() {
38+
ts.assign(N, 0);
39+
ll ng = 0, ok = numeric_limits<ll>::max() / 10;
40+
return binary_search(pass, ng, ok);
41+
}
42+
43+
int main() {
44+
ios_base::sync_with_stdio(false);
45+
cin.tie(0); cout.tie(0);
46+
47+
cin >> N;
48+
H.assign(N, 0);
49+
S.assign(N, 0);
50+
for (int i = 0; i < N; i++) {
51+
cin >> H[i] >> S[i];
52+
}
53+
cout << solve() << endl;
54+
55+
return 0;
56+
}

lib/cpalgo/util/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ We can use this technique in many problems. It's a pretty powerful technique.
2525
### Challenges
2626
- [食塩水](https://atcoder.jp/contests/abc034/tasks/abc034_d)
2727
- [Widespread](https://atcoder.jp/contests/abc063/tasks/arc075_b)
28+
- [射撃王](https://atcoder.jp/contests/abc023/tasks/abc023_d)
2829

2930

3031
## Dice

0 commit comments

Comments
 (0)