Logo
(追記) (追記ここまで)

31951번 - Comparator 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 (추가 시간 없음) 2048 MB (추가 메모리 없음)27212090.909%

문제

Many programming languages let you define custom comparators to sort user-defined objects.

IFFY is a programming language where the only programs are functions intended to be comparators. These functions operate on bitstrings, hereafter called "words". Words are 1-indexed starting with the leftmost character.

To write a function on two words in IFFY, the programmer writes a series of if-statements. Each if statement chooses a bit from the first word, a bit from the second word, and evaluates some expression on those two bits. If the expression evaluates to 1ドル$ on those chosen bits, then the function returns immediately with a specified return value. Otherwise, execution falls through to the next if statement, not returning anything.

The syntax of each if statement is $a$ $b$ expr $r,ドル where the integer $a$ specifies a bit from the first word, integer $b$ specifies a bit from the second word, and expr is a boolean expression using variables $x$ and/or $y,ドル and $r$ is the value (0ドル$ or 1ドル$) returned from the function if the expression evaluates to 1ドル$. The variable $x$ refers to the specified bit in the first word, and the variable $y$ refers to the specified bit in the second word. For example, consider the if statement '2 3 x|y 0'. This expression means: if the second bit of the first word or the third bit of the second word is set, then return 0ドル,ドル otherwise continue with the next statement.

The grammar for valid expressions is as follows:

  • $x,ドル $y,ドル 0, and 1 are valid expressions.
  • If E is a valid expression, then (E) is a valid expression.
  • If E is a valid expression, then !E is a valid expression.
  • If E1 and E2 are valid expressions, then all strings of the form E1 BIN_OP E2 are valid expressions, where BIN_OP is one of = (equals), & (and), | (or), or ^ (xor).

Parentheses take highest precedence, followed by the unary !, followed by the binary =, &, |, and ^, in that order. All binary operators are left-associative.

Here are the truth tables for each operator:

Figure C.1: The truth table for the sole unary operator.

Figure C.2: Truth tables for the binary operators.

In order for a function $f(x,y)$ to operate properly as a comparator, it must satisfy certain properties. Informally, for $f(x,y)$ to be a comparator, it should impose some ordering $<,ドル where $f(x,y)$ returns 1ドル$ if and only if $x < y$. For example, sample 1ドル$ is a valid comparator to sort bitstrings of length 2ドル$. More formally, three of the properties that comparators must satisfy are the reflexive, symmetric, and transitive properties, as follows:

  1. Reflexive: For all $x,ドル $f(x, x)$ should return 0.
  2. Symmetric: For all $x,y,ドル if $f(x, y)$ returns 1, then $f(y, x)$ must return 0.
  3. Transitive: For all $x,y,z,ドル if both $f(x, y)$ and $f(y, z)$ return 1, then so must $f(x, z)$.

Given a function in the IFFY language, determine how well it satisfies these three properties by counting how often they are violated. First, among all words of a given length, count the number of words for which the reflexive property fails. Next, count the number of pairs of words for which the symmetric property fails. Finally, count the number of triples of words for which the transitive property fails.

입력

The first line of input contains two integers $n$ (0ドル \leq n \leq 2 \cdot 10^{5}$) and $k$ (1ドル \leq k \leq 10$), where $n$ is the number of lines in the function and $k$ is the number of bits in the values being compared.

Each of the next $n$ lines contains four tokens of the form $a$ $b$ expr $r,ドル where $a$ and $b$ (1ドル \leq a, b \leq k$) are the indices of the bits to consider in $x$ and $y,ドル expr is a valid expression, and $r$ (0ドル \leq r \leq 1$) is the return value. The final line gives the returned value if no if statement is triggered. The total length of all expressions is at most 10ドル^6$.

출력

Output a single line with three space separated integers. The first integer is the number of words for which the reflexive property is violated, the second is the number of pairs of words for which the symmetric property is violated, and the third is the number of triples of words for which the transitive property is violated.

제한

예제 입력 1

3 2
1 1 (x=0)&(y=1) 1
1 1 (x=1)&(y=(x^x)) 0
2 2 (x=1)|(y=0) 0
1

예제 출력 1

0 0 0

예제 입력 2

4 3
2 1 x=0&(y=1) 1
1 2 !x^!!y 0
2 3 ((x|1)=y)&1&1 1
3 1 !x&!x&!x 0
1

예제 출력 2

3 25 52

힌트

출처

ICPC > Regionals > North America > North America Championship > North America Championship 2024 C번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /