Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
小数第三位までで表すことのできる実数 X が、小数第三位まで入力されます。
X を小数第一位で四捨五入した結果として得られる整数を出力してください。
制約
- 0 \leq X < 100
- X は小数第三位までで表現可能である。
- X は小数第三位まで与えられる。
入力
入力は以下の形式で標準入力から与えられる。
X
出力
X を小数第一位で四捨五入して得られる整数を出力せよ。
入力例 1
3.456
出力例 1
3
3.456 の小数第一位は 4 であるので、3.456 を小数第一位で四捨五入した値は 3 となります。
入力例 2
99.500
出力例 2
100
入力例 3
0.000
出力例 3
0
Score : 100 points
Problem Statement
You are given a real number X, which is representable using at most three decimal digits, with three decimal digits.
Round X to the nearest integer and print the result.
Constraints
- 0 \leq X < 100
- X is representable using at most three decimal digits.
- X has three decimal digits in input.
Input
Input is given from Standard Input in the following format:
X
Output
Print the integer resulting from rounding X to the nearest integer.
Sample Input 1
3.456
Sample Output 1
3
The digit in the first decimal place of 3.456 is 4, so we should round it down to 3.
Sample Input 2
99.500
Sample Output 2
100
Sample Input 3
0.000
Sample Output 3
0
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
3 問の問題からなる試験があり、それぞれの問題の配点は 1 点、2 点、4 点でした。
高橋君、青木君、すぬけ君の 3 人がこの試験を受け、 高橋君は A 点、青木君は B 点を取りました。
すぬけ君は、高橋君と青木君のうち少なくとも一方が解けた問題は解け、 2 人とも解けなかった問題は解けませんでした。
すぬけ君の点数を求めてください。
ただし、この問題の制約下で、すぬけ君の点数は一意に定まる事が証明できます。
制約
- 0\leq A,B \leq 7
- A,B は整数
入力
入力は以下の形式で標準入力から与えられる。
A B
出力
すぬけ君の点数を整数で出力せよ。
入力例 1
1 2
出力例 1
3
高橋君は 1 点を取った事から、 1 点の問題のみを正解し、それ以外の 2 問は解けなかったことがわかります。
同様に、青木君は 2 点を取った事から、 2 点の問題のみを正解し、それ以外の 2 問は解けなかったことがわかります。
よって、すぬけ君は 1 点の問題と 2 点の問題を正解し、高橋君と青木君がともに解けなかった 4 点の問題はすぬけ君も解けなかったことになるので、3 点を取ったことがわかります。よって、3 を出力します。
入力例 2
5 3
出力例 2
7
高橋君は 5 点を取った事から、 1 点の問題と 4 点の問題を正解し、 2 点の問題は解けなかったことがわかります。
同様に、青木君は 3 点を取った事から、 1 点の問題と 2 点の問題を正解し、 4 点の問題は解けなかったことがわかります。
よって、3 問すべてについて、高橋君と青木君の少なくとも一方が正解しているため、すぬけ君はすベての問題に正解し、7 点を取ったことがわかります。 よって、7 を出力します。
入力例 3
0 0
出力例 3
0
高橋君と青木君は 2 人ともいずれの問題も解けていません。 よって、すぬけ君もいずれの問題も解けておらず、 0 を出力します。
Score : 100 points
Problem Statement
There was an exam consisting of three problems worth 1, 2, and 4 points.
Takahashi, Aoki, and Snuke took this exam. Takahashi scored A points, and Aoki scored B points.
Snuke solved all of the problems solved by at least one of Takahashi and Aoki, and failed to solve any of the problems solved by neither of them.
Find Snuke's score.
It can be proved that Snuke's score is uniquely determined under the Constraints of this problem.
Constraints
- 0\leq A,B \leq 7
- A and B are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print Snuke's score as an integer.
Sample Input 1
1 2
Sample Output 1
3
Since Takahashi scored 1 point, we see that he solved only the 1-point problem and failed to solve the other two.
Similarly, since Aoki scored 2 points, we see that he solved only the 2-point problem and failed to solve the other two.
Therefore, Snuke must have solved the 1- and 2-point problems, but not the 4-point one, which Takahashi and Aoki both failed to solve, for a score of 3 points. Thus, 3 should be printed.
Sample Input 2
5 3
Sample Output 2
7
Since Takahashi scored 5 points, we see that he solved the 1- and 4-point problems but not the 2-point one.
Similarly, since Aoki scored 3 points, we see that he solved the 1- and 2-point problems but not the 4-point one.
Therefore, each of the three problems is solved by at least one of Takahashi and Aoki, so we see that Snuke solved all of the problems, for a score of 7 points. Thus, 7 should be printed.
Sample Input 3
0 0
Sample Output 3
0
Both Takahashi and Aoki solved none of the problems. Therefore, so did Snuke. Thus, 0 should be printed.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
ボウリングのピンは 1 から 10 の番号が付けられており、上から見ると下図のように配置されます。

