# # AtCoder Beginner Contest 182 题解

## # Problem A - twiblr (opens new window)

a, b = map(int, input().split())
print(2 * a + 100 - b)

1
2

## # Problem B - Almost GCD (opens new window)

n = int(input())
a = list(map(int, input().split()))
hi = 0
ans = 0
for i in range(2, max(a) + 1):
cnt = 0
for j in a:
if j % i == 0:
cnt += 1
if cnt > hi:
hi = cnt
ans = i
print(ans)

1
2
3
4
5
6
7
8
9
10
11
12
13

## # Problem C - To 3 (opens new window)

• 如果本身能被$3$整除，则不需要删除。
• 如果被$3$除余$1$，则首先看是否能删去$1$$1$，然后看是否能删去$2$$2$
• 如果被$3$除余$1$，则首先看是否能删去$1$$2$，然后看是否能删去$2$$1$

s = input()
n = int(s)
if n % 3 == 0:
print(0)
else:
a = list(map(int, list(s)))
c = [0] * 3
for i in a:
c[i % 3] += 1
if c[n % 3] >= 1 and len(a) > 1:
print(1)
elif c[3 - n % 3] >= 2 and len(a) > 2:
print(2)
else:
print(-1)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

## # Problem D - Wandering (opens new window)

#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
int n;
cin >> n;
int a;
ll ans = 0, hi = 0, sum = 0, pos = 0;
for (int i = 1; i <= n; ++i) {
cin >> a;
sum += a;
hi = max(hi, sum);
ans = max(ans, pos + hi);
pos += sum;
}
cout << ans;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

## # Problem E - Akari (opens new window)

#include <iostream>
#include <vector>

using namespace std;

int main() {
int h, w, n, m;
cin >> h >> w >> n >> m;
int a, b, c, d;
vector<vector<int>> mat(h, vector<int>(w));
for (int i = 0; i < n; ++i) {
cin >> a >> b;
mat[a - 1][b - 1] = 1;
}
for (int i = 0; i < m; ++i) {
cin >> c >> d;
mat[c - 1][d - 1] = -1;
}
for (int i = 0; i < h; ++i) {
bool light = false;
for (int j = 0; j < w; ++j) {
if (mat[i][j] == 1) {
light = true;
} else if (mat[i][j] == -1) {
light = false;
} else if (light)
mat[i][j] = 2;
}
light = false;
for (int j = w - 1; j >= 0; --j) {
if (mat[i][j] == 1) {
light = true;
} else if (mat[i][j] == -1) {
light = false;
} else if (light)
mat[i][j] = 2;
}
}
for (int j = 0; j < w; ++j) {
bool light = false;
for (int i = 0; i < h; ++i) {
if (mat[i][j] == 1) {
light = true;
} else if (mat[i][j] == -1) {
light = false;
} else if (light)
mat[i][j] = 2;
}
light = false;
for (int i = h - 1; i >= 0; --i) {
if (mat[i][j] == 1) {
light = true;
} else if (mat[i][j] == -1) {
light = false;
} else if (light)
mat[i][j] = 2;
}
}
int ans = 0;
for (int i = 0; i < h; ++i)
for (int j = 0; j < w; ++j)
ans += mat[i][j] > 0;
cout << ans;
}
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
61
62
63

## # Problem F - Valid payments (opens new window)

$\sum k_ia_i=x$

$\forall k_i, |k_ia_i| < a_{i+1}$

#include <iostream>
#include <unordered_map>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
int n;
ll x;
cin >> n >> x;
vector<ll> a(n);
for (int i = 0; i < n; ++i)
cin >> a[i];
unordered_map<ll, ll> v;
v[x] = 1;
ll ans = 0;
for (int i = 0; i < n; ++i) {
unordered_map<ll, ll> nv;
for (auto [c, f] : v) {
if (i + 1 < n) {
ll rem = c % a[i + 1];
nv[c - rem] += f;
if (rem > 0)
nv[c + a[i + 1] - rem] += f;
} else {
if (c % a[i] == 0)
nv[0] += f;
}
}
v = move(nv);
}
cout << v[0];
}
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