[ABC261B] Tournament Result

Problem Statement

$N$ players played a round-robin tournament.

You are given an $N$-by-$N$ table $A$ containing the results of the matches. Let $A_{i,j}$ denote the element at the $i$-th row and $j$-th column of $A$.
$A_{i,j}$ is - if $i=j$, and W, L, or D otherwise.
$A_{i,j}$ is W if Player $i$ beat Player $j$, L if Player $i$ lost to Player $j$, and D if Player $i$ drew with Player $j$.

Determine whether the given table is contradictory.

The table is said to be contradictory when some of the following holds:

  • There is a pair $(i,j)$ such that Player $i$ beat Player $j$, but Player $j$ did not lose to Player $i$;
  • There is a pair $(i,j)$ such that Player $i$ lost to Player $j$, but Player $j$ did not beat Player $i$;
  • There is a pair $(i,j)$ such that Player $i$ drew with Player $j$, but Player $j$ did not draw with Player $i$.

Constraints

  • $2 \leq N \leq 1000$
  • $A_{i,i}$ is -.
  • $A_{i,j}$ is W, L, or D, for $i\neq j$.

Input

Input is given from Standard Input in the following format:

$N$
$A_{1,1}A_{1,2}\ldots A_{1,N}$
$A_{2,1}A_{2,2}\ldots A_{2,N}$
$\vdots$
$A_{N,1}A_{N,2}\ldots A_{N,N}$

Output

If the given table is not contradictory, print correct; if it is contradictory, print incorrect.


Sample Input 1

4
-WWW
L-DD
LD-W
LDW-

Sample Output 1

incorrect

Player $3$ beat Player $4$, while Player $4$ also beat Player $3$, which is contradictory.


Sample Input 2

2
-D
D-

Sample Output 2

correct

There is no contradiction.

如果 \(a_{i,j}=D,a_{j,i}=D\)
如果 \(a_{i,j}=L,a_{j,i}=W\)
判定即可。

#include<cstdio>
int n;
char s[1005][1005]; 
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%s",s[i]+1);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(i!=j)
			{
				if(s[i][j]=='W'&&s[j][i]!='L')
				{
					printf("incorrect");
					return 0;
				}
				if(s[i][j]=='L'&&s[j][i]!='W')
				{
					printf("incorrect");
					return 0;
				}
				if(s[i][j]=='D'&&s[j][i]!='D')
				{
					printf("incorrect");
					return 0;
				}
			}
		}
	}
	printf("correct");
}
posted @ 2022-09-04 21:16  灰鲭鲨  阅读(41)  评论(0编辑  收藏  举报