AtCoder Beginner Contest 373(ABCDEF 题)视频讲解

时间:2024-10-01 09:24:37

A - September

Problem Statement

There are 12 12 12 strings S 1 , S 2 , … , S 12 S_1, S_2, \ldots, S_{12} S1,S2,,S12 consisting of lowercase English letters.
Find how many integers i i i ( 1 ≤ i ≤ 12 ) (1 \leq i \leq 12) (1i12) satisfy that the length of S i S_i Si is i i i.

Constraints

Each S i S_i Si is a string of length between 1 1 1 and 100 100 100, inclusive, consisting of lowercase English letters. ( 1 ≤ i ≤ 12 ) (1 \leq i \leq 12) (1i12)

Input

The input is given from Standard Input in the following format:

S 1 S_1 S1
S 2 S_2 S2
⋮ \vdots
S 12 S_{12} S12

Output

Print the number of integers i i i ( 1 ≤ i ≤ 12 ) (1 \leq i \leq 12) (1i12) such that the length of S i S_i Si is i i i.

Sample Input 1
january
february
march
april
may
june
july
august
september
october
november
december
Sample Output 1
1

There is only one integer i i i such that the length of S i S_i Si is i i i: 9 9 9. Thus, print 1.

Sample Input 2
ve
inrtfa
npccxva
djiq
lmbkktngaovl
mlfiv
fmbvcmuxuwggfq
qgmtwxmb
jii
ts
bfxrvs
eqvy
Sample Output 2
2

There are two integers i i i such that the length of S i S_i Si is i i i: 4 4 4 and 8 8 8. Thus, print 2.

Solution

具体见文末视频。


Code

#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second

using namespace std;

signed main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

	int res = 0;
	for (int i = 1; i <= 12; i ++) {
		string s;
		cin >> s;
		if (s.size() == i) res ++;
	}
	
	cout << res << endl;

	return 0;
}

B - 1D Keyboard

Problem Statement

There is a keyboard with 26 26 26 keys arranged on a number line.
The arrangement of this keyboard is represented by a string S S S, which is a permutation of ABCDEFGHIJKLMNOPQRSTUVWXYZ.
The key corresponding to the character S x S_x Sx is located at coordinate x x x ( 1 ≤ x ≤ 26 ) (1 \leq x \leq 26) (1x26). Here, S x S_x Sx denotes the x x x-th character of S S S.
You will use this keyboard to input ABCDEFGHIJKLMNOPQRSTUVWXYZ in this order, typing each letter exactly once with your right index finger.
To input a character, you need to move your finger to the coordinate of the key corresponding to that character and press the key.
Initially, your finger is at the coordinate of the key corresponding to A. Find the minimal possible total traveled distance of your finger from pressing the key for A to pressing the key for Z. Here, pressing a key does not contribute to the distance.

Constraints

S S S is a permutation of ABCDEFGHIJKLMNOPQRSTUVWXYZ.

Input

The input is given from Standard Input in the following format:

S S S

Output

Print the answer.

Sample Input 1
ABCDEFGHIJKLMNOPQRSTUVWXYZ
Sample Output 1
25

From pressing the key for A to pressing the key for Z, you need to move your finger 1 1 1 unit at a time in the positive direction, resulting in a total traveled distance of 25 25 25. It is impossible to press all keys with a total traveled distance less than 25 25 25, so print 25.

Sample Input 2
MGJYIZDKSBHPVENFLQURTCWOAX
Sample Output 2
223

Solution

具体见文末视频。

Code

#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second

using namespace std;

signed main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

	int res = 0;
	unordered_map<char, int> idx;
	for (int i = 1; i <= 26; i ++) {
		char x;
		cin >> x, idx[x] = i;
	}
	for (char i = 'A' + 1; i <= 'Z'; i ++)
		res += abs(idx[i] - idx[i - 1]);
	
	cout << res << endl;

	return 0;
}

C - Max Ai+Bj

Problem Statement

You are given two integer sequences A A A and B B B, each of length N N N. Choose integers i , j i, j i,j ( 1 ≤ i , j ≤ N ) (1 \leq i, j \leq N) (1i,jN) to maximize the value of A i + B j A_i + B_j Ai+Bj.

Constraints

1 ≤ N ≤ 5 × 1 0 5 1 \leq N \leq 5 \times 10^5 1N5×105
∣ A i ∣ ≤ 1 0 9 |A_i| \leq 10^9 Ai109 ( i = 1 , 2 , … , N ) (i=1,2,\dots,N) (i=1,2,,N)
∣ B j ∣ ≤ 1 0 9 |B_j| \leq 10^9 Bj109 ( j = 1 , 2 , … , N ) (j=1,2,\dots,N) (j=1,2,,N)
All input values are integers.

Input

The input is given from Standard Input in the following format:

N N N
A 1 A_1 A1 A 2 A_2 A2 … \dots A N A_N AN
B 1 B_1 B1 B 2 B_2 B2 … \dots B N B_N BN

Output

Print the maximum possible value of A i + B j A_i + B_j Ai+Bj.

Sample Input 1
2
-1 5
3 -7
Sample Output 1
8

For ( i , j ) = ( 1 , 1 ) , ( 1 , 2 ) , ( 2 , 1 ) , ( 2 , 2 ) (i,j) = (1,1), (1,2), (2,1), (2,2) (i,j)=(1,1),(1,2),(2,1),(2,2), the values of A i + B j A_i + B_j Ai<