A - Takahashi san

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

キーエンスでは、役割や年齢、立場の違いに関係なく「さん」付けして呼ぶという文化があります。 新入社員が社長を呼ぶときも「中田さん」と呼びます。

ある人の苗字と名前がそれぞれ文字列 S,T として与えられます。

苗字、スペース( )、敬称(san)をこの順に連結した文字列を出力してください。

制約

  • S,T は以下の各条件を満たす文字列
    • 長さ 1 以上 10 以下
    • 先頭の文字は英大文字
    • 先頭以外の文字は英小文字

入力

入力は以下の形式で標準入力から与えられる。

S T

出力

苗字、スペース( )、敬称(san)をこの順に連結した文字列を出力せよ。


入力例 1

Takahashi Chokudai

出力例 1

Takahashi san

苗字(Takahashi)、スペース( )、敬称(san)をこの順に連結した文字列を出力します。


入力例 2

K Eyence

出力例 2

K san

Score : 100 points

Problem Statement

Keyence has a culture of addressing everyone with the honorific "san," regardless of their role, age, or position. Even a new employee would call the president "Nakata-san." [Translator's note: this is a bit unusual in Japan.]

You are given a person's surname and first name as strings S and T, respectively.

Print the concatenation of the surname, a space ( ), and the honorific (san) in this order.

Constraints

  • Each of S and T is a string that satisfies the following conditions.
    • The length is between 1 and 10, inclusive.
    • The first character is an uppercase English letter.
    • All characters except the first one are lowercase English letters.

Input

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

S T

Output

Print the concatenation of the surname, a space ( ), and the honorific (san) in this order.


Sample Input 1

Takahashi Chokudai

Sample Output 1

Takahashi san

Print the concatenation of the surname (Takahashi), a space ( ), and the honorific (san) in this order.


Sample Input 2

K Eyence

Sample Output 2

K san
B - World Meeting

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 250

問題文

キーエンスには世界各地に N 個の拠点があり、1 から N までの番号が付けられています。 拠点 i には W_i 人の社員が所属しており、世界標準時で 0 時のとき拠点 iX_i 時です。

あなたはキーエンス全社で 1 時間の会議を開きたいです。 各社員は、会議の開催時間帯が所属する拠点における 9:00-18:00 の時間帯に完全に含まれる場合にのみ会議に参加できます。 なるべく多くの社員が参加できるように会議の開催時間帯を決めるとき、会議に参加できる社員の数の最大値を求めてください。

制約

  • 1\leq N \leq 1000
  • 1\leq W_i \leq 10^6
  • 0\leq X_i < 24
  • 入力は全て整数

入力

入力は以下の形式で標準入力から与えられる。

N
W_1 X_1
W_2 X_2
\vdots
W_N X_N

出力

会議に参加できる社員の数の最大値を出力せよ。


入力例 1

3
5 0
3 3
2 18

出力例 1

8

世界標準時で 14:00-15:00 の時間帯に会議を開催することを考えます。

  • 拠点 1 における 14:00-15:00 の時間帯に会議が開催されるため、拠点 1 に所属する 5 人の社員は会議に参加できます。
  • 拠点 2 における 17:00-18:00 の時間帯に会議が開催されるため、拠点 2 に所属する 3 人の社員は会議に参加できます。
  • 拠点 3 における 8:00-9:00 の時間帯に会議が開催されるため、拠点 3 に所属する 2 人の社員は会議に参加できません。

よって、合計で 5+3=8 人の社員が会議に参加できます。 これより多くの社員が参加できるような会議の開催時間帯はありません。


入力例 2

2
1 10
1000000 20

出力例 2

1000000

入力例 3

6
31 3
20 8
11 5
4 3
47 14
1 18

出力例 3

67

Score : 250 points

Problem Statement

Keyence has N bases worldwide, numbered 1 to N. Base i has W_i employees, and at 0 o'clock in Coordinated Universal Time (UTC), it is X_i o'clock at base i.

You want to hold a one-hour meeting across the entire company. Each employee can only participate in the meeting if the meeting time is completely within the 9:00-18:00 time slot at their base. Find the maximum number of employees who can participate when deciding the meeting time to allow as many employees as possible to participate.

Constraints

  • 1\leq N \leq 1000
  • 1\leq W_i \leq 10^6
  • 0\leq X_i < 24
  • All input values are integers.

Input

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

N
W_1 X_1
W_2 X_2
\vdots
W_N X_N

Output

Print the maximum number of employees who can participate in the meeting.


Sample Input 1

3
5 0
3 3
2 18

Sample Output 1

8

Consider holding the meeting from 14:00 to 15:00 in UTC.

  • The meeting is held from 14:00 to 15:00 at base 1, so the 5 employees at base 1 can participate in the meeting.
  • The meeting is held from 17:00 to 18:00 at base 2, so the 3 employees at base 2 can participate in the meeting.
  • The meeting is held from 8:00 to 9:00 at base 3, so the 2 employees at base 3 cannot participate in the meeting.

Thus, a total of 5+3=8 employees can participate in the meeting. No meeting time allows more employees to participate.


Sample Input 2

2
1 10
1000000 20

Sample Output 2

1000000

Sample Input 3

6
31 3
20 8
11 5
4 3
47 14
1 18

Sample Output 3

67
C - Sensors

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300

問題文

HW 列のマス目の上に 0 個以上のセンサが配置されています。上から i 行目、左から j 列目のマス目を (i, j) と表記します。
センサが配置されているマス目の情報は長さ W の文字列 S_1, S_2, \ldots, S_H によって与えられ、S_ij 文字目が # のとき、またそのときに限り (i, j) にセンサが配置されています。
このセンサは上下左右斜めに隣接しているマス目に存在する他のセンサと連動し、一つのセンサとして動作します。 ただし、マス目 (x, y)(x', y') が上下左右斜めに隣接しているとは、\max(|x-x'|,|y-y'|) = 1 であることを指します。
また、センサ A とセンサ B が連動し、センサ A とセンサ C が連動しているとき、センサ B とセンサ C も連動することに注意してください。

連動するセンサを一つのセンサと見なしたとき、このマス目の上にあるセンサの個数を求めてください。

制約

  • 1 \leq H, W \leq 1000
  • H, W は整数
  • S_i は各文字が # または . である長さ W の文字列

入力

入力は以下の形式で標準入力から与えられる。

H W
S_1
S_2
\vdots
S_H

出力

答えを出力せよ。


入力例 1

5 6
.##...
...#..
....##
#.#...
..#...

出力例 1

3

連動しているセンサを一つのセンサと見なしたとき、

  • (1,2),(1,3),(2,4),(3,5),(3,6) にあるセンサが連動したもの
  • (4,1) にあるセンサ
  • (4,3),(5,3) にあるセンサが連動したもの

3 つのセンサが存在します。


入力例 2

3 3
#.#
.#.
#.#

出力例 2

1

入力例 3

4 2
..
..
..
..

出力例 3

0

入力例 4

5 47
.#..#..#####..#...#..#####..#...#...###...#####
.#.#...#.......#.#...#......##..#..#...#..#....
.##....#####....#....#####..#.#.#..#......#####
.#.#...#........#....#......#..##..#...#..#....
.#..#..#####....#....#####..#...#...###...#####

出力例 4

7

Score : 300 points

Problem Statement

There are zero or more sensors placed on a grid of H rows and W columns. Let (i, j) denote the square in the i-th row from the top and the j-th column from the left.
Whether each square contains a sensor is given by the strings S_1, S_2, \ldots, S_H, each of length W. (i, j) contains a sensor if and only if the j-th character of S_i is #.
These sensors interact with other sensors in the squares horizontally, vertically, or diagonally adjacent to them and operate as one sensor. Here, a cell (x, y) and a cell (x', y') are said to be horizontally, vertically, or diagonally adjacent if and only if \max(|x-x'|,|y-y'|) = 1.
Note that if sensor A interacts with sensor B and sensor A interacts with sensor C, then sensor B and sensor C also interact.

Considering the interacting sensors as one sensor, find the number of sensors on this grid.

Constraints

  • 1 \leq H, W \leq 1000
  • H and W are integers.
  • S_i is a string of length W where each character is # or ..

Input

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

H W
S_1
S_2
\vdots
S_H

Output

Print the answer.


Sample Input 1

5 6
.##...
...#..
....##
#.#...
..#...

Sample Output 1

3

When considering the interacting sensors as one sensor, the following three sensors exist:

  • The interacting sensors at (1,2),(1,3),(2,4),(3,5),(3,6)
  • The sensor at (4,1)
  • The interacting sensors at (4,3),(5,3)

Sample Input 2

3 3
#.#
.#.
#.#

Sample Output 2

1

Sample Input 3

4 2
..
..
..
..

Sample Output 3

0

Sample Input 4

5 47
.#..#..#####..#...#..#####..#...#...###...#####
.#.#...#.......#.#...#......##..#..#...#..#....
.##....#####....#....#####..#.#.#..#......#####
.#.#...#........#....#......#..##..#...#..#....
.#..#..#####....#....#####..#...#...###...#####

Sample Output 4

7
D - Printing Machine

Time Limit: 3 sec / Memory Limit: 1024 MB

配点 : 450

問題文

1 から N までの番号が付けられた N 個の商品がベルトコンベア上を流れています。 ベルトコンベアには印字機が取り付けられており、商品 i は今から T_i [μs] 後に印字機の範囲に入り、その D_i [μs] 後に印字機の範囲から出ます。

キーエンスの印字機は、印字機の範囲内にある商品 1 つに一瞬で印字することができます(特に、商品が印字機の範囲に入る瞬間や範囲から出る瞬間に印字することも可能です)。 ただし、1 度印字すると、次に印字するまでに 1 [μs] のチャージ時間が必要です。 印字機が印字をする商品とタイミングをうまく選んだとき、最大で何個の商品に印字することができますか?

制約

  • 1\leq N \leq 2\times 10^5
  • 1\leq T_i,D_i \leq 10^{18}
  • 入力は全て整数

入力

入力は以下の形式で標準入力から与えられる。

N
T_1 D_1
T_2 D_2
\vdots
T_N D_N

出力

印字機が印字することのできる商品の数の最大値を出力せよ。


入力例 1

5
1 1
1 1
2 1
1 2
1 4

出力例 1

4

以下、今から t [μs] 後のことを単に時刻 t とよびます。

例えば、次のようにして 4 個の商品に印字することができます。

  • 時刻 1 : 商品 1,2,4,5 が印字機の範囲に入る。商品 4 に印字する。
  • 時刻 2 : 商品 3 が印字機の範囲に入り、商品 1,2 が印字機の範囲から出る。商品 1 に印字する。
  • 時刻 3 : 商品 3,4 が印字機の範囲から出る。商品 3 に印字する。
  • 時刻 4.5 : 商品 5 に印字する。
  • 時刻 5 : 商品 5 が印字機の範囲から出る。

5 個の商品すべてに印字することはできないため、答えは 4 です。


入力例 2

2
1 1
1000000000000000000 1000000000000000000

出力例 2

2

入力例 3

10
4 1
1 2
1 4
3 2
5 1
5 1
4 1
2 1
4 1
2 4

出力例 3

6

Score : 450 points

Problem Statement

There are N products labeled 1 to N flowing on a conveyor belt. A Keyence printer is attached to the conveyor belt, and product i enters the range of the printer T_i microseconds from now and leaves it D_i microseconds later.

The Keyence printer can instantly print on one product within the range of the printer (in particular, it is possible to print at the moment the product enters or leaves the range of the printer). However, after printing once, it requires a charge time of 1 microseconds before it can print again. What is the maximum number of products the printer can print on when the product and timing for the printer to print are chosen optimally?

Constraints

  • 1\leq N \leq 2\times 10^5
  • 1\leq T_i,D_i \leq 10^{18}
  • All input values are integers.

Input

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

N
T_1 D_1
T_2 D_2
\vdots
T_N D_N

Output

Print the maximum number of products the printer can print on.


Sample Input 1

5
1 1
1 1
2 1
1 2
1 4

Sample Output 1

4

Below, we will simply call the moment t microseconds from now time t.

For example, you can print on four products as follows:

  • Time 1 : Products 1,2,4,5 enter the range of the printer. Print on product 4.
  • Time 2 : Product 3 enters the range of the printer, and products 1,2 leave the range of the printer. Print on product 1.
  • Time 3 : Products 3,4 leave the range of the printer. Print on product 3.
  • Time 4.5 : Print on product 5.
  • Time 5 : Product 5 leaves the range of the printer.

It is impossible to print on all five products, so the answer is 4.


Sample Input 2

2
1 1
1000000000000000000 1000000000000000000

Sample Output 2

2

Sample Input 3

10
4 1
1 2
1 4
3 2
5 1
5 1
4 1
2 1
4 1
2 4

Sample Output 3

6
E - Our clients, please wait a moment

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 450

問題文

ある国には都市が N 個あります。
あなたは、都市 1 にある営業所から 0 個以上の都市を経由して都市 N にある訪問先へ移動しようとしています。
移動手段は社用車と電車の 2 種類があります。都市 i から都市 j へ移動するときの所要時間は以下の通りです。

  • 社用車を使った場合 : D_{i,j} \times A
  • 電車を使った場合 : D_{i,j} \times B + C

ただし、社用車から電車に乗り換えることはできますが、電車から社用車に乗り換えることはできません。
また、乗り換えは各都市のみで行え、乗り換えに時間はかかりません。

都市 1 から都市 N に移動するのにかかる時間は最短で何分ですか?

制約

  • 2 \leq N \leq 1000
  • 1 \leq A, B, C \leq 10^6
  • D_{i,j} \leq 10^6
  • D_{i,i} = 0
  • D_{i,j} = D_{j,i} > 0 (i \neq j)
  • 入力される数値はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

N A B C
D_{1,1} D_{1,2} \ldots D_{1,N}
D_{2,1} D_{2,2} \ldots D_{2,N}
\vdots
D_{N,1} D_{N,2} \ldots D_{N,N}

出力

答えを整数として出力せよ。


入力例 1

4 8 5 13
0 6 2 15
6 0 3 5
2 3 0 13
15 5 13 0

出力例 1

78

以下のように移動することで合計 78 分で都市 1 から都市 4 に移動することができます。

  • 都市 1 から都市 3 まで社用車で移動する。この移動には 2 \times 8 = 16 分かかる。
  • 都市 3 から都市 2 まで社用車で移動する。この移動には 3 \times 8 = 24 分かかる。
  • 都市 2 から都市 4 まで電車で移動する。この移動には 5 \times 5 + 13 = 38 分かかる。

78 分未満の時間で都市 1 から都市 4 に移動することはできません。


入力例 2

3 1 1000000 1000000
0 10 1
10 0 10
1 10 0

出力例 2

1

入力例 3

5 954257 954213 814214
0 84251 214529 10017 373342
84251 0 91926 32336 164457
214529 91926 0 108914 57762
10017 32336 108914 0 234705
373342 164457 57762 234705 0

出力例 3

168604826785

Score : 450 points

Problem Statement

There are N cities in a certain country.
You will travel from your office in city 1 to a destination in city N, via zero or more cities.
Two types of transportation are available: company car and train. The time required to travel from city i to city j is as follows:

  • D_{i,j} \times A minutes by company car, and
  • D_{i,j} \times B + C minutes by train.

You can switch from company car to train, but not vice versa.
You can do so without spending time, but only in a city.

What is the minimum time in minutes to travel from city 1 to city N?

Constraints

  • 2 \leq N \leq 1000
  • 1 \leq A, B, C \leq 10^6
  • D_{i,j} \leq 10^6
  • D_{i,i} = 0
  • D_{i,j} = D_{j,i} > 0 (i \neq j)
  • All input values are integers.

Input

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

N A B C
D_{1,1} D_{1,2} \ldots D_{1,N}
D_{2,1} D_{2,2} \ldots D_{2,N}
\vdots
D_{N,1} D_{N,2} \ldots D_{N,N}

Output

Print the answer as an integer.


Sample Input 1

4 8 5 13
0 6 2 15
6 0 3 5
2 3 0 13
15 5 13 0

Sample Output 1

78

You can travel from city 1 to city 4 in a total of 78 minutes by moving as follows.

  • Travel by company car from city 1 to city 3. This takes 2 \times 8 = 16 minutes.
  • Travel by company car from city 3 to city 2. This takes 3 \times 8 = 24 minutes.
  • Travel by train from city 2 to city 4. This takes 5 \times 5 + 13 = 38 minutes.

It is impossible to travel from city 1 to city 4 in less than 78 minutes.


Sample Input 2

3 1 1000000 1000000
0 10 1
10 0 10
1 10 0

Sample Output 2

1

Sample Input 3

5 954257 954213 814214
0 84251 214529 10017 373342
84251 0 91926 32336 164457
214529 91926 0 108914 57762
10017 32336 108914 0 234705
373342 164457 57762 234705 0

Sample Output 3

168604826785
F - Sensor Optimization Dilemma

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

キーエンスの工場長であるあなたは、ベルトコンベア上のいくつかの区間をセンサーによって監視したいと考えています。 あなたが監視したい区間は全部で N 個あり、i 個目の区間の長さは D_i メートルです。

センサーには 2 種類の候補があり、それぞれのセンサーに関する情報は以下の通りです。

  • センサー j\ (1\leq j \leq 2) : 長さ L_j メートルの区間を監視できる。 価格は 1 個あたり C_j であり、全体で最大 K_j 個まで使用することができる。

1 つの区間をいくつかの区間に分割して監視することもできます。 また、センサーが監視する区間が重なっていたり、監視したい区間の長さより余分に監視していたりしても問題はありません。 例えば、L_1=4,L_2=2 であるとき、センサー 11 つ使って長さ 3 メートルの区間を監視したり、センサー 1,21 つずつ使って長さ 5 メートルの区間を監視したりすることが可能です。

N 個の区画をすべて監視することが可能であるか判定し、可能ならば必要なセンサーの価格の総和の最小値を求めてください。

制約

  • 1\leq N \leq 100
  • 1\leq D_i,L_j \leq 10^5
  • 1\leq C_j \leq 10^9
  • 1\leq K_j \leq 10^3
  • 入力は全て整数

入力

入力は以下の形式で標準入力から与えられる。

N
D_1 D_2 \dots D_N
L_1 C_1 K_1
L_2 C_2 K_2

出力

N 個の区画をすべて監視することが不可能ならば -1 を、可能ならば必要なセンサーの価格の総和の最小値を出力せよ。


入力例 1

3
3 5 10
4 3 3
2 2 6

出力例 1

17

以下のようにすることで、センサー 13 つ、センサー 24 つ使ってすべての区間を監視できます。

  • センサー 11 つ使って 1 個目の区間を監視する。
  • センサー 1,21 つずつ使って 2 個目の区間を監視する。
  • センサー 11 つ、センサー 23 つ使って 3 個目の区間を監視する。

このとき、必要なセンサーの価格の総和は 3\times 3 + 2\times 4 = 17 であり、これが最小です。


入力例 2

3
3 5 10
4 3 3
2 2 3

出力例 2

-1

入力例 3

2
4 8
3 1 100
4 10000 100

出力例 3

5

1 つも使わない種類のセンサーがあっても構いません。

Score : 500 points

Problem Statement

As the factory manager of Keyence, you want to monitor several sections on a conveyor belt. There are a total of N sections you want to monitor, and the length of the i-th section is D_i meters.

There are two types of sensors to choose from, and below is some information about each sensor.

  • Type-j sensor (1\leq j \leq 2): Can monitor a section of length L_j meters. The price is C_j per sensor, and you can use at most K_j sensors of this type in total.

You can divide one section into several sections for monitoring. It is fine if the sections monitored by the sensors overlap, or if they monitor more than the length of the section you want to monitor. For example, when L_1=4 and L_2=2, you can use one type-1 sensor to monitor a section of length 3 meters, or use one type-1 and one type-2 sensor to monitor a section of length 5 meters.

Determine whether it is possible to monitor all N sections, and if it is possible, find the minimum total cost of the necessary sensors.

Constraints

  • 1\leq N \leq 100
  • 1\leq D_i,L_j \leq 10^5
  • 1\leq C_j \leq 10^9
  • 1\leq K_j \leq 10^3
  • All input values are integers.

Input

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

N
D_1 D_2 \dots D_N
L_1 C_1 K_1
L_2 C_2 K_2

Output

If it is impossible to monitor all N sections, print -1. Otherwise, print the minimum total cost of the necessary sensors.


Sample Input 1

3
3 5 10
4 3 3
2 2 6

Sample Output 1

17

You can monitor all sections by using three type-1 sensors and four type-2 sensors as follows.

  • Use one type-1 sensor to monitor the first section.
  • Use one type-1 and one type-2 sensor to monitor the second section.
  • Use one type-1 and three type-2 sensors to monitor the third section.

In this case, the total cost of the necessary sensors is 3\times 3 + 2\times 4 = 17, which is the minimum.


Sample Input 2

3
3 5 10
4 3 3
2 2 3

Sample Output 2

-1

Sample Input 3

2
4 8
3 1 100
4 10000 100

Sample Output 3

5

It is fine if one type of sensor is not used at all.

G - offence

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 575

問題文

文字列 S が与えられます。文字列 S に対して以下の操作を 0 回以上繰り返し行うことで得られる文字列の長さの最小値を求めてください。

  • 文字列の中で of が連続する箇所および 0 以上 K 以下の整数 i1 つ選ぶ。その後、of およびその後ろに連続する i 文字を文字列から取り除く。

制約

  • 0 \leq K < |S| \leq 300
  • K は整数
  • S は英小文字からなる文字列

入力

入力は以下の形式で標準入力から与えられる。

S
K

出力

答えを出力せよ。


入力例 1

keyofscience
3

出力例 1

7

4, 5 文字目に連続する of を選び、i = 3 とすることで keyofscience から ofsci を取り除き、 keyence を得ます。
操作の繰り返しにより文字列の長さを 6 以下にすることはできないため、7 が答えとなります。


入力例 2

oofsifffence
3

出力例 2

2

入力例 3

ooofff
5

出力例 3

0

入力例 4

okeyencef
4

出力例 4

9

Score : 575 points

Problem Statement

You are given a string S. Find the minimum length of a string that can be obtained by performing the following operation on the string S zero or more times.

  • Choose a contiguous occurrence of of in the string and an integer i between 0 and K, inclusive. Then, remove the of and the following i characters from the string.

Constraints

  • 0 \leq K < |S| \leq 300
  • K is an integer.
  • S is a string consisting of lowercase English letters.

Input

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

S
K

Output

Print the answer.


Sample Input 1

keyofscience
3

Sample Output 1

7

By choosing the of formed by the fourth and fifth characters and setting i = 3, you can remove ofsci from keyofscience and get keyence.
It is impossible to reduce the length of the string to 6 or less by repeating the operation, so the answer is 7.


Sample Input 2

oofsifffence
3

Sample Output 2

2

Sample Input 3

ooofff
5

Sample Output 3

0

Sample Input 4

okeyencef
4

Sample Output 4

9