A. CS240 project Problem 1

    Type: Default 1000ms 256MiB

CS240 project Problem 1

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

Problem Statement

Consider an endlessly repeating sequence of keys, analogous to an infinite piano keyboard. This sequence follows a specific pattern that repeats indefinitely: wbwbwwbwbwbw. You need to determine if a continuous section of this sequence can be found which includes exactly W white keys (denoted by w) and B black keys (denoted by b).

Details

  • The pattern for the sequence is: wbwbwwbwbwbw.
  • Your task is to identify whether there is a substring in this infinite sequence that contains exactly W 'w' characters and B 'b' characters.

Constraints

  • N: An integer such that 0N100 \leq N \leq 10
  • W: An integer such that 0W1000 \leq W \leq 100
  • B: An integer such that 0B1000 \leq B \leq 100
  • The sum of W and B must be at least 1 (W+B1W + B \geq 1), ensuring that you are always looking for a non-empty segment.

Input

The input is given from Standard Input in the following format:

N
W1 B1
W2 B2
...
WN BN

Here, N denotes the number of queries. Each line after the first specifies a pair of integers Wi and Bi, which represent the numbers of 'w' and 'b' characters to check for in the string S respectively.

Output

For each query, if there is a contiguous substring in S that contains exactly Wi 'w' characters and Bi 'b' characters, output Yes; otherwise, output No.

F1 F2 ... FN

Sample Input 1

1
3 2

Sample Output 1

Yes

The first 15 characters of SS are wbwbwwbwbwbwwbw. You can take the 11-th through 15-th characters to form the string bwwbw, which is a substring consisting of three occurrences of w and two occurrences of b.

Sample Input 2

2
3 0
10 2

Sample Output 2

No No

The only string consisting of three occurrences of w and zero occurrences of b is www, which is not a substring of SS.

Sample Input 3

3
92 66
1 3
3 1

Sample Output 3

Yes No Yes

CS240 2024 Spring Project Problem

Not Attended
Status
Done
Rule
IOI
Problem
4
Start at
2024-5-30 17:00
End at
2024-6-24 23:59
Duration
607 hour(s)
Host
Partic.
99