A

1
2
3
4
5
6
7
8
9
10
11
12
13
14
signed main() {
IOS;
int ans = 0;
for (int i = 1; i <= 12; i++) {
string a;
cin >> a;
if (a.size() == i) {
ans++;
}
}
cout << ans << endl;

return 0;
}

B

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
signed main() {
IOS;
string a;
cin >> a;
int ans = 0;
vector<int> b(30);
for (int i = 1; i <= a.size(); i++) {
b[a[i] - 'A'] = i;
}
for (int i = 1; i <= 25; i++) {
ans += abs(b[i] - b[i - 1]);
}
cout << ans << endl;

return 0;
}

C

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
signed main()
{
IOS;
int n;
cin >> n;
int a = -1e9, b = -1e9;
for (int i = 1; i <= n; i++)
{
int x;
cin >> x;
a = max(a, x);
}
for (int i = 1; i <= n; i++)
{
int x;
cin >> x;
b = max(b, x);
}
cout << a + b << endl;

return 0;
}

D

反向连边

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
#define MAX 200005
vector<PII> G[MAX];
int d[MAX];
int st[MAX];
int ind[MAX];
void dfs(int u, int fa)
{
for (int i = 0; i < G[u].size(); i++) {
int v = G[u][i].first, w = G[u][i].second;
if (v == fa) {
continue;
}
if (d[v] == 32423424234)
{
d[v] = d[u] + w;
dfs(v, u);
}
}
}
signed main()
{
IOS;
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
d[i] = 32423424234;
}
for (int i = 1; i <= m; i++) {
int u, v, w;
cin >> u >> v >> w;
G[u].push_back({v, w});
G[v].push_back({u, -w});
}
for (int i = 1; i <= n; i++) {
if (d[i] == 32423424234)
{
d[i] = 1;
dfs(i, -1);
}
}
for (int i = 1; i <= n; i++) {
cout << d[i] << ' ';
}

return 0;
}

E

二分

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
64
65
66
67
68
69
70
71
72
73
74
75
76
void solve() {

i64 n, m, k, sum = 0;
cin >> n >> m >> k;

vector<pll> a(n + 1);
vector<i64> ans(n + 1, 0), pre(n + 1, 0), b(n + 1, 0);
for(int i = 1; i <= n; i ++) {
cin >> a[i].first;
a[i].second = i;
sum += a[i].first;
}

if(n == m) {
for(int i = 1; i <= n; i ++) {
cout << 0 << " \n"[i == n];
}
return;
}

i64 tmp = k - sum;

sort(a.begin() + 1, a.begin() + 1 + n);

for(int i = 1; i <= n; i ++) {
pre[i] = pre[i - 1] + a[i].first;
}

for(int i = 1; i <= n; i ++) {
b[i] = a[i].first;
}

auto check = [&](i64 x, int id) -> bool {
i64 res = a[id].first + x + 1;
// cout << "? " << mid << ' ' << id << ' ' << pos << '\n';
i64 l = n - m, r = n;
while(l < r) {i64 mid = l + r + 1 >> 1;
if(b[mid] < res) {
l = mid;
} else {
r = mid - 1;
}
}
if(res <= b[n - m]) {
return false;
} else {
i64 y = l - n + m, tot;
if(id <= n - m) {
tot = res * y - (pre[l] - pre[n - m]);
} else {
tot = res * y - (pre[l] - pre[n - m - 1] - b[id]);
}
if(tmp - x >= tot) {
return false;
} else {
return true;
}
}
};

for(int i = 1; i <= n; i ++) {
i64 l = 0, r = tmp;
while(l < r) {
i64 mid = l + r >> 1;
if(check(mid, i)) {
r = mid;
} else {
l = mid + 1;
}
}
ans[a[i].second] = check(l, i) ? l : -1;
}

for(int i = 1; i <= n; i ++) {
cout << ans[i] << " \n"[i == n];
}