C - マルチコミュニケーション 2 (Multi Communication 2) 解説 /

実行時間制限: 3 sec / メモリ制限: 1024 MiB

Score: 100 points

Distributed Files

Problem Statement

President K has prepared a game for the contestants of the JOI Final Stage. President K secretly has an N \times N table A, each of whose cells contains a non-negative integer. Let A_{i,j} denote the integer written in the cell in the (i + 1)-st row from the top (0 \leq i \leq N - 1) and the (j + 1)-st column from the left (0 \leq j \leq N - 1). The table A satisfies the following conditions.

  • For each i such that 0 \leq i \leq N - 1, we have A_{i,i} = 0.
  • For each i, j such that 0 \leq i < j \leq N - 1, we have A_{i,j} = A_{j,i}.

Consider the weighted undirected graph with N vertices in which the edge between vertex i and vertex j (0 \leq i < j \leq N - 1) has weight A_{i,j}. Let X be the weight of a minimum spanning tree of this graph. In other words, X is the value obtained by the following procedure. The goal of the game is for all contestants to cooperate and determine the value of X.

  1. Set x = 0.
  2. Consider an undirected graph G with N vertices. The vertices of G are numbered 0, 1, \dots, N - 1. Initially, G has no edges.
  3. Repeat the following operation N - 1 times. Let X be the value of x after these N - 1 operations.
    1. Call the vertices of G that are currently reachable from vertex 0 by using some edges the near vertices, and call the other vertices the far vertices. Choose a pair (i, j) consisting of a near vertex i and a far vertex j so that the value A_{i,j} \times N^2 + i \times N + j is minimized. It can be proved that there is at least one near vertex and at least one far vertex, and that (i, j) is uniquely determined.
    2. Add the edge connecting vertex i and vertex j to G.
    3. Update x \gets x + A_{i,j}.

Define R = \lfloor 5120 / N \rfloor (where \lfloor x \rfloor denotes the greatest integer not exceeding x). There are R \times N contestants in the JOI Final Stage, divided into R groups of N contestants each. The groups are numbered 0 through R-1, and the contestants in group r (0 \leq r \leq R-1) are numbered (r, 0), (r, 1), \dots, (r, N-1).

The game proceeds by repeating the following rounds, in the order round 0, 1, 2, \dots, at most R times. During the game, the contestants are not allowed to communicate with one another, but they may share a strategy in advance.

Round r (0 \leq r \leq R-1) proceeds as follows.

  • For i = 0, 1, \dots, N-1 in this order, President K and contestant (r, i) perform the following interaction.
    1. President K gives contestant (r, i) the following information.
      • the contestant's number (r, i),
      • the information in the (i + 1)-st row of the table A, namely A_{i,0}, A_{i,1}, \dots, A_{i,N-1},
      • the integers B_{r,i,0}, B_{r,i,1}, \dots, B_{r,i,N-1}, each of which is an integer between 0 and 2^{64}-1, inclusive, sent to contestant (r, i) from the contestants in the previous round.
        • If r > 0, these integers are determined in interaction 3 described below.
        • If r = 0, then for convenience we define B_{r,i,0} = B_{r,i,1} = \dots = B_{r,i,N-1} = 0.
    2. If contestant (r, i) is able to determine the value of X, they answer President K with that value. If any contestant gives an answer, the game ends immediately.
    3. For each j = 0, 1, \dots, N-1, contestant (r, i) determines an integer B_{r+1,j,i}, which must be between 0 and 2^{64}-1, inclusive, to send to contestant (r+1, j), and tells it to President K. Even when r = R - 1, so that contestant (r+1, j) does not exist, contestant (r, i) must still determine B_{r+1,j,i} and tell it to President K.

If an answered value of X is incorrect, or if nobody answers the value of X by the end of round R - 1, the game fails. If the correct value of X is answered by the end of round R - 1, the game succeeds. A smaller number of rounds used yields a higher score (if an answer is given in round r, the number of rounds is counted as r + 1).

Implement a strategy for the contestants so that the game succeeds in as few rounds as possible.

Implementation Details

