Time Limit: 2 sec / Memory Limit: 256 MB
配点 : 100 点
問題文
イルカは、新年に長さ 19 の文字列 s を受け取りました。
文字列 s の形式は [英小文字 5 文字],[英小文字 7 文字],[英小文字 5 文字]
で表されます。
イルカは、カンマで区切られた文字列 s を、スペースで区切られた文字列に変換したいと思っています。
イルカの代わりに、この処理を行うプログラムを作ってください。
制約
- s の長さは 19 である。
- s の 6 文字目と 14 文字目は
,
である。 - それら以外の s の文字は英小文字である。
入力
入力は以下の形式で標準入力から与えられる。
s
出力
処理した後の文字列を出力せよ。
入力例 1
happy,newyear,enjoy
出力例 1
happy newyear enjoy
happy,newyear,enjoy
に含まれるカンマをスペースで置き換えて、happy newyear enjoy
を出力します。
入力例 2
haiku,atcoder,tasks
出力例 2
haiku atcoder tasks
入力例 3
abcde,fghihgf,edcba
出力例 3
abcde fghihgf edcba
Score : 100 points
Problem Statement
As a New Year's gift, Dolphin received a string s of length 19.
The string s has the following format: [five lowercase English letters],[seven lowercase English letters],[five lowercase English letters]
.
Dolphin wants to convert the comma-separated string s into a space-separated string.
Write a program to perform the conversion for him.
Constraints
- The length of s is 19.
- The sixth and fourteenth characters in s are
,
. - The other characters in s are lowercase English letters.
Input
The input is given from Standard Input in the following format:
s
Output
Print the string after the conversion.
Sample Input 1
happy,newyear,enjoy
Sample Output 1
happy newyear enjoy
Replace all the commas in happy,newyear,enjoy
with spaces to obtain happy newyear enjoy
.
Sample Input 2
haiku,atcoder,tasks
Sample Output 2
haiku atcoder tasks
Sample Input 3
abcde,fghihgf,edcba
Sample Output 3
abcde fghihgf edcba
Time Limit: 2 sec / Memory Limit: 256 MB
Score : 200 points
Problem Statement
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
Constraints
- 2≤K≤2500
- 0≤S≤3K
- K and S are integers.
Input
The input is given from Standard Input in the following format:
K S
Output
Print the number of the triples of X, Y and Z that satisfy the condition.
Sample Input 1
2 2
Sample Output 1
6
There are six triples of X, Y and Z that satisfy the condition:
- X = 0, Y = 0, Z = 2
- X = 0, Y = 2, Z = 0
- X = 2, Y = 0, Z = 0
- X = 0, Y = 1, Z = 1
- X = 1, Y = 0, Z = 1
- X = 1, Y = 1, Z = 0
Sample Input 2
5 15
Sample Output 2
1
The maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z.
配点 : 200 点
問題文
2 つの整数 K,S が与えられます。
3 つの変数 X,Y,Z があり、0≦X,Y,Z≦K を満たす整数の値を取ります。
X + Y + Z = S を満たす X,Y,Z への値の割り当ては何通りありますか。
制約
- 2≦K≦2500
- 0≦S≦3K
- K,S は整数である。
入力
入力は以下の形式で標準入力から与えられる。
K S
出力
問題文の条件を満たす X,Y,Z の組が何通りあるか出力せよ。
入力例 1
2 2
出力例 1
6
問題文の条件を満たす X,Y,Z の組は以下の 6 通りです。
- X = 0, Y = 0, Z = 2
- X = 0, Y = 2, Z = 0
- X = 2, Y = 0, Z = 0
- X = 0, Y = 1, Z = 1
- X = 1, Y = 0, Z = 1
- X = 1, Y = 1, Z = 0
入力例 2
5 15
出力例 2
1
X + Y + Z の最大値は 15 であり、それを満たす組は 1 通りです。
Time Limit: 2 sec / Memory Limit: 256 MB
配点 : 300 点
問題文
イルカは x 軸正方向を右、y 軸正方向を上とする 2 次元座標平面にいます。
イルカは現在点 (sx,sy) にいて、1 秒あたり上下左右に距離 1 だけ進むことができます。
このとき、移動前と移動後の x 座標、y 座標はともに整数でなければなりません。
イルカはここから sx < tx と sy < ty を満たす点 (tx,ty) に行き、その後点 (sx,sy) に戻り、また点 (tx,ty) に行き、その後点 (sx,sy) に戻ります。
このとき、イルカは点 (sx,sy) と点 (tx,ty) を除いて、途中で同じ座標を複数回通らないように移動しなければなりません。
このような条件を満たすイルカの最短経路を 1 つ求めてください。
制約
- -1000≦ sx < tx ≦1000
- -1000≦ sy < ty ≦1000
- sx,sy,tx,ty は整数である。
入力
入力は以下の形式で標準入力から与えられる。
sx sy tx ty
出力
イルカの最短経路を表す文字列 S を出力せよ。
S の i 番目の文字はイルカの i 番目の移動を表す。
イルカの各方向への移動を表す文字の対応関係は以下のとおりである。
U
: 上方向D
: 下方向L
: 左方向R
: 右方向
条件を満たすような最短経路が複数ある場合、そのうちどれか 1 つを出力せよ。
入力例 1
0 0 1 2
出力例 1
UURDDLLUUURRDRDDDLLU
以下に示す移動経路が最短経路の 1 つです。
- 1 回目の (sx,sy) から (tx,ty) への移動: (0,0) → (0,1) → (0,2) → (1,2)
- 1 回目の (tx,ty) から (sx,sy) への移動: (1,2) → (1,1) → (1,0) → (0,0)
- 2 回目の (sx,sy) から (tx,ty) への移動: (0,0) → (-1,0) → (-1,1) → (-1,2) → (-1,3) → (0,3) → (1,3) → (1,2)
- 2 回目の (tx,ty) から (sx,sy) への移動: (1,2) → (2,2) → (2,1) → (2,0) → (2,-1) → (1,-1) → (0,-1) → (0,0)
入力例 2
-2 -2 1 1
出力例 2
UURRURRDDDLLDLLULUUURRURRDDDLLDL
Score : 300 points
Problem Statement
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.
Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.
Here, both the x- and y-coordinates before and after each movement must be integers.
He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).
Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).
Under this condition, find a shortest path for him.
Constraints
- -1000 ≤ sx < tx ≤ 1000
- -1000 ≤ sy < ty ≤ 1000
- sx,sy,tx and ty are integers.
Input
The input is given from Standard Input in the following format:
sx sy tx ty
Output
Print a string S that represents a shortest path for Dolphin.
The i-th character in S should correspond to his i-th movement.
The directions of the movements should be indicated by the following characters:
U
: UpD
: DownL
: LeftR
: Right
If there exist multiple shortest paths under the condition, print any of them.
Sample Input 1
0 0 1 2
Sample Output 1
UURDDLLUUURRDRDDDLLU
One possible shortest path is:
- Going from (sx,sy) to (tx,ty) for the first time: (0,0) → (0,1) → (0,2) → (1,2)
- Going from (tx,ty) to (sx,sy) for the first time: (1,2) → (1,1) → (1,0) → (0,0)
- Going from (sx,sy) to (tx,ty) for the second time: (0,0) → (-1,0) → (-1,1) → (-1,2) → (-1,3) → (0,3) → (1,3) → (1,2)
- Going from (tx,ty) to (sx,sy) for the second time: (1,2) → (2,2) → (2,1) → (2,0) → (2,-1) → (1,-1) → (0,-1) → (0,0)
Sample Input 2
-2 -2 1 1
Sample Output 2
UURRURRDDDLLDLLULUUURRURRDDDLLDL
Time Limit: 2 sec / Memory Limit: 256 MB
配点 : 400 点
問題文
自己ループと二重辺を含まない N 頂点 M 辺の重み付き無向連結グラフが与えられます。
i (1≦i≦M) 番目の辺は頂点 a_i と頂点 b_i を距離 c_i で結びます。
ここで、自己ループは a_i = b_i (1≦i≦M) となる辺のことを表します。
また、二重辺は (a_i,b_i)=(a_j,b_j) または (a_i,b_i)=(b_j,a_j) (1≦i<j≦M) となる辺のことを表します。
連結グラフは、どの異なる 2 頂点間にも経路が存在するグラフのことを表します。
どの異なる 2 頂点間の、どの最短経路にも含まれない辺の数を求めてください。
制約
- 2≦N≦100
- N-1≦M≦min(N(N-1)/2,1000)
- 1≦a_i,b_i≦N
- 1≦c_i≦1000
- c_i は整数である。
- 与えられるグラフは自己ループと二重辺を含まない。
- 与えられるグラフは連結である。
入力
入力は以下の形式で標準入力から与えられる。
N M a_1 b_1 c_1 a_2 b_2 c_2 : a_M b_M c_M
出力
グラフ上の、どの異なる 2 頂点間の、どの最短経路にも含まれない辺の数を出力せよ。
入力例 1
3 3 1 2 1 1 3 1 2 3 3
出力例 1
1
この入力例で与えられるグラフにおける、全ての異なる 2 頂点間の最短経路は以下の通りです。
- 頂点 1 から頂点 2 への最短経路は、頂点 1 → 頂点 2 で経路長は 1
- 頂点 1 から頂点 3 への最短経路は、頂点 1 → 頂点 3 で経路長は 1
- 頂点 2 から頂点 1 への最短経路は、頂点 2 → 頂点 1 で経路長は 1
- 頂点 2 から頂点 3 への最短経路は、頂点 2 → 頂点 1 → 頂点 3 で経路長は 2
- 頂点 3 から頂点 1 への最短経路は、頂点 3 → 頂点 1 で経路長は 1
- 頂点 3 から頂点 2 への最短経路は、頂点 3 → 頂点 1 → 頂点 2 で経路長は 2
したがって、一度も最短経路として使用されていない辺は、頂点 2 と頂点 3 を結ぶ長さ 3 の辺のみであるため、1 を出力します。
入力例 2
3 2 1 2 1 2 3 1
出力例 2
0
全ての辺が異なる 2 頂点間のある最短経路で使用されます。
Score : 400 points
Problem Statement
You are given an undirected connected weighted graph with N vertices and M edges that contains neither self-loops nor double edges.
The i-th (1≤i≤M) edge connects vertex a_i and vertex b_i with a distance of c_i.
Here, a self-loop is an edge where a_i = b_i (1≤i≤M), and double edges are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M).
A connected graph is a graph where there is a path between every pair of different vertices.
Find the number of the edges that are not contained in any shortest path between any pair of different vertices.
Constraints
- 2≤N≤100
- N-1≤M≤min(N(N-1)/2,1000)
- 1≤a_i,b_i≤N
- 1≤c_i≤1000
- c_i is an integer.
- The given graph contains neither self-loops nor double edges.
- The given graph is connected.
Input
The input is given from Standard Input in the following format:
N M a_1 b_1 c_1 a_2 b_2 c_2 : a_M b_M c_M
Output
Print the number of the edges in the graph that are not contained in any shortest path between any pair of different vertices.
Sample Input 1
3 3 1 2 1 1 3 1 2 3 3
Sample Output 1
1
In the given graph, the shortest paths between all pairs of different vertices are as follows:
- The shortest path from vertex 1 to vertex 2 is: vertex 1 → vertex 2, with the length of 1.
- The shortest path from vertex 1 to vertex 3 is: vertex 1 → vertex 3, with the length of 1.
- The shortest path from vertex 2 to vertex 1 is: vertex 2 → vertex 1, with the length of 1.
- The shortest path from vertex 2 to vertex 3 is: vertex 2 → vertex 1 → vertex 3, with the length of 2.
- The shortest path from vertex 3 to vertex 1 is: vertex 3 → vertex 1, with the length of 1.
- The shortest path from vertex 3 to vertex 2 is: vertex 3 → vertex 1 → vertex 2, with the length of 2.
Thus, the only edge that is not contained in any shortest path, is the edge of length 3 connecting vertex 2 and vertex 3, hence the output should be 1.
Sample Input 2
3 2 1 2 1 2 3 1
Sample Output 2
0
Every edge is contained in some shortest path between some pair of different vertices.