0% found this document useful (0 votes)
3 views

Problem - A122 - Codeforces

The document describes a problem from Codeforces involving a binary string where the goal is to determine the minimum number of operations required to change all characters in the string to 0. Each operation allows the selection of a non-empty subsequence of characters that are different and flipping them. The input consists of multiple test cases, and the output is the minimum number of operations for each case.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Problem - A122 - Codeforces

The document describes a problem from Codeforces involving a binary string where the goal is to determine the minimum number of operations required to change all characters in the string to 0. Each operation allows the selection of a non-empty subsequence of characters that are different and flipping them. The input consists of multiple test cases, and the output is the minimum number of operations for each case.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

3/9/25, 10:20 PM Problem - A - Codeforces

Enter | Register

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

 Codeforces Blitz Cup 2025 Final Rounds Have Started! Join the stream now: https://youtu.be/rbHFLNg7Nkc. ×

PROBLEMS SUBMIT CODE MY SUBMISSIONS STATUS HACKS ROOM STANDINGS CUSTOM INVOCATION

Ethflow Round 1 (Codeforces


A. String Round 1001, Div. 1 + Div. 2)

time limit per test: 1 second Finished


memory limit per test: 512 megabytes
→ Practice?
You are given a string s of length n consisting of 0 and/or 1. In one operation, you can select a non-
empty subsequence t from s such that any two adjacent characters in t are different. Then, you flip each Want to solve the contest problems after the
official contest ends? Just register for
character of t (0 becomes 1 and 1 becomes 0). For example, if s = 00101 and practice and you will be able to submit

– ––––
t = s1 s3 s4 s5 = 0101 , after the operation, s becomes 10010 . solutions.

– ––––

Calculate the minimum number of operations required to change all characters in s to 0. Register for practice

Recall that for a string s = s1 s2 … sn , any string t = si si


1 2
… si
k
(k ≥ 1 ) where
1 ≤ i1 < i2 < … < ik ≤ n is a subsequence of s . → Virtual participation 
Input Virtual contest is a way to take part in past
contest, as close as possible to participation
The first line of input contains a single integer t (1
4
≤ t ≤ 10 ) — the number of input test cases. on time. It is supported only ICPC mode for
virtual contests. If you've seen these
The only line of each test case contains the string s (1 ≤ |s| ≤ 50 ), where |s| represents the length of problems, a virtual contest is not for you -
solve these problems in the archive. If you
s. just want to solve some problem from a
contest, a virtual contest is not for you -
solve this problem in the archive. Never use
Output someone else's code, read the tutorials or
For each test case, output the minimum number of operations required to change all characters in s to 0. communicate with other person during a
virtual contest.

Example
Start virtual contest
input Copy

https://codeforces.com/contest/2062/problem/A 1/2
3/9/25, 10:20 PM Problem - A - Codeforces

5 → Problem tags
1
000
constructive algorithms greedy math
1001
10101 strings *800
01100101011101 No tag edit access

output Copy

1 → Contest materials
0
2
Announcement (en)
3
8 Tutorial (en)
Note
In the first test case, you can flip s1 . Then s becomes 0, so the answer is 1.

In the fourth test case, you can perform the following three operations in order:

1. Flip s1 s2 s3 s4 s5 . Then s becomes 01010 .


––––––
2. Flip s2 s3 s4 . Then s becomes 0010 0.
––––
3. Flip s3 . Then s becomes 00000.

It can be shown that you can not change all characters in s to 0 in less than three operations, so the
answer is 3.

Codeforces (c) Copyright 2010-2025 Mike Mirzayanov


The only programming contests Web 2.0 platform
Server time: Mar/09/2025 22:20:34UTC+7 (l2).
Desktop version, switch to mobile version.
Privacy Policy

Supported by

https://codeforces.com/contest/2062/problem/A 2/2

You might also like