Your submission must include multi.h using a #include preprocessing directive, and must implement the following function.

  • std::vector<unsigned long long> strategy(int N, int r, int i, std::vector<unsigned long long> A, std::vector<unsigned long long> B)
    • The argument N represents the number of rows and columns of the table A.
    • The arguments r and i represent the contestant number (r, i).
    • The argument A is a sequence of non-negative integers of length N, where A[j] (0 \leq j \leq N - 1) represents the integer A_{i,j} written in the cell in the (i + 1)-st row from the top and the (j + 1)-st column from the left of the table A.
    • The argument B is a sequence of non-negative integers of length N, where B[j] (0 \leq j \leq N - 1) represents the integer B_{r,i,j} sent from contestant (r-1, j) to contestant (r, i). If r = 0, then \texttt{B[j]} = 0.
    • This function must return a sequence of non-negative integers of length 1 or N, representing the action taken by contestant (r, i) given the information in the arguments A, B. If the returned sequence has length other than 1 or N, the submission is judged as Wrong Answer [1].
      • To answer that the value of X is x, this function must return a sequence of length 1, namely (x). If the answered value is incorrect, the submission is judged as Wrong Answer [2].
      • If no answer is given, this function must return a sequence B' of length N.
        • For each j = 0, 1, \dots, N-1, B'[j] represents the integer B_{r+1,j,i} sent by contestant (r, i) to contestant (r+1, j). It must be an integer between 0 and 2^{64}-1, inclusive. Note that even when r = R - 1 and contestant (r+1, j) does not exist, the length of B' must still be N.
      • By the end of round R - 1, at least one contestant must give an answer. If no contestant gives an answer, the submission is judged as Wrong Answer [3].
    • The return value of this function must be determined solely by its arguments. In particular, note that the return value must not depend on previous calls to strategy or on runtime randomness. If this function returns different values for the same arguments, the submission is judged as Wrong Answer [4].
    • It is guaranteed that the given arguments can actually occur when playing the game using some table A and the submitted function strategy. However, note that calls are not necessarily made in the order of rounds 0, 1, \dots, R - 1.
    • The grader will play one or more games in a single execution. In one execution, this function is called at most 10\,240 times.

Important Notes

  • You may freely implement other functions or declare global variables for internal use.
  • Your submitted program must not communicate in any way with standard input, standard output, or any other files. However, outputting debugging information and the like to standard error output is allowed.

Constraints

  • 2 \leq N \leq 256.
  • 0 \leq A_{i,j} < 2^{48} (0 \leq i \leq N - 1, 0 \leq j \leq N - 1).
  • A_{i,i} = 0 (0 \leq i \leq N - 1).
  • A_{i,j} = A_{j,i} (0 \leq i < j \leq N - 1).
  • N and A_{i,j} (0 \leq i \leq N - 1, 0 \leq j \leq N - 1) are integers.

Subtasks

  1. (5 points) N \leq 64, A_{i,j} \leq 1 (0 \leq i \leq N - 1, 0 \leq j \leq N - 1).
  2. (10 points) A_{i,j} \leq 1 (0 \leq i \leq N - 1, 0 \leq j \leq N - 1).
  3. (15 points) N \leq 64.
  4. (40 points) A_{i,j} < 2^{20} (0 \leq i \leq N - 1, 0 \leq j \leq N - 1).
  5. (15 points) A_{i,j} < 2^{40} (0 \leq i \leq N - 1, 0 \leq j \leq N - 1).
  6. (15 points) There are no additional constraints.

Scoring

If, among the test cases of a subtask, there is even one that is judged as Wrong Answer [1]–[4], Time Limit Exceeded, Memory Limit Exceeded, or Runtime Error, then the score for that subtask is 0. Otherwise, let S be the maximum number of rounds used over all games in that subtask. Then the score for that subtask is determined as follows.

In the case of Subtask 3

  • Regardless of the value of S, the score for that subtask is 100\% of the points for the subtask. If S > 6, the contest site may display "Output is partially correct", but this does not affect the score.

In the case of subtasks other than Subtask 3

  • If S \leq 6, the score for that subtask is 100\% of the points for the subtask.
  • If 7 \leq S \leq 9, the score for that subtask is (100 - 20 \cdot (S - 6))\% of the points for the subtask.
  • If 10 \leq S \leq 19, the score for that subtask is (40 - S)\% of the points for the subtask.
  • If 20 \leq S, the score for that subtask is 20\% of the points for the subtask.

Compilation and Test Run

