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

Problems - Codeforces

The document outlines multiple programming challenges, each with specific tasks and constraints. These include counting integers based on XOR properties, determining the safety of a Tetris-like game, constructing matrices with certain properties, finding colorful paths in a directed graph, and converting binary strings to a 'Good String' with minimal cost. Additionally, it describes a game scenario between Alice and Bob involving selling items from shelves, where the winner is determined based on optimal play.

Uploaded by

jaydatt19
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Problems - Codeforces

The document outlines multiple programming challenges, each with specific tasks and constraints. These include counting integers based on XOR properties, determining the safety of a Tetris-like game, constructing matrices with certain properties, finding colorful paths in a directed graph, and converting binary strings to a 'Good String' with minimal cost. Additionally, it describes a game scenario between Alice and Bob involving selling items from shelves, where the winner is determined based on optimal play.

Uploaded by

jaydatt19
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

CPL ROUND - 1.

2 (3rd-4th Year)

A. Elon's Quest 12 : XOR at even indices (1) vs. XOR at odd indices (2). Condition
not satisfied.
1 second, 256 megabytes
13 : XOR at even indices (1) vs. XOR at odd indices (3). Condition

In a mystical land of numbers, a curious robot named Elon wants to find not satisfied.
hidden treasures between two magical numbers, a and b. Elon has a 14 : XOR at even indices (1) vs. XOR at odd indices (4). Condition
special task: it needs to count how many integers in this range have the not satisfied.
following property: the XOR of the digits at even positions (counting from 15 : XOR at even indices (1) vs. XOR at odd indices (5). Condition

the left, starting at 0 meaning zero-based indexing) is strictly greater than not satisfied.
the XOR of the digits at odd positions.
So, there is 1 number in the range [10, 15] that meets the condition,
Can you help Elon by counting these special integers and guiding it to resulting in an output of 1.
the treasure?

Input B. Zero Risk, Full Loss


The first line contains a single integer T . (1 ≤ T ≤ 10 )
3
2 s., 1024 MB
For each test case contain a single line with two integers a and b.
9
If you've ever played Tetris for long enough, you might have experienced
(1 ≤ a ≤ b ≤ 10 )
the Tetris effect – seeing falling blocks even after you have stopped
playing. To stay focused on solving problems and avoid such distractions,
Output
For each test case, output a single integer, the count of integers in the we will consider a simplified version of the game.
range [a, b] satisfying the condition. The game is played on a board composed of square cells arranged in a
grid. Columns of the grid are numbered sequentially from left to right. The
input board is infinite to the right and to the top. Each cell is either empty or
1 filled, and initially, all cells are empty.
10 15
A sequence of N rectangular pieces is given, and the pieces are dropped
output onto the board one at a time. Pieces have different sizes. A piece of size
1 L is either vertical (L × 1 cells) or horizontal (1 × L cells). When a piece

is dropped at a specified column, it starts at a location above all the


The integers in the range [10, 15] are: 10, 11, 12, 13, 14, and 15 currently filled cells and falls straight down until it either reaches the
bottom of the board or lands on top of an already filled cell. Once a piece
For each integer:
lands, it fills its final set of cells.
10 : XOR at even indices (1) vs. XOR at odd indices (0). Condition
satisfied.
11 : XOR at even indices (1) vs. XOR at odd indices (1). Condition

not satisfied.
Each time a piece lands, the game is considered safe if no empty cell has output
a filled cell above it; otherwise the game is unsafe, the offending piece is
SUSS
removed from the board, and the game continues with the next piece as if
it had never been dropped.
input
In the example below, corresponding to the first sample input, the game
4
becomes unsafe once the second piece lands, hence the piece is | 3 1
removed and the next pieces keep the game safe. | 2 3
| 1 2
- 2 2

output
SSSU

Given the sequence of pieces and their drop positions, your task is to C. Greatest Common Delirium
determine, for each piece, whether it makes the board unsafe after
landing. 1 s., 256 MB
Input You are given an integer n. You need to construct an n × n matrix a that
The first line contains an integer N (1
5
≤ N ≤ 2 ⋅ 10 ), indicating the satisfies all of the following conditions :
number of pieces.
1 ≤ ai,j ≤ 1000 for all 1 ≤ i, j ≤ n.
Each of the next N lines describes a piece with a character C and two
gcd(ai,j , i + j) > 1 for all 1 ≤ i, j ≤ , here gcd means greatest
n
integers L and P (1 ≤ L ≤ 109 and 1 ≤ P ≤ 1018 ), representing
common divisor.
respectively the type of the piece, its length, and the position where it is
dropped. For a vertical piece, C is the character '|' (pipe), the piece has The bitwise XOR of all numbers of the matrix a equals 0.
L × 1 cells, and it is dropped at column P . For a horizontal piece, C is
Input
the character '-' (hyphen), the piece has 1 × L cells, and it is dropped
The first line of input contains an integer t (1 ≤ t ≤ 100) — the number
spanning columns P , P + 1, … , P + L − 1 .
of testcases.
Output The first line of each testcase contains a single integer n
Output a single line with a string of length N . The i -th character of the (2 ≤ n ≤ 500) .
string must be the uppercase letter 'U' if the game becomes unsafe
immediately after the i -th piece lands on the board, and the uppercase It is guaranteed that the sum of n over all testcases does not exceed 500.
letter 'S' otherwise.
Output
For each testcase, print an n × n matrix a that satisfies all the given
input conditions.
4
| 3 1 If there are multiple answers, print any one of them.
- 2 1
| 3 2
It can be proved that atleast one such matrix exists under the given
- 2 1 constraints.
input input
2 4
2 5 6
3 1 2 1
2 3 1
output 2 4 2
12 12 4 2 3
12 12 3 4 3
4 6 8 3 5 1
3 2 5 3 2
2 10 6 1 3 1
2 1 1
5 5
1 2 1
D. Colorful Paths 2 3 2
3 4 3
3 seconds, 256 megabytes
4 2 2
2 5 1
You are given a directed graph with n nodes and m edges. The color of 1 0
the i -th edge is ci .
output
We call a path (does not have to be a simple path) colorful iff it does not
1 2 3 4
have two consecutive edges of the same color. 1 3
1 2 3 4 5
Find all nodes x such that there exist a colorful path starting from 1 and 1
ending at x .

