#P4249. [WC2007] 剪刀石头布
[WC2007] 剪刀石头布
Description
In some one-on-one game competitions (such as chess, table tennis, and badminton singles), we often encounter the interesting situation where beats , beats , and beats . Let us vividly call this the rock-paper-scissors situation. Sometimes, people will enthusiastically count how many such rock-paper-scissors situations occur, that is, how many unordered triples satisfy that one person beats another, the second beats the third, and the third beats the first. Note that unordered means the order of elements in the triple does not matter, and , , , , , and are regarded as the same situation.
There are people participating in such a competition. The schedule requires that every pair of people plays exactly one match, so there are a total of matches. Some matches have already been played. We want to know, in the extreme case, what is the maximum possible number of rock-paper-scissors situations after all matches are completed. That is, given the results of the matches that have already taken place, you may assign the outcomes of the remaining matches arbitrarily to obtain as many rock-paper-scissors situations as possible.
Input Format
The first line contains an integer , the number of participants.
Then follows an -by- numeric matrix: rows, each with columns, and numbers separated by spaces.
In row and column , if the number is , it means has already beaten ; if the number is , it means has already lost to ; if the number is , it means the match between and has not yet taken place. The numbers on the diagonal, i.e., the number in row and column , are all . They are merely placeholders and have no meaning.
The input is guaranteed to be valid and without contradictions. When , the two numbers at row , column and row , column are either both , or one is and the other is .
Output Format
The first line contains an integer, indicating how many rock-paper-scissors situations occur in your arranged set of match results.
Starting from line , output an -by- numeric matrix in the same format as the input. The number in row and column describes the result of the match between and : means beats , and means loses to . Unlike the input matrix, there is no number indicating an unplayed match; the diagonal numbers are all . The output matrix must be valid and free of contradictions.
3
0 1 2
0 0 2
2 2 0
1
0 1 0
0 0 1
1 0 0
Hint
- Scoring criteria: For each test point, you will receive full credit only if the first line of your output matches the standard answer and you provide a valid arrangement consistent with it. Otherwise, you will receive points for that test point.
- Constraints: For of the testdata, . For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号