A sample grader for testing your program is included in the archive downloadable from the contest site. This archive also contains a sample file that you must submit.

The sample grader consists of a single file. That file is grader.cpp. To test your program, place the files grader.cpp, multi.cpp, and multi.h in the same Presidenty, and execute the following command.

g++ -std=gnu++20 -O2 -o grader grader.cpp multi.cpp

Alternatively, you may execute the file compile.sh included in the archive. In that case, run the following command.

./compile.sh

If the compilation succeeds, an executable file named grader is generated.

Note that the actual grader used for evaluation differs from the sample grader. The sample grader runs as a single process. This program reads input from standard input and writes the results to standard output.


Input for the Sample Grader

The sample grader plays one or more games in a single execution.

First, the sample grader reads the number of games T from standard input. Then, for each of the T games, it reads the information of the table A in the following format.

N 
A_{0,1} A_{0,2} A_{0,3} \cdots A_{0,N-1} 
A_{1,2} A_{1,3} \cdots A_{1,N-1} 
\vdots 
A_{N-2,N-1} 

Output for the Sample Grader

The sample grader outputs T lines to standard output. On the t-th line (1 \leq t \leq T), it outputs the result of the t-th game in the following format (the quotation marks are not actually printed).

  • If the game succeeds, the number of rounds used in that game is output as in Accepted: 22.
  • If any of the Wrong Answer conditions applies, the type of Wrong Answer is output as in Wrong Answer [4].

If the program being executed satisfies more than one Wrong Answer condition, only one of them will be displayed.

Sample Communication

Below is an example of input read by the sample grader and the corresponding sequence of function calls.

Sample Input 1

1
3
1 2
3

In round 0, the following interactions take place.

  • Contestant (0, 0) does not answer the value of X, and sends B_{1,0,0} = 0 to contestant (1, 0), B_{1,1,0} = 1 to contestant (1, 1), and B_{1,2,0} = 2 to contestant (1, 2).
  • Contestant (0, 1) does not answer the value of X, and sends B_{1,0,1} = 3 to contestant (1, 0), B_{1,1,1} = 4 to contestant (1, 1), and B_{1,2,1} = 5 to contestant (1, 2).
  • Contestant (0, 2) does not answer the value of X, and sends B_{1,0,2} = 6 to contestant (1, 0), B_{1,1,2} = 7 to contestant (1, 1), and B_{1,2,2} = 8 to contestant (1, 2).

Since no contestant answered the value of X, the game proceeds to the next round.

In round 1, the following interaction takes place.

  • Contestant (1, 0) receives B_{1,0,0} = 0 from contestant (0, 0), B_{1,0,1} = 3 from contestant (0, 1), and B_{1,0,2} = 6 from contestant (0, 2), and answers that X = 3. Since the value of X has been answered, the game ends at this point.

Because the answered value of X is correct, the game succeeds. The number of rounds used in this game is 2.

This sample input satisfies the constraints of Subtasks 3, 4, 5, and 6.

Among the files downloadable from the contest site, sample-01-in.txt corresponds to Sample Input 1. The archive downloadable from the contest site also contains further sample inputs: sample-02-in.txt, sample-03-in.txt, and sample-04-in.txt. sample-02-in.txt satisfies the constraints of all subtasks, sample-03-in.txt satisfies the constraints of Subtasks 3, 4, 5, and 6, and sample-04-in.txt satisfies the constraints of Subtasks 4, 5, and 6.

配点: 100

配布ファイル

問題文

K 理事長は JOI ファイナルステージの参加者にゲームを用意した. K 理事長は各マスに非負整数が書かれた N \times N マスの表 A を隠し持っている. A の上から i + 1 行目 (0 \leqq i \leqq N - 1),左から j + 1 列目 (0 \leqq j \leqq N - 1) のマスに書かれた非負整数を A_{i,j} とする. ここで,A は以下の条件を満たす.

  • 0 \leqq i \leqq N - 1 を満たす各 i に対して,A_{i,i} = 0
  • 0 \leqq i < j \leqq N - 1 を満たす各 i, j に対して,A_{i,j} = A_{j,i}