Input E. The Costly Conversion


The first line of the input contains a single integer t (1 ≤ t ≤ 10 ) — the
5

number of test cases. The description of the test cases follows. 1 s., 256 MB

The first line of each test case contains two integers n and m ( Yugandhar bought a binary string† S of length n for Diya's birthday gift.
1 ≤ n ≤ 10
6
,0 ≤ m ≤ 10
6
) — the number of nodes and the number But later he knows that Diya likes only binary strings if it doesn't contain
of edges. 01 and 10 as substrings, and termed it as Good String.

Next m lines describe edges: i -th line contains three integers u i , vi , ci ( To make a string good, there are two possible operations available for
1 ≤ u i , vi , ≤ n; u i ≠ vi ; 1 ≤ ci ≤ m ) — defining the edge from u i to Yugandhar.
vi of color ci .
1. Choose a character and flip it(change 0 to 1 and vice-
The sum of n and the sum of m over all test cases does not exceed 10 . 6
versa).
Output 2. Choose characters from two different positions in the string, and
For each test case, output all the nodes x such that there exist a colorful replace these characters with their XOR value.
path starting from 1 and ending at x in ascending order.
Operation 1 costs a coins and Operation 2 costs b coins. 1 second, 256 megabytes
Yugandhar doesn't have too much money. So he wants to convert the
given string to Good String using minimum number of coins. Alice and Bob are competing for the "Employee of the Month" title at their
store. The manager has organized a friendly competition based on selling
Can you help Yugandhar with minimum number of coins needed to items from store shelves. The details are as follows:
convert the string Good?
There are n shelves in the store, and each shelf i initially contains ai
A binary string is a string which only contains 0

and 1 s .
† ′
s
items.
Input Alice and Bob take turns assisting customers, with Alice going first.
Each test contains multiple test cases. The first line contains the number
On each turn, they convince a customer to buy any number of items in
of test cases t (1 ≤ t ≤ 10 ). The description of the test cases follows.
the range [1, x], where x is the number of distinct prime factors of ai .
The first line of each testcase contains three integers n, a, b ( After selling y items (where y ∈ [1, x]), the count on that shelf is
3
), the length of binary string, number of coins required
1 ≤ n, a, b ≤ 10 updated to ai := ai − y.
for operation 1, number of coins required for operation 2 The game ends when it is a player's turn, and all shelves contain 0
respectively. items. The player who cannot make a sale loses the game.
The second line of each testcase contains a binary string S of length n. Your task is to determine the winner, assuming both play optimally.
Output Note: Prime factors are considered from 2 onward. If a shelf has exactly
For each test case, print a single integer — the minimum number of coins one item, the number of prime factors is considered to be 1.
needed to convert the given string to Good String
Input
input
The first line contains integer T , number of test cases.
4 3
(1 ≤ T ≤ 10 )
2 1 1
10 Each test case contains:
3 2 1
110 The first line contains a single integer N , number of shelves.
4 4 2 5
(1 ≤ N ≤ 2 ⋅ 10 )
1010
6 5 6 The second line contains N integers ai (1 ≤ ai ≤ 10 )
6

110011
It is guaranteed that the sum of N across all test cases does not exceed
output 5
10 .
1
1 Output
2 For each test case, output who wins, Alice or Bob.
10

st
In the 1 testcase, It is optimal to convert the first character of the given
string using Operation 1. So the total coins spent are 1.

F. Employee Showdown
input
3
2
2 3
2
6 10
3
30 7 1

output
Alice
Bob
Bob

In the first test case, the move sequence leading to Alice's win among
many other is:

Alice sells 1 item from shelf2 making the array = [2, 2]


Bob sells 1 item from shelf1 resulting in array = [1, 2]
Alice sells 1 item from shelf1 resulting in array = [0, 2]
Bob sells 1 item from shelf1 resulting in array = [0, 1]
Alice sells 1 item from shelf1 resulting in array = [0, 0]

Alice sold the last item in the whole store, leaving Bob not able to sell any
item. Alice wins.

There is no other optimal play by Alice and Bob resulting in Bob's win in
this case.
Codeforces (c) Copyright 2010-2025 Mike Mirzayanov
The only programming contests Web 2.0 platform

You might also like