# AtCoder Beginner Contest 185 Tutorial
See the Video Tutorial (opens new window).
And here are the solutions.
# Problem A - ABC Preparation (opens new window)
Just output the minimum of the four numbers.
Time complexity is ã
Code (Python 3)
print(min(map(int, input().split())))
1
# Problem B - Smartphone Addiction (opens new window)
Simulation.
Time complexity is .
Code (Python 3)
n, m, t = map(int, input().split())
last = 0
now = n
for _ in range(m):
ai, bi = map(int, input().split())
now -= ai - last
if now <= 0:
print('No')
exit(0)
now += bi - ai
if now > n:
now = n
last = bi
now -= t - last
print('Yes' if now > 0 else 'No')
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Problem C - Duodecim Ferra (opens new window)
The answer is .
Time complexity is .
Code (Python 3)
from math import comb
l = int(input())
print(comb(l - 1, 11))
1
2
3
4
2
3
4
# Problem D - Stamp (opens new window)
Find all white segments. The length of the shortest segment will be the optimal value for . Then just calculate , where is the length of the -th white segment.
Time complexity is .
Code (Python 3)
n, m = map(int, input().split())
a = [] if m == 0 else list(map(int, input().split()))
a.sort()
if m == 0:
print(1)
else:
seg = []
if a[0] != 1:
seg.append(a[0] - 1)
if a[-1] != n:
seg.append(n - a[-1])
for i in range(m - 1):
if a[i + 1] - a[i] > 1:
seg.append(a[i + 1] - a[i] - 1)
if len(seg) == 0:
print(0)
else:
shortest = min(seg)
print(sum((si - 1) // shortest + 1 for si in seg))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Problem E - Sequence Matching (opens new window)
Similar to the Longest Common Subsequence problem. Consider transitions from .
Time complexity is .
Code (Python 3)
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
dp = [[0 for _ in range(m + 1)] for _ in range(n + 1)]
for i in range(n + 1):
for j in range(m + 1):
if i == 0 and j == 0:
continue
dp[i][j] = int(1e6)
if i > 0:
dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1)
if j > 0:
dp[i][j] = min(dp[i][j], dp[i][j - 1] + 1)
if i > 0 and j > 0:
extra = -1 if a[i - 1] == b[j - 1] else 0
dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + 1 + extra)
print(dp[n][m])
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Problem F - Range Xor Query (opens new window)
A typical segment tree with single update and range query. Just use the template in AC-Library.
Time complexity is .
Code (C++)
#include <atcoder/segtree>
#include <iostream>
#include <vector>
using namespace std;
int op(int a, int b) { return a ^ b; }
int e() { return 0; }
int main() {
int n, q;
cin >> n >> q;
vector<int> v(n);
for (int i = 0; i < n; ++i)
cin >> v[i];
atcoder::segtree<int, op, e> seg(v);
while (q--) {
int t, x, y;
cin >> t >> x >> y;
if (t == 1) {
seg.set(x - 1, v[x - 1] ^ y);
v[x - 1] ^= y;
} else {
cout << seg.prod(x - 1, y) << endl;
}
}
}
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
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