頂点 i と頂点 j の間 (0 \leqq i < j \leqq N - 1) の辺の重みが A_{i,j} であるような N 頂点の重み付き無向グラフの最小全域木の重みを X とする. すなわち,X は以下の手順で求められる値である.参加者全員で協力して X の値を求めることがこのゲームの目標である.

  1. x = 0 とする.
  2. N 頂点の無向グラフ G を考える.G の頂点には 0, 1, \dots, N - 1 の番号が付けられている.はじめ,G には辺が張られていない.
  3. 以下の操作を N - 1 回繰り返す.N - 1 回の操作が終了した後の x の値を X とする.
    1. 現在いくつかの辺を通って頂点 0 から到達可能である G の頂点を近い頂点, それ以外の G の頂点を遠い頂点と呼ぶ. 近い頂点 i と遠い頂点 j の組 (i, j) を,A_{i,j} \times N^2 + i \times N + j の値が最小になるように選ぶ. 近い頂点と遠い頂点がそれぞれ 1 つ以上存在し,(i, j) が一意に定まることが証明できる.
    2. 頂点 i と頂点 j を結ぶ辺を G に追加する.
    3. x \gets x + A_{i,j} と更新する.

R = \lfloor 5120 / N \rfloor と定義する (\lfloor x \rfloorx を超えない最大の整数を表す). JOI ファイナルステージには R \times N 人の参加者がおり,N 人ずつ R 個のグループに分けられている. 各グループには 0 から R-1 までの番号が付けられており,グループ r (0 \leqq r \leqq R-1) の参加者にはそれぞれ (r, 0), (r, 1), \dots, (r, N-1) の番号が付けられている.

ゲームは以下のラウンドをラウンド 0, 1, 2, \dots の順に最大 R 回繰り返すことで行われる. ゲーム中は参加者同士でコミュニケーションを取ることはできないが,事前に戦略を共有することができる.

ラウンド r (0 \leqq r \leqq R-1) は以下の手順で行われる.

  • i = 0, 1, \dots, N-1 の順に,K 理事長と参加者 (r, i) は以下のやりとりを行う.
    1. K 理事長は,参加者 (r, i) に以下の情報を与える.
      • 参加者の番号 (r, i)
      • Ai + 1 行目の情報 A_{i,0}, A_{i,1}, \dots, A_{i,N-1}
      • 前のラウンドの各参加者から参加者 (r, i) に送られた,0 以上 2^{64} 未満の整数 B_{r,i,0}, B_{r,i,1}, \dots, B_{r,i,N-1}
        • r > 0 の場合,これらの整数は以下で説明するやりとり 3 において決定される.
        • r = 0 の場合,便宜上 B_{r,i,0} = B_{r,i,1} = \dots = B_{r,i,N-1} = 0 とする.
    2. 参加者 (r, i)X の値を求めることができたなら,K 理事長に X の値を回答する.ある参加者が回答を行ったら,その時点でゲームは終了する.
    3. 参加者 (r, i) は,各 j = 0, 1, \dots, N-1 について,参加者 (r+1, j) に送る 0 以上 2^{64} 未満の整数 B_{r+1,j,i} を決定し,K 理事長に伝える. r = R - 1 のとき参加者 (r+1, j) は存在しないが,その場合でも B_{r+1,j,i} を決定し,K 理事長に伝える必要がある.

回答した X の値が間違っている場合や,ラウンド R - 1 までに誰も X の値を回答しなかった場合,ゲームは失敗となる. ラウンド R - 1 までに正しい X の値を回答した場合ゲームは成功となり,行われたラウンド数 (ラウンド r に回答を行った場合,ラウンド数は r + 1) が少ないほど高い評価を得られる.

できるだけ少ないラウンド数でゲームを成功させるような,参加者たちの戦略を実装せよ.

実装の詳細

