Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
フリーマーケットで、売り主の高橋君は N 個の商品を左から順に並べています。 i 番目の商品の値段は A_i 円です。
客の青木君は X 円までなら買ってもよいと考えています。各商品について、値段が X 円以下なら o 、そうでなければ x として、左の商品から順に並べた長さ N の文字列を出力してください。
制約
- 1 \leq N \leq 100
- 1 \leq X \leq 10000
- 1 \leq A_i \leq 10000
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N X A_1 A_2 \ldots A_N
- 1 行目には、商品の個数 N と青木君の予算 X がスペース区切りで与えられる。
- 2 行目には、各商品の値段 A_1, A_2, \ldots, A_N がスペース区切りで与えられる。
出力
長さ N の文字列を 1 行で出力せよ。
入力例 1
5 500 300 800 450 1200 100
出力例 1
oxoxo
入力例 2
3 100 200 300 400
出力例 2
xxx
入力例 3
2 9000 1 8999
出力例 3
oo
入力例 4
1 500 499
出力例 4
o
入力例 5
5 500 300 1 450 1200 100
出力例 5
oooxo
Score : 200 pts
Problem Statement
At a flea market, the seller Takahashi has lined up N items in order from left to right. The price of the i-th item is A_i yen.
Aoki, a customer, is willing to buy an item as long as it costs at most X yen. For each item, let the character be o if its price is at most X yen and x otherwise, and output the string of length N formed by arranging these characters in order from the leftmost item.
Constraints
- 1 \leq N \leq 100
- 1 \leq X \leq 10000
- 1 \leq A_i \leq 10000
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N X A_1 A_2 \ldots A_N
- The first line contains the number of items N and Aoki's budget X, separated by a space.
- The second line contains the prices A_1, A_2, \ldots, A_N of the items, separated by spaces.
Output
Output a string of length N in a single line.
Sample Input 1
5 500 300 800 450 1200 100
Sample Output 1
oxoxo
Sample Input 2
3 100 200 300 400
Sample Output 2
xxx
Sample Input 3
2 9000 1 8999
Sample Output 3
oo
Sample Input 4
1 500 499
Sample Output 4
o
Sample Input 5
5 500 300 1 450 1200 100
Sample Output 5
oooxo
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 233 点
問題文
高橋君は焼き肉屋で N 枚の肉を同時に網に乗せました。 i 枚目の肉は、乗せてから A_i 秒後に焼き上がります。
最初に焼き上がる肉は何枚目かを求めてください。最初に焼き上がる肉が複数ある場合は、そのうち番号が最も小さいものを答えてください。
制約
- 1 \leq N \leq 100
- 1 \leq A_i \leq 1000
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
- 1 行目には、肉の枚数 N が与えられる。
- 2 行目には、各肉が焼き上がるまでの秒数 A_1, A_2, \ldots, A_N がスペース区切りで与えられる。
出力
最初に焼き上がる肉の番号を 1 行で出力せよ。複数ある場合は最も小さい番号を出力せよ。
入力例 1
4 30 10 20 40
出力例 1
2
入力例 2
1 5
出力例 2
1
入力例 3
3 9 8 7
出力例 3
3
入力例 4
7 130 623 701 180 63 216 91
出力例 4
5
入力例 5
8 361 505 856 200 271 262 190 149
出力例 5
8
Score : 233 pts
Problem Statement
Takahashi placed N pieces of meat on the grill at a yakiniku restaurant at the same time. The i-th piece of meat will finish cooking A_i seconds after being placed on the grill.
Find which piece of meat finishes cooking first. If multiple pieces finish first, answer the one with the smallest index.
Constraints
- 1 \leq N \leq 100
- 1 \leq A_i \leq 1000
- All input values are integers.
Input
The input is given from standard input in the following format:
N A_1 A_2 \ldots A_N
- The first line contains the number of pieces of meat N.
- The second line contains the numbers of seconds A_1, A_2, \ldots, A_N until each piece finishes cooking, separated by spaces.
Output
Print the index of the piece of meat that finishes cooking first in one line. If there are multiple such pieces, print the smallest index.
Sample Input 1
4 30 10 20 40
Sample Output 1
2
Sample Input 2
1 5
Sample Output 2
1
Sample Input 3
3 9 8 7
Sample Output 3
3
Sample Input 4
7 130 623 701 180 63 216 91
Sample Output 4
5
Sample Input 5
8 361 505 856 200 271 262 190 149
Sample Output 5
8
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
高橋君は学園祭の実行委員長です。学園祭では K 種類のカテゴリ(飲食、展示、ステージなど)が設定されており、カテゴリは 1 から K までの整数で表されます。
応募された企画は全部で N 個あり、i 番目の企画 (1 \leq i \leq N) はカテゴリ B_i に属し、集客の見込み数 D_i が設定されています。なお、企画が1つも属していないカテゴリが存在することもあります。
高橋君はこの N 個の企画の中からいくつかの企画を選んで採用します(1つも採用しなくてもよい)。ただし、各カテゴリから採用できる企画は最大1つです。すなわち、採用された企画のカテゴリはすべて異なっていなければなりません。
この条件のもとで、採用した企画の集客の見込み数の合計の最大値を求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq K \leq N
- 1 \leq B_i \leq K (1 \leq i \leq N)
- 1 \leq D_i \leq 10^9 (1 \leq i \leq N)
- 入力はすべて整数である。
入力
N K B_1 D_1 B_2 D_2 \vdots B_N D_N
- 1 行目には、企画の個数 N と、カテゴリの種類数 K が、スペース区切りで与えられる。
- 続く N 行の i 行目 (1 \leq i \leq N) には、i 番目の企画のカテゴリ B_i と集客の見込み数 D_i が、スペース区切りで与えられる。
出力
採用した企画の集客の見込み数の合計の最大値を 1 行で出力せよ。
入力例 1
5 3 1 10 2 20 1 30 3 15 2 25
出力例 1
70
入力例 2
4 4 1 100 2 200 3 300 4 400
出力例 2
1000
入力例 3
10 4 1 50 2 30 3 70 4 10 1 80 2 90 3 60 4 40 1 20 3 100
出力例 3
310
入力例 4
20 5 1 1000000000 2 999999999 3 500000000 4 750000000 5 100000000 1 999999998 2 1000000000 3 999999997 4 250000000 5 800000000 1 300000000 2 450000000 3 1000000000 4 1000000000 5 999999999 1 600000000 2 700000000 3 850000000 4 600000000 5 500000000
出力例 4
4999999999
入力例 5
1 1 1 1
出力例 5
1
Score : 300 pts
Problem Statement
Takahashi is the chairperson of the school festival organizing committee. The school festival has K categories (such as food & drink, exhibitions, stage performances, etc.), and each category is represented by an integer from 1 to K.
There are N proposed projects in total. The i-th project (1 \leq i \leq N) belongs to category B_i and has an expected visitor count of D_i. Note that there may be categories to which no project belongs.
Takahashi will select and approve some of these N projects (it is also acceptable to approve none). However, at most one project can be approved from each category. In other words, all approved projects must belong to distinct categories.
Under this condition, find the maximum possible total expected visitor count of the approved projects.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq K \leq N
- 1 \leq B_i \leq K (1 \leq i \leq N)
- 1 \leq D_i \leq 10^9 (1 \leq i \leq N)
- All input values are integers.
Input
N K B_1 D_1 B_2 D_2 \vdots B_N D_N
- The first line contains the number of projects N and the number of categories K, separated by a space.
- The i-th of the following N lines (1 \leq i \leq N) contains the category B_i and the expected visitor count D_i of the i-th project, separated by a space.
Output
Print the maximum possible total expected visitor count of the approved projects in one line.
Sample Input 1
5 3 1 10 2 20 1 30 3 15 2 25
Sample Output 1
70
Sample Input 2
4 4 1 100 2 200 3 300 4 400
Sample Output 2
1000
Sample Input 3
10 4 1 50 2 30 3 70 4 10 1 80 2 90 3 60 4 40 1 20 3 100
Sample Output 3
310
Sample Input 4
20 5 1 1000000000 2 999999999 3 500000000 4 750000000 5 100000000 1 999999998 2 1000000000 3 999999997 4 250000000 5 800000000 1 300000000 2 450000000 3 1000000000 4 1000000000 5 999999999 1 600000000 2 700000000 3 850000000 4 600000000 5 500000000
Sample Output 4
4999999999
Sample Input 5
1 1 1 1
Sample Output 5
1
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 366 点
問題文
高橋君が働く職場では、日々の勤務形態として「シフト A」と「シフト B」の 2 種類があります。
現在、高橋君の今後 N 日間の勤務計画を表す長さ N の文字列 S が与えられます。
S の i 番目の文字(1 \le i \le N)は i 日目の勤務予定を表しており、それぞれ以下の意味を持ちます。
A:シフト A に入ることが確定している。B:シフト B に入ることが確定している。C:シフトが未定である。
高橋君は、S に含まれるすべての C をそれぞれ独立に A または B に置き換えることで、すべての日についてシフト A またはシフト B のどちらかを割り当てようとしています。
この職場では、健康管理の観点からシフト A に 2 日連続で入ることが禁止されているため、置き換え後の文字列において A が 2 つ連続してはなりません(すなわち、置き換え後の文字列が連続部分文字列として AA を含んではいけません)。
条件を満たす置き換え方の総数を 998244353 で割った余りを求めてください。なお、条件を満たす置き換え方が 1 つも存在しない場合は 0 を出力してください。
制約
- 1 \le N \le 2 \times 10^6
- N は整数
- S は
A,B,Cのみからなる長さ N の文字列
入力
入力は標準入力から以下の形式で与えられる。
N S
出力
答えを 998244353 で割った余りを 1 行で出力してください。
入力例 1
4 ACBC
出力例 1
2
入力例 2
5 CBAAC
出力例 2
0
入力例 3
15 CCBACBCBCCABCCC
出力例 3
60
入力例 4
50 CBCCBCACBCBCACBCBCCBCBCBACBCCBCACBCBCACBCBCCBCBCBA
出力例 4
41472
入力例 5
1 C
出力例 5
2
Score : 366 pts
Problem Statement
At Takahashi's workplace, there are two types of daily shifts: Shift A and Shift B.
You are given a string S of length N representing Takahashi's work schedule for the next N days.
The i-th character of S (1 \le i \le N) represents the work schedule for the i-th day, with the following meanings:
A: Confirmed to work Shift A.B: Confirmed to work Shift B.C: The shift is undecided.
Takahashi wants to assign either Shift A or Shift B to each day by independently replacing every C in S with either A or B.
At this workplace, working Shift A on two consecutive days is prohibited for health management reasons. Therefore, there must not be two consecutive A's in the string after replacement (that is, the resulting string must not contain AA as a contiguous substring).
Find the number of valid ways to replace the characters, modulo 998244353. If no valid replacement exists, output 0.
Constraints
- 1 \le N \le 2 \times 10^6
- N is an integer.
- S is a string of length N consisting only of
A,B, andC.
Input
The input is given from Standard Input in the following format:
N S
Output
Print the answer modulo 998244353 in a single line.
Sample Input 1
4 ACBC
Sample Output 1
2
Sample Input 2
5 CBAAC
Sample Output 2
0
Sample Input 3
15 CCBACBCBCCABCCC
Sample Output 3
60
Sample Input 4
50 CBCCBCACBCBCACBCBCCBCBCBACBCCBCACBCBCACBCBCCBCBCBA
Sample Output 4
41472
Sample Input 5
1 C
Sample Output 5
2
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 433 点
問題文
高橋君は、横一列に並んだ N 個の看板を管理しています。左から i 番目の看板には整数 A_i が書かれています。
高橋君は、看板に書かれた整数が左から順に広義単調増加となるように、いくつかの看板の整数を書き換えることにしました。
具体的には、書き換え後の看板の整数を左から順に A'_1, A'_2, \dots, A'_N としたとき、すべての 1 \le i \le N - 1 について以下の条件を満たすようにしたいです。
- A'_i \le A'_{i+1}
高橋君は 1 回の操作で、看板を 1 つ選び、そこに書かれた整数を任意の整数に書き換えることができます。
条件を満たすために必要な操作回数の最小値を求めてください。
制約
- 1 \le N \le 2 \times 10^5
- 1 \le A_i \le 10^9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \dots A_N
- 1 行目には、看板の個数を表す整数 N が与えられる。
- 2 行目には、N 個の看板に書かれた整数を表す A_1, A_2, \dots, A_N がスペース区切りで与えられる。
出力
条件を満たすために必要な操作回数の最小値を 1 行で出力せよ。
入力例 1
5 3 1 4 1 5
出力例 1
2
入力例 2
4 2 3 3 7
出力例 2
0
入力例 3
15 10 40 20 50 30 70 60 90 80 100 1000000000 500 800 999999999 1000000000
出力例 3
5
入力例 4
40 54 12 87 23 91 34 65 18 76 43 99 2 81 59 31 70 45 88 16 62 38 95 27 73 50 84 9 67 41 93 20 78 56 3 89 35 68 47 97 25
出力例 4
30
入力例 5
1 1000000000
出力例 5
0
Score : 433 pts
Problem Statement
Takahashi manages N signboards arranged in a horizontal row. The i-th signboard from the left has an integer A_i written on it.
Takahashi has decided to rewrite the integers on some of the signboards so that the integers written on the signboards are non-decreasing from left to right.
Specifically, letting the integers on the signboards after rewriting be A'_1, A'_2, \dots, A'_N from left to right, he wants to satisfy the following condition for all 1 \le i \le N - 1:
- A'_i \le A'_{i+1}
In one operation, Takahashi can choose one signboard and rewrite the integer written on it to any integer.
Find the minimum number of operations required to satisfy the condition.
Constraints
- 1 \le N \le 2 \times 10^5
- 1 \le A_i \le 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \dots A_N
- The first line contains an integer N, representing the number of signboards.
- The second line contains A_1, A_2, \dots, A_N separated by spaces, representing the integers written on the N signboards.
Output
Print the minimum number of operations required to satisfy the condition in a single line.
Sample Input 1
5 3 1 4 1 5
Sample Output 1
2
Sample Input 2
4 2 3 3 7
Sample Output 2
0
Sample Input 3
15 10 40 20 50 30 70 60 90 80 100 1000000000 500 800 999999999 1000000000
Sample Output 3
5
Sample Input 4
40 54 12 87 23 91 34 65 18 76 43 99 2 81 59 31 70 45 88 16 62 38 95 27 73 50 84 9 67 41 93 20 78 56 3 89 35 68 47 97 25
Sample Output 4
30
Sample Input 5
1 1000000000
Sample Output 5
0