この図の二つの点線に挟まれた部分を列と呼ぶことにします。
例えば、ピン 1, 5 とピン 3, 9 はそれぞれ同じ列に存在します。
いくつかのピンが倒れた状態のうち、特殊なものはスプリットと呼ばれます。
ピンの配置がスプリットであるとは、以下の条件が全て成り立つことを言います。
- ピン 1 が倒れている。
- ある二つの異なる列であって、次の条件を満たすものが存在する。
- それぞれの列には、立っているピンが 1 本以上存在する。
- それらの列の間に、ピンが全て倒れている列が存在する。
具体例は入出力例を参考にしてください。
さて、あるピンの配置が長さ 10 の文字列 S として与えられます。
i = 1, \dots, 10 について、ピン i が倒れているとき S の i 文字目は 0 であり、ピン i が立っているとき S の i 文字目は 1 です。
S で表されるピンの配置がスプリットかどうか判定してください。
制約
- S は
0と1からなる長さ 10 の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S で表されるピンの配置がスプリットなら Yes を、そうでないなら No を出力せよ。
入力例 1
0101110101
出力例 1
Yes
倒れているピンを灰色で、立っているピンを白色で示すと下図のようになります。

ピン 5 が立っている列とピン 6 が立っている列の間にはピン 3, 9 が置かれている列が存在しますが、ピン 3, 9 はいずれも倒れているので、この配置はスプリットです。
入力例 2
0100101001
出力例 2
Yes

入力例 3
0000100110
出力例 3
No

この配置はスプリットではありません。
入力例 4
1101110101
出力例 4
No

ピン 1 が倒れていないので、スプリットではありません。
Score : 200 points
Problem Statement
Bowling pins are numbered 1 through 10. The following figure is a top view of the arrangement of the pins:

Let us call each part between two dotted lines in the figure a column.
For example, Pins 1 and 5 belong to the same column, and so do Pin 3 and 9.
When some of the pins are knocked down, a special situation called split may occur.
A placement of the pins is a split if both of the following conditions are satisfied:
- Pin 1 is knocked down.
- There are two different columns that satisfy both of the following conditions:
- Each of the columns has one or more standing pins.
- There exists a column between these columns such that all pins in the column are knocked down.
See also Sample Inputs and Outputs for examples.
Now, you are given a placement of the pins as a string S of length 10.
For i = 1, \dots, 10, the i-th character of S is 0 if Pin i is knocked down, and is 1 if it is standing.
Determine if the placement of the pins represented by S is a split.
Constraints
- S is a string of length 10 consisting of
0and1.
Input
Input is given from Standard Input in the following format:
S
Output
If the placement of the pins represented by S is a split, print Yes; otherwise, print No.
Sample Input 1
0101110101
Sample Output 1
Yes
In the figure below, the knocked-down pins are painted gray, and the standing pins are painted white:

Between the column containing a standing pin 5 and the column containing a standing pin 6 is a column containing Pins 3 and 9. Since Pins 3 and 9 are both knocked down, the placement is a split.
Sample Input 2
0100101001
Sample Output 2
Yes

Sample Input 3
0000100110
Sample Output 3
No

This placement is not a split.
Sample Input 4
1101110101
Sample Output 4
No