あなたの回答プログラムは,multi.h#include プリプロセッサ指令で読み込み,以下の関数を実装しなければならない.

  • std::vector<unsigned long long> strategy(int N, int r, int i, std::vector<unsigned long long> A, std::vector<unsigned long long> B)
    • 引数 N は表 A の行および列の個数 N を表す.
    • 引数 r, i は参加者の番号 (r, i) を表す.
    • 引数 A は長さ N の非負整数列であり,A[j] (0 \leqq j \leqq N - 1) は表 A の上から i + 1 行目,左から j + 1 列目のマスに書かれた非負整数 A_{i,j} を表す.
    • 引数 B は長さ N の非負整数列であり,B[j] (0 \leqq j \leqq N - 1) は参加者 (r-1, j) から参加者 (r, i) に送られた 0 以上 2^{64} 未満の整数 B_{r,i,j} を表す. r = 0 の場合は \texttt{B[j]} = 0 である.
    • この関数は,引数 A, B の情報が与えられたときに参加者 (r, i) のする行動を表す,長さが 1 または N である非負整数列を返さなければならない. 返り値の非負整数列の長さが 1 でも N でもない場合,不正解[1] と判定される.
      • X の値が x であると回答する場合,この関数は長さ 1 の非負整数列 (x) を返さなければならない.回答した値が間違っている場合,不正解[2] と判定される.
      • 回答を行わない場合,この関数は長さ N の非負整数列 B' を返さなければならない.
        • j = 0, 1, \dots, N-1 について,B'[j] は参加者 (r, i) が参加者 (r+1, j) に送る整数 B_{r+1,j,i} を表す. これは 0 以上 2^{64} 未満の整数でなければならない. r = R - 1 のとき参加者 (r+1, j) は存在しないが,その場合でも B' の長さは N でなければならないことに注意せよ.
      • ラウンド R - 1 が終わるまでに,いずれかの参加者が回答を行わなければならない.どの参加者も回答を行わなかった場合,不正解[3] と判定される.
    • この関数の返り値は引数のみから決定しなければならない. 特に,以前の strategy の呼び出しや実行時の乱数によって返り値が変化してはならないことに注意せよ. この関数が同じ引数に対して異なる値を返した場合,不正解[4] と判定される.
    • 与えられる引数は,ある表 A と提出された関数 strategy を使用してゲームを行った際に実際に表れるものであることが保証される. ただし,ラウンド 0, 1, \dots, R - 1 の順に呼び出されるとは限らないことに注意せよ.
    • 採点プログラムは 1 回の実行で 1 回以上のゲームを行う.1 回の実行において,この関数は最大 10\,240 回呼び出される.

重要な注意

  • 内部での使用のために他の関数を実装したり,グローバル変数を宣言するのは自由である.
  • あなたの提出したプログラムは,標準入力・標準出力,あるいは他のファイルといかなる方法でもやりとりしてはならない. ただし,標準エラー出力にデバッグ情報等を出力することは許される.

制約

  • 2 \leqq N \leqq 256
  • 0 \leqq A_{i,j} < 2^{48} (0 \leqq i \leqq N - 10 \leqq j \leqq N - 1).
  • A_{i,i} = 0 (0 \leqq i \leqq N - 1).
  • A_{i,j} = A_{j,i} (0 \leqq i < j \leqq N - 1).
  • N, A_{i,j} (0 \leqq i \leqq N - 10 \leqq j \leqq N - 1) は整数である.

小課題

  1. (5 点) N \leqq 64A_{i,j} \leqq 1 (0 \leqq i \leqq N - 10 \leqq j \leqq N - 1).
  2. (10 点) A_{i,j} \leqq 1 (0 \leqq i \leqq N - 10 \leqq j \leqq N - 1).
  3. (15 点) N \leqq 64
  4. (40 点) A_{i,j} < 2^{20} (0 \leqq i \leqq N - 10 \leqq j \leqq N - 1).
  5. (15 点) A_{i,j} < 2^{40} (0 \leqq i \leqq N - 10 \leqq j \leqq N - 1).
  6. (15 点) 追加の制約はない.

採点基準

ある小課題のテストケースの中で,1 つでも 不正解[1] 〜 [4] と判定されたものや, 実行時間制限超過,メモリ制限超過,実行時エラーと判定されたものがあった場合,その小課題の得点は 0 点となる. それ以外の場合,その小課題のすべてのゲームにわたる,行われたラウンド数の最大値を S として,その小課題の得点は以下のように決定される.

小課題 3 の場合

  • S にかかわらず,その小課題の配点の 100\%S > 6 である場合,コンテストサイトにおいて「出力は部分的に正しい」と表記されることがあるが,得点には影響しない.

小課題 3 以外の場合

  • S \leqq 6 のとき,その小課題の配点の 100\%
  • 7 \leqq S \leqq 9 のとき,その小課題の配点の (100 - 20 \cdot (S - 6))\%
  • 10 \leqq S \leqq 19 のとき,その小課題の配点の (40 - S)\%
  • 20 \leqq S のとき,その小課題の配点の 20\%

