Problems - Codeforces
Problems - Codeforces
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?
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 .
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 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