跳到正文

个人记录

atcoder 418 题目

18031636603slf约 11 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年3月18日
篇幅
约 11 分钟

版本

  1. v1当前

A - I’m a teapot / Time Limit: 2 sec / Memory Limit: 1024 MiB

× It is prohibited to use generative AI in ongoing AtCoder contests. Please refer to the following rules for more details.

AtCoder Rules against Generative AI - Version 20250718

Score : 100 points

Problem Statement Takahashi is a teapot. Since he is a teapot, he will gladly accept tea, but will refuse any other liquid. Determine whether you can pour a liquid named S into him.

You are given a string S of length N consisting of lowercase English letters. Determine whether S is a string that ends with tea.

Constraints 1≤N≤20 N is an integer. S is a string of length N consisting of lowercase English letters. Input The input is given from Standard Input in the following format:

N S Output If S is a string that ends with tea, print Yes; otherwise, print No.

Sample Input 1

8 greentea Sample Output 1

Yes greentea is a string that ends with tea.

Sample Input 2

6 coffee Sample Output 2

No coffee is not a string that ends with tea.

Sample Input 3 3 tea Sample Output 3

Yes Sample Input 4

1 t Sample Output 4

No

B - You’re a teapot / Time Limit: 2 sec / Memory Limit: 1024 MiB

× It is prohibited to use generative AI in ongoing AtCoder contests. Please refer to the following rules for more details.

AtCoder Rules against Generative AI - Version 20250718

Score : 200 points

Problem Statement I begin with T and end with T, and I am full of T. What am I?

For a string t, define the filling rate as follows:

If the first and last characters of t are both t and ∣t∣≥3: Let x be the number of t in t. Then the filling rate of t is ∣t∣−2 x−2 ​ , where ∣t∣ denotes the length of t. Otherwise: the filling rate of t is 0. You are given a string S. Find the maximum possible filling rate of a substring of S.

What is a substring? Constraints 1≤∣S∣≤100 S is a string consisting of lowercase English letters. Input The input is given from Standard Input in the following format:

S Output Print the maximum possible filling rate of a substring of S.

Your output will be judged as correct when the absolute error from the true value is at most 10 −9 .

Sample Input 1 Copy attitude Sample Output 1 Copy 0.50000000000000000 ttit is a substring of S, and its filling rate is 4−2 3−2 ​

2 1 ​ .

There is no substring with a filling rate greater than 2 1 ​ , so the answer is 2 1 ​ .

Sample Input 2 Copy ottottott Sample Output 2 Copy 0.66666666666666667 ttottott is a substring of S, and its filling rate is 8−2 6−2 ​

3 2 ​ .

There is no substring with a filling rate greater than 3 2 ​ , so the answer is 3 2 ​ .

Sample Input 3 Copy coffeecup Sample Output 3 Copy 0.00000000000000000 ff is a substring of S, and its filling rate is 0.

There is no substring with a filling rate greater than 0, so the answer is 0.

C - Flush / Time Limit: 2 sec / Memory Limit: 1024 MiB

× It is prohibited to use generative AI in ongoing AtCoder contests. Please refer to the following rules for more details.

AtCoder Rules against Generative AI - Version 20250718

Score : 350 points

Problem Statement On the poker table, there are tea bags of N different flavors. The flavors are numbered from 1 through N, and there are A i ​ tea bags of flavor i ( 1≤i≤N).

You will play a game using these tea bags. The game has a parameter called difficulty between 1 and A 1 ​ +⋯+A N ​ , inclusive. A game of difficulty b proceeds as follows:

You declare an integer x. Here, it must satisfy b≤x≤A 1 ​ +⋯+A N ​ . The dealer chooses exactly x tea bags from among those on the table and gives them to you. You check the flavors of the x tea bags you received, and choose b tea bags from them. If all b tea bags you chose are of the same flavor, you win. Otherwise, you lose. The dealer will do their best to make you lose.

You are given Q queries, so answer each of them. The j-th query is as follows:

For a game of difficulty B j ​ , report the minimum integer x you must declare at the start to guarantee a win. If it is impossible to win, report −1 instead. Constraints 1≤N≤3×10 5

1≤Q≤3×10 5

1≤A i ​ ≤10 6 ( 1≤i≤N) 1≤B j ​ ≤min(10 6 ,A 1 ​ +⋯+A N ​ ) ( 1≤j≤Q) All input values are integers. Input The input is given from Standard Input in the following format:

N Q A 1 ​

⋯ A N ​

B 1 ​

⋮ B Q ​

Output Print Q lines.

The j-th line ( 1≤j≤Q) should contain the answer to the j-th query.

Sample Input 1 Copy 4 5 4 1 8 4 1 8 5 2 10 Sample Output 1 Copy 1 17 14 5 -1 For the 1-st query, if you declare x=1, then no matter which 1 bag the dealer chooses, you can satisfy the winning condition by choosing appropriate 1 bag among them. Since you cannot choose an integer x less than 1, the answer is 1.

For the 2-nd query, if you declare x=17, then no matter which 17 bags the dealer chooses, you can satisfy the winning condition by choosing appropriate 8 bags among them. Conversely, if x<17, the dealer can choose bags to prevent your victory. Thus, the answer is 17.

For the 3-nd query, if you declare x=14, then no matter which 14 bags the dealer chooses, you can satisfy the winning condition by choosing appropriate 5 bags among them. Conversely, if x<14, the dealer can choose bags to prevent your victory. Thus, the answer is 14.

For the 4-th query, if you declare x=5, then no matter which 5 bags the dealer chooses, you can satisfy the winning condition by choosing appropriate 2 bags among them. Conversely, if x<5, the dealer can choose bags to prevent your victory. Thus, the answer is 5.

For the 5-th query, no matter what x you declare, the dealer can choose bags to prevent your victory. Thus, print −1.

Sample Input 2 Copy 5 3 13 13 13 13 2 5 12 13 Sample Output 2 Copy 19 47 51

原文