コンパイル・実行の方法

作成したプログラムをテストするための,採点プログラムのサンプルが, コンテストサイトからダウンロードできるアーカイブの中に含まれている. このアーカイブには,提出しなければならないファイルのサンプルも含まれている.

採点プログラムのサンプルは 1 つのファイルからなる. そのファイルは grader.cpp である. 作成したプログラムをテストするには, これらのファイル grader.cpp, multi.cpp, multi.h を同じディレクトリに置き,次のようにコマンドを実行する.

g++ -std=gnu++20 -O2 -o grader grader.cpp multi.cpp

なお,アーカイブの中に含まれている compile.sh というファイルを代わりに実行してもよい.その場合,次のようにコマンドを実行する.

./compile.sh

コンパイルが成功すれば,grader という実行ファイルが生成される.

実際の採点プログラムは,採点プログラムのサンプルとは異なることに注意すること. 採点プログラムのサンプルは単一のプロセスとして起動する. このプログラムは,標準入力から入力を読み込み,標準出力に結果を出力する.

採点プログラムのサンプルの入力

採点プログラムのサンプルは 1 回の実行で 1 回以上のゲームを行う.

まず,採点プログラムのサンプルは標準入力からゲームの回数 T を受け取る. その後,T 回にわたって,以下の形式で表 A の情報を読み込む.

N 
A_{0,1} A_{0,2} A_{0,3} \cdots A_{0,N-1} 
A_{1,2} A_{1,3} \cdots A_{1,N-1} 
\vdots 
A_{N-2,N-1} 

採点プログラムのサンプルの出力

採点プログラムのサンプルは標準出力へ T 行出力する. t 行目 (1 \leqq t \leqq T) には t 回目のゲームの結果を以下の形式で出力する (引用符は実際には出力されない).

  • ゲームが成功した場合,そのゲームで行われたラウンド数が Accepted: 22 のように出力される.
  • いずれかの不正解の条件に当てはまった場合,不正解の種類が Wrong Answer [4] のように出力される.

実行するプログラムが複数の不正解の条件を満たした場合,表示される不正解の種類はそれらのうち 1 つのみである.

やりとりの例

採点プログラムのサンプルが読み込む入力の例と,それに対応する関数の呼び出しの例を以下に示す.

入力例 1

1
3
1 2
3

ラウンド 0 では以下のやりとりが行われる.

  • 参加者 (0, 0)X の値を回答せず,参加者 (1, 0)B_{1,0,0} = 0 を,参加者 (1, 1)B_{1,1,0} = 1 を,参加者 (1, 2)B_{1,2,0} = 2 を送る.
  • 参加者 (0, 1)X の値を回答せず,参加者 (1, 0)B_{1,0,1} = 3 を,参加者 (1, 1)B_{1,1,1} = 4 を,参加者 (1, 2)B_{1,2,1} = 5 を送る.
  • 参加者 (0, 2)X の値を回答せず,参加者 (1, 0)B_{1,0,2} = 6 を,参加者 (1, 1)B_{1,1,2} = 7 を,参加者 (1, 2)B_{1,2,2} = 8 を送る.

どの参加者も X の値を回答しなかったので,ゲームは次のラウンドに進む.

ラウンド 1 では以下のやりとりが行われる.

  • 参加者 (1, 0) は参加者 (0, 0) から B_{1,0,0} = 0 を,参加者 (0, 1) から B_{1,0,1} = 3 を,参加者 (0, 2) から B_{1,0,2} = 6 を受け取り,X = 3 であると回答する. X の値を回答したため,この時点でゲームは終了する.

正しい X の値を回答したため,ゲームは成功となる.このゲームで行われたラウンド数は 2 である.

この入力例は小課題 3, 4, 5, 6 の制約を満たす.

コンテストサイトからダウンロードできるファイルのうち,sample-01-in.txt は入力例 1 に対応する. また,コンテストサイトからダウンロードできるアーカイブの中には,さらなる入力例 sample-02-in.txt, sample-03-in.txt, sample-04-in.txt が存在する. sample-02-in.txt はすべての小課題の制約を満たし, sample-03-in.txt は小課題 3, 4, 5, 6 の制約を満たし, sample-04-in.txt は小課題 4, 5, 6 の制約を満たす.