문제
Farmer John has a boolean statement that is
A phrase of the form
x andy : This evaluates to true if bothx andy are true, and false otherwise.x ory : This evaluates to true if eitherx ory is true, and false otherwise.
When evaluating the statement, FJ has to take the order of precedence in Moo Language into account. Similar to C++, and takes priority over or. More specifically, to evaluate the statement, repeat the following step until the statement consists of only one keyword.
If the statement contains an and, choose any of them and replace the phrase surrounding it with its evaluation.
Otherwise, the statement contains an or. Choose any of them and replace the phrase surrounding it with its evaluation.
It may be proven that if multiple phrases can be evaluated during a given step, it does not matter which one is chosen; the statement will always evaluate to the same value.
FJ has
입력
The first line contains
The next line contains
The following
출력
Output a string of length
부분문제
| 번호 | 점수 | 조건 |
|---|---|---|
| #1 | 20점 | |
| #2 | 30점 | |
| #3 | 50점 | 추가 제약 조건 없음 |
예제 #1
5 7
false and true or true
1 1 false
1 3 true
1 5 false
3 3 true
3 3 false
5 5 false
5 5 true
NYYYNYY
Let's analyze the first query:
If we were to replace delete the segment
true and true or true
We evaluate the and keyword from at position
true or true
Since we have no and keywords left, we have to evaluate the or keyword. After evaluation, all that is left is
true
It can be shown that if we were to replace the segment with false, the statement will still evaluate to true, so we output N since the statement cannot possibly evaluate to false.
For the second query, we can replace the segment
For the third query, since
예제 #2
13 4
false or true and false and false and true or true and false
1 5 false
3 11 true
3 11 false
13 13 true
YNYY