All MicroEvals
codeforces around 1138 div3 question C response accuracy check
Create MicroEval

codeforces around 1138 div3 question C response accuracy check

Prompt

C. Finding Shapes in the Clouds time limit per test2 seconds memory limit per test256 megabytes After eating and settling down on a soft blanket by the lake, Sunny and Aubrey began gazing at the sky. The friends noticed an unusual long band of n clouds, where each cloud is either fluffy and white (represented as "0") or thin and dark (represented as "1"). Let s be the current string of cloud types. While watching the sky, Aubrey noticed an unusual phenomenon: when gusts of wind blow through the cloud band, a "cloud swirl" occurs. In one cloud swirl, the friends can choose two clouds at positions i and j (1≤i<j≤|s| ) that have the same type (si=sj ). As a result of this wind: Both selected clouds si and sj dissipate and completely disappear from the band. All clouds located strictly between them (at positions from i+1 to j−1 ) invert their type due to turbulence: a white cloud ("0") becomes dark ("1"), and a dark cloud ("1") becomes white ("0"). The remaining clouds keep their order and are renumbered starting from one. Can the friends make the cloud band empty by applying this operation? Input Each test consists of multiple test cases. The first line contains an integer t (1≤t≤104 ) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer n (1≤n≤2⋅105 ) — the initial length of the cloud band. The second line contains a binary string s of length n consisting only of characters '0' and '1'. The sum of n over all test cases does not exceed 2⋅105 . Output For each test case, print YES if the sky can be completely cleared of clouds, and NO otherwise. You can output each letter in any case (for example, YES, Yes, yes will be recognized as a positive answer). Example InputCopy 7 4 0000 4 0101 6 011010 2 01 3 000 4 1000 6 010001 OutputCopy YES NO YES NO NO YES YES Note In the third test case, remove the clouds at positions 1 and 4 in 011010. After the inversion the band reads 0010. Removing positions 2 and 4 now leaves 00, whose two clouds can disappear together. In the fourth test case the two clouds have different types, so there is no legal first move. please solve the above questions in python and c++

Drag to resize