You are on page 1of 2

31/10/2023, 10:38 Problem - C - Codeforces

Enter | Register

HOME TOP CATALOG CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP ICPC CHALLENGE

PROBLEMS SUBMIT CODE MY SUBMISSIONS STATUS HACKS ROOM STANDINGS CUSTOM INVOCATION

Codeforces Round 906 (Div. 2)


C. Qingshan Loves Strings 2 Finished
time limit per test: 1 second
memory limit per test: 256 megabytes → Practice?
input: standard input
Want to solve the contest problems after the
output: standard output official contest ends? Just register for
practice and you will be able to submit
Qingshan has a string s which only contains 0 and 1. solutions.

A string a of length k is good if and only if Register for practice

ai ≠ ak−i+1 for all i = 1, 2, … , k .


→ Virtual participation 
For Div. 2 contestants, note that this condition is different from the condition in problem B.
Virtual contest is a way to take part in past
For example, 10 , 1010, 111000 are good, while 11 , 101, 001, 001100 are not good. contest, as close as possible to participation
on time. It is supported only ICPC mode for
virtual contests. If you've seen these
Qingshan wants to make s good. To do this, she can do the following operation at most 300 problems, a virtual contest is not for you -
times (possibly, zero): solve these problems in the archive. If you
just want to solve some problem from a
contest, a virtual contest is not for you -
insert 01 to any position of s (getting a new s ). solve this problem in the archive. Never use
someone else's code, read the tutorials or
communicate with other person during a
Please tell Qingshan if it is possible to make s good. If it is possible, print a sequence of virtual contest.
operations that makes s good.
Start virtual contest
Input
The input consists of multiple test cases. The first line contains a single integer t (
1 ≤ t ≤ 100 ) — the number of test cases. The description of the test cases follows. → Problem tags

The first line of each test case contains a single integer n (1 ≤ n ≤ 100 ) — the length of constructive algorithms implementation
string s , respectively. No tag edit access

The second line of each test case contains a string s with length n.
→ Contest materials
It is guaranteed that s only consists of 0 and 1.
Announcement (en)
Output
For each test case, if it impossible to make s good, output −1. Tutorial (en)

Otherwise, output p (0 ≤ p ≤ 300 ) — the number of operations, in the first line.

Then, output p integers in the second line. The i -th integer should be an index x i (
0 ≤ x i ≤ n + 2i − 2) — the position where you want to insert 01 in the current s . If

x i = 0 , you insert 01 at the beginning of s . Otherwise, you insert 01 immediately after the x i

-th character of s .

We can show that under the constraints in this problem, if an answer exists, there is always an
answer that requires at most 300 operations.

Example
input Copy

6
2
01
3
000
4
1111
6
001110
10
0111001100
3
001

output Copy

https://codeforces.com/contest/1890/problem/C 1/2
31/10/2023, 10:38 Problem - C - Codeforces
0

-1
-1
2
6 7
1
10
-1
Note
In the first test case, you can do zero operations and get s = 01 , which is good.

Another valid solution is to do one operation: (the inserted 01 is underlined)

1. 0011
–––

and get s = 0011 , which is good.

In the second and the third test case, it is impossible to make s good.

In the fourth test case, you can do two operations:

1. 00111001
–––
2. 0011100011
–––

and get s = 0011100011 , which is good.

Codeforces (c) Copyright 2010-2023 Mike Mirzayanov


The only programming contests Web 2.0 platform
Server time: Oct/30/2023 14:56:29UTC+5.5 (k1).
Desktop version, switch to mobile version.
Privacy Policy

Supported by

https://codeforces.com/contest/1890/problem/C 2/2

You might also like