This is not a split because Pin 1 is not knocked down.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
1 から N までの番号が付いた N 人のプレイヤーが総当たり戦をしました。この総当たり戦で行われた試合全てについて、二人の一方が勝ち、もう一方が負けました。
総当たり戦の結果は N 個の長さ N の文字列 S_1,S_2,\ldots,S_N によって以下の形式で与えられます。
-
i\neq j のとき、S_i の j 文字目は
o,xのいずれかであり、oのときプレイヤー i がプレイヤー j に勝ったことを、xのときプレイヤー i がプレイヤー j に負けたことを意味する。 -
i=j のとき、S_i の j 文字目は
-である。
総当たり戦で勝った試合数が多いほうが順位が上であり、勝った試合数が同じ場合は、プレイヤーの番号が小さいほうが順位が上となります。 N 人のプレイヤーの番号を順位が高い順に答えてください。
制約
- 2\leq N\leq 100
- N は整数
- S_i は
o,x,-からなる長さ N の文字列 - S_1,\ldots,S_N は問題文中の形式を満たす
入力
入力は以下の形式で標準入力から与えられる。
N S_1 S_2 \vdots S_N
出力
N 人のプレイヤーの番号を、順位が高い順に空白区切りで出力せよ。
入力例 1
3 -xx o-x oo-
出力例 1
3 2 1
プレイヤー 1 は 0 勝、プレイヤー 2 は 1 勝、プレイヤー 3 は 2 勝なので、プレイヤーの番号は順位が高い順に 3,2,1 です。
入力例 2
7 -oxoxox x-xxxox oo-xoox xoo-ooo ooxx-ox xxxxx-x oooxoo-
出力例 2
4 7 3 1 5 2 6
プレイヤー 4 とプレイヤー 7 はどちらも 5 勝ですが、プレイヤー番号が小さいプレイヤー 4 のほうが順位が上になります。
Score : 200 points
Problem Statement
There are N players numbered 1 to N, who have played a round-robin tournament. For every match in this tournament, one player won and the other lost.
The results of the matches are given as N strings S_1,S_2,\ldots,S_N of length N each, in the following format:
-
If i\neq j, the j-th character of S_i is
oorx.omeans that player i won against player j, andxmeans that player i lost to player j. -
If i=j, the j-th character of S_i is
-.
The player with more wins ranks higher. If two players have the same number of wins, the player with the smaller player number ranks higher. Report the player numbers of the N players in descending order of rank.
Constraints
- 2\leq N\leq 100
- N is an integer.
- S_i is a string of length N consisting of
o,x, and-. - S_1,\ldots,S_N conform to the format described in the problem statement.
Input
The input is given from Standard Input in the following format:
N S_1 S_2 \vdots S_N
Output
Print the player numbers of the N players in descending order of rank.
Sample Input 1
3 -xx o-x oo-
Sample Output 1
3 2 1
Player 1 has 0 wins, player 2 has 1 win, and player 3 has 2 wins. Thus, the player numbers in descending order of rank are 3,2,1.
Sample Input 2
7 -oxoxox x-xxxox oo-xoox xoo-ooo ooxx-ox xxxxx-x oooxoo-
Sample Output 2
4 7 3 1 5 2 6
Both players 4 and 7 have 5 wins, but player 4 ranks higher because their player number is smaller.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
長さ N の数列 A = (A_1, A_2, \ldots, A_N) が与えられます。 K = 0, 1, 2, \ldots, N-1 のそれぞれについて、下記の問題を解いてください。
1 以上 N 以下の整数 i であって、次の条件を満たすものの個数を求めよ。
- A に含まれる整数のうち A_i より大きいものはちょうど K 種類である。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq A_i \leq 10^9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
N 行出力せよ。 i = 1, 2, \ldots, N について、i 行目には K = i-1 の場合の問題の答えを出力せよ。
入力例 1
6 2 7 1 8 2 8
出力例 1
2 1 2 1 0 0
例として、K = 2 の場合の問題の答えを以下で求めます。
- A_1 = 2 に関して、A に含まれる整数のうち A_1 より大きいものは、7, 8 の 2 種類です。
- A_2 = 7 に関して、A に含まれる整数のうち A_2 より大きいものは、8 の 1 種類です。
- A_3 = 1 に関して、A に含まれる整数のうち A_3 より大きいものは、2, 7, 8 の 3 種類です。
- A_4 = 8 に関して、A に含まれる整数のうち A_4 より大きいものは、0 種類です(存在しません)。
- A_5 = 2 に関して、A に含まれる整数のうち A_5 より大きいものは、7, 8 の 2 種類です。
- A_6 = 8 に関して、A に含まれる整数のうち A_6 より大きいものは、0 種類です(存在しません)。
よって、A に含まれる整数のうちA_i より大きいものがちょうど K = 2 種類であるような i は、i = 1 と i = 5 の 2 つです。よって、K = 2 の場合の答えは 2 です。
入力例 2
1 1
出力例 2
1
入力例 3
10 979861204 57882493 979861204 447672230 644706927 710511029 763027379 710511029 447672230 136397527
出力例 3
2 1 2 1 2 1 1 0 0 0
Score : 300 points
Problem Statement
You are given a sequence A = (A_1, A_2, \ldots, A_N) of length N. For each K = 0, 1, 2, \ldots, N-1, solve the following problem.
Find the number of integers i between 1 and N (inclusive) such that:
- A contains exactly K distinct integers greater than A_i.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq A_i \leq 10^9
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
Print N lines. For i = 1, 2, \ldots, N, the i-th line should contain the answer for K = i-1.
Sample Input 1
6 2 7 1 8 2 8
Sample Output 1
2 1 2 1 0 0
For example, we will find the answer for K=2.
- Regarding A_1 = 2, A contains 2 distinct integers greater than A_1: 7 and 8.
- Regarding A_2 = 7, A contains 1 distinct integer greater than A_2: 8.
- Regarding A_3 = 1, A contains 3 distinct integers greater than A_3: 2, 7, and 8.
- Regarding A_4 = 8, A contains 0 distinct integers greater than A_4 (there is no such integer).
- Regarding A_5 = 2, A contains 2 distinct integers greater than A_5: 7 and 8.
- Regarding A_6 = 8, A contains 0 distinct integers greater than A_6 (there is no such integer).
Thus, there are two i's, i = 1 and i = 5, such that A contains exactly K = 2 distinct integers greater than A_i. Therefore, the answer for K = 2 is 2.
Sample Input 2
1 1
Sample Output 2
1
Sample Input 3
10 979861204 57882493 979861204 447672230 644706927 710511029 763027379 710511029 447672230 136397527
Sample Output 3
2 1 2 1 2 1 1 0 0 0
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
頂点 1, 頂点 2,\ldots, 頂点 N の N 個の頂点からなる単純無向グラフ G,H が与えられます。 G には M _ G 本の辺があり、i 本目 (1\leq i\leq M _ G) の辺は頂点 u _ i と頂点 v _ i を結んでいます。 H には M _ H 本の辺があり、i 本目 (1\leq i\leq M _ H) の辺は頂点 a _ i と頂点 b _ i を結んでいます。
あなたは、グラフ H に対して次の操作を 0 回以上の好きな回数繰り返すことができます。
- 1\leq i\lt j\leq N を満たす整数の組 (i,j) をひとつ選ぶ。A _ {i,j} 円を支払って、頂点 i と頂点 j を結ぶ辺がなければ追加し、あれば取り除く。
G と H を同型にするために少なくとも何円支払う必要があるか求めてください。
単純無向グラフとは?
単純無向グラフとは、自己ループや多重辺を含まず、辺に向きの無いグラフのことをいいます。
グラフの同型とは?
N 頂点のグラフ G と H が同型であるとは、ある (1,2,\ldots,N) の並べ替え (P _ 1,P _ 2,\ldots,P _ N) が存在して、どの 1\leq i\lt j\leq N に対しても
- G に頂点 i, 頂点 j を結ぶ辺が存在するとき、かつそのときに限り H に頂点 P _ i, 頂点 P _ j を結ぶ辺が存在する
制約
- 1\leq N\leq8
- 0\leq M _ G\leq\dfrac{N(N-1)}2
- 0\leq M _ H\leq\dfrac{N(N-1)}2
- 1\leq u _ i\lt v _ i\leq N\ (1\leq i\leq M _ G)
- (u _ i,v _ i)\neq(u _ j,v _ j)\ (1\leq i\lt j\leq M _ G)
- 1\leq a _ i\lt b _ i\leq N\ (1\leq i\leq M _ H)
- (a _ i,b _ i)\neq(a _ j,b _ j)\ (1\leq i\lt j\leq M _ H)
- 1\leq A _ {i,j}\leq 10 ^ 6\ (1\leq i\lt j\leq N)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N
M _ G
u _ 1 v _ 1
u _ 2 v _ 2
\vdots
u _ {M _ G} v _ {M _ G}
M _ H
a _ 1 b _ 1
a _ 2 b _ 2
\vdots
a _ {M _ H} b _ {M _ H}
A _ {1,2} A _ {1,3} \ldots A _ {1,N}
A _ {2,3} \ldots A _ {2,N}
\vdots
A _ {N-1,N}
出力
答えを出力せよ。
入力例 1
5 4 1 2 2 3 3 4 4 5 4 1 2 1 3 1 4 1 5 3 1 4 1 5 9 2 6 5 3
出力例 1
9
与えられたグラフはそれぞれ以下のようになります。

