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

11114번 - Paper 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 256 MB2875100.000%

문제

Nils is preparing his Master’s thesis, and wants to include the source code for his new logarithmic-time halting problem solver. To minimize the environmental impact of the inevitable millions of printouts of his revolutionary paper around the world, he wants to make his program as short as possible.

You will help by designing an expression optimizer for boolean expressions. The input will be a fully parenthesized expression, using the standard one-character boolean operators (&, | and !).

For each expression, print the length of the shortest equivalent expression (not including spaces).

expression ::= variable
 | ’(’ expression ’ ’ operator ’ ’ expression ’)’
 | ’!’ expression
operator ::= ’&’ | ’|’
variable ::= ’x’ | ’y’ | ’z’

Note in particular that parentheses are required for all operators. This means that each operator will contribute three characters to the length, whereas NOTs and variable references contribute one character each.

입력

The input has 1 ≤ n ≤ 50 cases, where n is given by the first line of input. Each test case is given by a line with an expression as decribed earlier. Each expression will be no more than 500 characters long (including spaces).

출력

For each test case output the length of the shortest equivalent expression.

제한

예제 입력 1

3
(((x & !y) & (y & !z)) & (z & !x))
((x & z) | (y & z))
!((!x & !y) | !z)

예제 출력 1

6
9
9

힌트

In the example, the first expression is never true. It can be written as (x & !x), which has a length of 6. The third example can be simplified by applying De Morgan’s law twice (after which it becomes equivalent to the second example).

출처

Contest > IDI Open Contest > IDI Open 2008 G번

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

출처

대학교 대회

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

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