たとえば、H に対して次のような 4 つの操作を順に行うことで、9 円を支払ってG と H を同型にすることができます。
- (i,j)=(1,3) として操作を行う。H には頂点 1 と頂点 3 を結ぶ辺があるので、1 円を支払ってこれを取り除く。
- (i,j)=(2,5) として操作を行う。H には頂点 2 と頂点 5 を結ぶ辺はないので、2 円を支払ってこれを追加する。
- (i,j)=(1,5) として操作を行う。H には頂点 1 と頂点 5 を結ぶ辺があるので、1 円を支払ってこれを取り除く。
- (i,j)=(3,5) として操作を行う。H には頂点 3 と頂点 5 を結ぶ辺はないので、5 円を支払ってこれを追加する。
操作の結果、H は以下のようになります。

支払う金額を 8 円以下にして G と H を同型にすることはできないため、9 を出力してください。
入力例 2
5 3 1 2 2 3 3 4 4 1 2 2 3 3 4 4 5 9 1 1 1 1 1 1 1 1 9
出力例 2
3
たとえば、(i,j)=(2,3),(2,4),(3,4) とした 3 回の操作を行うことで G と H を同型にすることができます。
入力例 3
5 3 1 2 2 3 3 4 4 1 2 2 3 3 4 4 5 5 4 4 4 4 4 4 4 4 5
出力例 3
5
たとえば、(i,j)=(4,5) とした 1 回の操作を行うことで G と H を同型にすることができます。
入力例 4
2 0 0 371
出力例 4
0
G や H には辺が含まれていないこともあります。 また、一度も操作をする必要がないこともあります。
入力例 5
8 13 1 8 5 7 4 6 1 5 7 8 1 6 1 2 5 8 2 6 5 6 6 7 3 7 4 8 15 3 5 1 7 4 6 3 8 7 8 1 2 5 6 1 6 1 5 1 4 2 8 2 6 2 4 4 7 1 3 7483 1694 5868 3296 9723 5299 4326 5195 4088 5871 1384 2491 6562 1149 6326 2996 9845 7557 4041 7720 1554 5060 8329 8541 3530 4652 3874 3748
出力例 5
21214
Score : 300 points
Problem Statement
You are given simple undirected graphs G and H, each with N vertices: vertices 1, 2, \ldots, N. Graph G has M_G edges, and its i-th edge (1\leq i\leq M_G) connects vertices u_i and v_i. Graph H has M_H edges, and its i-th edge (1\leq i\leq M_H) connects vertices a_i and b_i.
You can perform the following operation on graph H any number of times, possibly zero.
- Choose a pair of integers (i,j) satisfying 1\leq i<j\leq N. Pay A_{i,j} yen, and if there is no edge between vertices i and j in H, add one; if there is, remove it.
Find the minimum total cost required to make G and H isomorphic.
What is a simple undirected graph?
A simple undirected graph is a graph without self-loops or multi-edges, where edges have no direction.
What does it mean for graphs to be isomorphic?
Two graphs G and H with N vertices are isomorphic if and only if there exists a permutation (P_1,P_2,\ldots,P_N) of (1,2,\ldots,N) such that for all 1\leq i\lt j\leq N:
- an edge exists between vertices i and j in G if and only if an edge exists between vertices P_i and P_j in H.
Constraints
- 1\leq N\leq8
- 0\leq M _ G\leq\dfrac{N(N-1)}2
- 0\leq M _ H\leq\dfrac{N(N-1)}2
- 1\leq u _ i\lt v _ i\leq N\ (1\leq i\leq M _ G)
- (u _ i,v _ i)\neq(u _ j,v _ j)\ (1\leq i\lt j\leq M _ G)
- 1\leq a _ i\lt b _ i\leq N\ (1\leq i\leq M _ H)
- (a _ i,b _ i)\neq(a _ j,b _ j)\ (1\leq i\lt j\leq M _ H)
- 1\leq A _ {i,j}\leq 10 ^ 6\ (1\leq i\lt j\leq N)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N
M _ G
u _ 1 v _ 1
u _ 2 v _ 2
\vdots
u _ {M _ G} v _ {M _ G}
M _ H
a _ 1 b _ 1
a _ 2 b _ 2
\vdots
a _ {M _ H} b _ {M _ H}
A _ {1,2} A _ {1,3} \ldots A _ {1,N}
A _ {2,3} \ldots A _ {2,N}
\vdots
A _ {N-1,N}
Output
Print the answer.
Sample Input 1
5 4 1 2 2 3 3 4 4 5 4 1 2 1 3 1 4 1 5 3 1 4 1 5 9 2 6 5 3
Sample Output 1
9
The given graphs are as follows:

For example, you can perform the following four operations on H to make it isomorphic to G at a cost of 9 yen.
- Choose (i,j)=(1,3). There is an edge between vertices 1 and 3 in H, so pay 1 yen to remove it.
- Choose (i,j)=(2,5). There is no edge between vertices 2 and 5 in H, so pay 2 yen to add it.
- Choose (i,j)=(1,5). There is an edge between vertices 1 and 5 in H, so pay 1 yen to remove it.
- Choose (i,j)=(3,5). There is no edge between vertices 3 and 5 in H, so pay 5 yen to add it.
After these operations, H becomes:

You cannot make G and H isomorphic at a cost less than 9 yen, so print 9.
Sample Input 2
5 3 1 2 2 3 3 4 4 1 2 2 3 3 4 4 5 9 1 1 1 1 1 1 1 1 9
Sample Output 2
3
For example, performing the operations (i,j)=(2,3),(2,4),(3,4) on H will make it isomorphic to G.
Sample Input 3
5 3 1 2 2 3 3 4 4 1 2 2 3 3 4 4 5 5 4 4 4 4 4 4 4 4 5
Sample Output 3
5
For example, performing the operation (i,j)=(4,5) once will make G and H isomorphic.
Sample Input 4
2 0 0 371
Sample Output 4
0
Note that G and H may have no edges.
Also, it is possible that no operations are needed.
Sample Input 5
8 13 1 8 5 7 4 6 1 5 7 8 1 6 1 2 5 8 2 6 5 6 6 7 3 7 4 8 15 3 5 1 7 4 6 3 8 7 8 1 2 5 6 1 6 1 5 1 4 2 8 2 6 2 4 4 7 1 3 7483 1694 5868 3296 9723 5299 4326 5195 4088 5871 1384 2491 6562 1149 6326 2996 9845 7557 4041 7720 1554 5060 8329 8541 3530 4652 3874 3748
Sample Output 5
21214
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
N 頂点 M 辺の有向グラフが与えられます。j 番目の有向辺は頂点 u_j から頂点 v_j に向かっており、重み w_j を持っています。
各頂点に -10^{18} 以上 10^{18} 以下の整数を書き込む方法であって、次の条件を満たすものを 1 つ見つけてください。
- 頂点 i に書き込まれている値を x_i とする。すべての辺 j=1,2,\dots,M について、x_{v_j} - x_{u_j} = w_j が成り立つ。
与えられる入力について、条件を満たす書き込み方が少なくとも 1 つ存在することが保証されます。
制約
- 2 \leq N \leq 2 \times 10^5
- 1 \leq M \leq \min\{2 \times 10^5,N(N-1)/2\}
- 1 \leq u_j, v_j \leq N
- u_j \neq v_j
- i \neq j なら (u_i,v_i) \neq (u_j,v_j) かつ (u_i,v_i) \neq (v_j,u_j)
- |w_j| \leq 10^9
- 入力はすべて整数
- 条件を満たす書き込み方が少なくとも 1 つ存在する
入力
入力は以下の形式で標準入力から与えられる。
N M u_1 v_1 w_1 u_2 v_2 w_2 \vdots u_M v_M w_M
出力
頂点 i に書き込む整数を x_i として、x_1,x_2,\dots,x_N をこの順に空白区切りで 1 行で出力せよ。答えが複数ある場合、どれを出力しても良い。
入力例 1
3 3 1 2 2 3 2 3 1 3 -1
出力例 1
3 5 2
x=(3,5,2) とすることで、x_2-x_1=w_1=2,x_2-x_3=w_2=3,x_3-x_1=w_3=-1 となり、条件を満たします。
他にも、たとえば x=(-1,1,-2) としても正解となります。
入力例 2
4 2 2 1 5 3 4 -3
出力例 2
5 0 6 3
他にも、たとえば x=(0,-5,4,1) や x=(5,0,4,1) としても正解となります。
入力例 3
5 7 2 1 18169343 3 1 307110901 4 1 130955934 2 3 -288941558 2 5 96267410 5 3 -385208968 4 3 -176154967
出力例 3
200401298 182231955 -106709603 69445364 278499365
Score : 400 points
Problem Statement
You are given a directed graph with N vertices and M edges. The j-th directed edge goes from vertex u_j to vertex v_j and has a weight of w_j.
Find one way to write an integer between -10^{18} and 10^{18}, inclusive, to each vertex such that the following condition is satisfied.
- Let x_i be the value written on vertex i. For all edges j=1,2,\dots,M, it holds that x_{v_j} - x_{u_j} = w_j.
It is guaranteed that at least one such assignment exists for the given input.
Constraints
- 2 \leq N \leq 2 \times 10^5
- 1 \leq M \leq \min\{2 \times 10^5,N(N-1)/2\}
- 1 \leq u_j, v_j \leq N
- u_j \neq v_j
- If i \neq j, then (u_i, v_i) \neq (u_j, v_j) and (u_i, v_i) \neq (v_j, u_j)
- |w_j| \leq 10^9
- All input values are integers.
- There exists at least one assignment satisfying the conditions.
Input
The input is given from Standard Input in the following format:
N M u_1 v_1 w_1 u_2 v_2 w_2 \vdots u_M v_M w_M
Output
Let x_i be the integer written on vertex i. Print x_1, x_2, \dots, x_N in this order, separated by spaces, on a single line. If there are multiple solutions, you may print any of them.
Sample Input 1
3 3 1 2 2 3 2 3 1 3 -1
Sample Output 1
3 5 2
By setting x = (3, 5, 2), we have x_2 - x_1 = w_1 = 2, x_2 - x_3 = w_2 = 3, x_3 - x_1 = w_3 = -1, satisfying the conditions.
For example, x = (-1, 1, -2) is also a valid answer.
Sample Input 2
4 2 2 1 5 3 4 -3
Sample Output 2
5 0 6 3
For example, x = (0, -5, 4, 1) and x = (5, 0, 4, 1) are also valid answers.
Sample Input 3
5 7 2 1 18169343 3 1 307110901 4 1 130955934 2 3 -288941558 2 5 96267410 5 3 -385208968 4 3 -176154967
Sample Output 3
200401298 182231955 -106709603 69445364 278499365
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 475 点
問題文
2 次元平面上の N 個の点 (x_1,y_1),(x_2,y_2),\dots,(x_N,y_N) と、非負整数 D が与えられます。
整数の組 (x,y) であって、 \displaystyle \sum_{i=1}^N (|x-x_i|+|y-y_i|) \leq D を満たすものの個数を求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 0 \leq D \leq 10^6
- -10^6 \leq x_i, y_i \leq 10^6
- i\neq j ならば (x_i,y_i) \neq (x_j,y_j)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N D x_1 y_1 x_2 y_2 \vdots x_N y_N
出力
答えを出力せよ。
入力例 1
2 3 0 0 1 0
出力例 1
8
下図は、サンプル 1 の入力と答えを可視化したものです。青い点が入力を表します。青い点と赤い点の合計 8 点が、問題文中の条件を満たす点です。

入力例 2
2 0 0 0 2 0
出力例 2
0
入力例 3
6 100 9 -6 10 -1 2 10 -1 7 -7 5 -1 -4
出力例 3
419
Score : 475 points
Problem Statement
You are given N points (x_1, y_1), (x_2, y_2), \dots, (x_N, y_N) on a two-dimensional plane, and a non-negative integer D.
Find the number of integer pairs (x, y) such that \displaystyle \sum_{i=1}^N (|x-x_i|+|y-y_i|) \leq D.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 0 \leq D \leq 10^6
- -10^6 \leq x_i, y_i \leq 10^6
- (x_i, y_i) \neq (x_j, y_j) for i \neq j.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N D x_1 y_1 x_2 y_2 \vdots x_N y_N
Output
Print the answer.
Sample Input 1
2 3 0 0 1 0
Sample Output 1
8
The following figure visualizes the input and the answer for Sample 1. The blue points represent the input. The blue and red points, eight in total, satisfy the condition in the statement.

Sample Input 2
2 0 0 0 2 0
Sample Output 2
0
Sample Input 3
6 100 9 -6 10 -1 2 10 -1 7 -7 5 -1 -4
Sample Output 3
419
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
2 次元平面上の N 個の相異なる点が与えられます。点 i\, (1 \leq i \leq N) の座標は (x_i,y_i) です。
2 つの点 i,j\, (1 \leq i,j \leq N) の距離を \mathrm{min} (|x_i-x_j|,|y_i-y_j|) 、すなわち x 座標の差と y 座標の差の小さい方と定義します。
異なる 2 つの点の距離の最大値を求めてください。
制約
- 2 \leq N \leq 200000
- 0 \leq x_i,y_i \leq 10^9
- (x_i,y_i) \neq (x_j,y_j) (i \neq j)
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N x_1 y_1 x_2 y_2 \vdots x_N y_N
出力
異なる 2 つの点の距離の最大値を出力せよ。
入力例 1
3 0 3 3 1 4 10
出力例 1
4
点 1 と点 2 の距離は 2 、点 1 と点 3 の距離は 4 、点 2 と点 3 の距離は 1 です。よって 4 を出力してください。
入力例 2
4 0 1 0 4 0 10 0 6
出力例 2
0
入力例 3
8 897 729 802 969 765 184 992 887 1 104 521 641 220 909 380 378
出力例 3
801
Score : 500 points
Problem Statement
Given are N distinct points in a two-dimensional plane. Point i (1 \leq i \leq N) has the coordinates (x_i,y_i).
Let us define the distance between two points i and j be \mathrm{min} (|x_i-x_j|,|y_i-y_j|): the smaller of the difference in the x-coordinates and the difference in the y-coordinates.
Find the maximum distance between two different points.
Constraints
- 2 \leq N \leq 200000
- 0 \leq x_i,y_i \leq 10^9
- (x_i,y_i) \neq (x_j,y_j) (i \neq j)
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N x_1 y_1 x_2 y_2 \vdots x_N y_N
Output
Print the maximum distance between two different points.
Sample Input 1
3 0 3 3 1 4 10
Sample Output 1
4
The distances between Points 1 and 2, between Points 1 and 3, and between Points 2 and 3 are 2, 4, and 1, respectively, so your output should be 4.
Sample Input 2
4 0 1 0 4 0 10 0 6
Sample Output 2
0
Sample Input 3
8 897 729 802 969 765 184 992 887 1 104 521 641 220 909 380 378
Sample Output 3
801