0% found this document useful (0 votes)
122 views5 pages

Problems - Codeforces: Input Output

Uploaded by

dyugbuyhgb
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)
122 views5 pages

Problems - Codeforces: Input Output

Uploaded by

dyugbuyhgb
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/ 5

Problems - Codeforces https://sitstar.contest.codeforces.com/group/v...

SIT STAR Contest 2020

A. Julia and Numbers input


1 second, 256 megabytes 7 9 3 8 0

Favorite numbers of Julia are numbers 3 and 7. She sympathizes with all output
numbers that are divisible by 3 or 7 (or even both of these numbers). 0
Thus, the beginning of the sequence of numbers, which Julia sympathizes
with, is: 3, 6, 7, 9, 12 , 14 , 15 , 18 , 21 , 24 ...
C. Unsorted Array
Find the k-th number among those whom Julia sympathizes with.
1 second, 256 megabytes
Input
The only line of the input contains an integer k (1 ≤ k ≤ 100). Peter does not like sorted arrays, so he asked you to build the permutation
of numbers 1, 2, … , n, such that there would be no segment of size k
Output that would be sorted (in ascending or descending order). Help him to find
Print the k-th positive integer number from the sequence of 3 and/or such permutation or tell that it is impossible.
7-divisible numbers.
A permutation of numbers 1, 2, … , n is an array of n elements such that
every integer from 1 to n appears in it exactly once.
input
2 Input
Input contains two integers n and k (2 ≤ k ≤ n ≤ 1000).
output
6
Output
Print the desired permutation, or −1 if it is not possible. If there are
multiple solutions, print any of them.
input
9
input
output 7 4
21
output
1 7 2 4 6 5 3
input
11
input
output 10 2
27
output
-1
B. Workstations
1 second, 256 megabytes input
4 3
To decide how many participants to invite to the final round of the
programming contest, the organizers first decided to see how many output
workstations they can assemble. After examining the equipment in the 4 1 3 2
warehouse, they found a desktop computers, b monitors, c all-in-one
computers, d keyboards and e mice. In order to assemble a single
workstation, you need one of the following sets:
D. Skis
2 seconds, 256 megabytes
desktop computer, monitor, keyboard, mouse
all-in-one computer, keyboard, mouse Skiing is very popular in Switzerland. The most popular ski resort has only
n skis, the size of the i -th ski is si . You think that skis are not divided into
Help the organizers find out how many workstations they can assemble. left and right and that two skis can be paired if the absolute difference of
Input their sizes does not exceed k. Formally, two skis i and j can be paired if
The input contains five integers a, b, c, d, e. All numbers are in range i ≠ j and |si − sj | ≤ k.
from 0 to 100, inclusive.
Your task is to compose the maximum number of ski pairs.
Output
Print the number of workstations. Input
≤ n ≤ 2 ⋅ 105 ,
The first line contains two numbers n and k (1
input 0 ≤ k ≤ 109 ) — the number of skis and the maximal difference of ski
sizes in a pair.
5 4 3 10 8

output The second line contains the integer sizes s1 , s2 , … , sn


(1 ≤ si ≤ 109 ).
7
Output
input In the first line print p — the maximum number of ski pairs you can
compose. The following p lines should contain pairs of integers xj , yj
10 8 0 5 6
(1 ≤ xj , yj ≤ n ) meaning that the j -th pair contains the xj -th and yj -th
output skis. All numbers xj and yj should be distinct. You can print pairs (as well
5 as numbers in a pair) in any order. If there are multiple solutions, print any
of them.

1 of 5 17/06/20, 1:42 pm
Problems - Codeforces https://sitstar.contest.codeforces.com/group/v...

input input
8 1 1 8
9 7 1 2 6 1 2 7 #..#...#

output output
3 A..B...C
4 6
8 2
7 3 input
5 7
##.....
input
##.###.
5 5 .......
5 4 3 2 1 .###.#.
.###...
output
output
2
5 3 AA.....
1 2 AA.BBB.
.......
.CCC.D.
input .CCC...
6 0
1 2 1 2 1 2
F. Zurich-Geneva
output
3 seconds, 256 megabytes
2
1 3
2 4 There are n people in the line at the ticket office of the train Zurich-
Geneva. There are m (m ≥ n) seats in the train, numbered from 1 to m.

input When the i -th person in the line is served at the ticket office, she/he asks
2 9 for a ticket to the seat ai . If this seat is open, the cashier sells a ticket to
11 1 this seat. If this seat is already taken, the cashier sells a ticket for the first
(minimum) open seat.
output
0 For each person in the line, find the number of the seat for which the ticket
will be sold to her/him.

E. Buildings Marking Input


The first line of the input contains two integers n and m
1 second, 256 megabytes (1 ≤ n ≤ m ≤ 2 ⋅ 105) — the number of people in the line and the total
number of seats in the train.
Mary works in the city planning department. Once she was assigned to
mark various buildings on a city map. The city map is a matrix of The second line of the input contains n integers a1 , a2 , … , an
characters "." corresponding to an empty space and "#" corresponding to (1 ≤ ai ≤ m ), where ai is the number of a seat the i -th person wants.
buildings. It is guaranteed that each building is a rectangle of characters
Output
"#", and that different buildings do not intersect and do not touch each
Print b1 , b2 , … , bn , where bi is the number of a seat in the ticket of the
other.
i -th person.
Mary's task is to draw a map, replacing the symbols "#" with capital letters
of the English alphabet in each building so that different letters correspond input
to different buildings. Help Mary with this task.
7 13
3 2 2 2 5 5 5
Input
The first line contains integers n and m, the size of the map output
(1 ≤ n, m ≤ 100). The following n lines contain m characters each, the
3 2 1 4 5 6 7
map in the format described above. It is guaranteed that each building is a
rectangle, that the buildings do not intersect and do not touch each other.
The total number of buildings on the map does not exceed 20.
input
7 7
Output 1 1 1 1 1 1 1
Print n lines of m characters, the same map with marked buildings. If
output
there are multiple solutions, print any of them.
1 2 3 4 5 6 7

input
3 4
input
##.. 11 11
##.. 3 1 4 1 5 9 2 6 5 3 5
...#
output
output
3 1 4 2 5 9 6 7 8 10 11
ZZ..
ZZ..
...W
G. Sum of Digits
1 second, 256 megabytes

2 of 5 17/06/20, 1:42 pm
Problems - Codeforces https://sitstar.contest.codeforces.com/group/v...

David loves books and math. Once, while reading an interesting book, he
output
came up with a mathematical problem. Consider the page numbers on the
3
page spreads of the book. The first spread contains page 1, the second
1 3 2 1 2
spread contains pages 2 and 3, the third spread contains pages 4 and 5,
etc. The task is to find the very first spread where the sum of the digits of
input
all page numbers is s. Try to solve this problem.
2 100
Input 1 2
The input contains a single number s from 1 to 300. output
Output 2
Print the page numbers that are on the desired page spread, in ascending 1 2
order. Print numbers without leading zeros. If there is no such spread, print
- 1. I. Roads
input 3 seconds, 256 megabytes

21 There are n cities in Berland. You are given n non-negative integers


output d1 , d2 , … , dn . It is required to build a set of exactly n − 1 one-way
roads so that:
28 29
Except one, each city has exactly one incoming road, and one city
input doesn't have any incoming roads at all (let's call this only city r ).
1 From each city there are between 0 and 2 outcoming roads, inclusive
(the city r must also satisfy this requirement).
output
All cities are reachable along roads from r .
1
The distance from the city r to the i -th city should be equal to di ,
where di is the given integer. The distance from r to i is the number
input of roads on the path from r to i (the city r must also satisfy this
16 requirement).
output Find any way to build n − 1 roads according to the requirements, or
-1 indicate that it is not possible.

Input
input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 105 ). The second
3
line contains n integers d1 , d2 , … dn (0 ≤ di ≤ n − 1).
output
Output
10 11 In solution exits, in the first line print YES. Print NO in the opposite case. In
case of positive answer print n − 1 lines containing pairs of integers xj ,
yj (1 ≤ xj , yj ≤ n ), meaning that the j-th road goes from the city xj to
H. Wireless Access Points
the city yj . If there are multiple answers, print any.
3 seconds, 256 megabytes
input
There are n wireless access points in the long straight corridor: the i -th of
them are located at a distance xi along the corridor from the entrance to 8
3 2 2 0 1 2 1 2
the building.
output
It is known that if two wireless access points are installed at a distance of
less than d, then they must work at different frequencies. What is the least YES
4 5
number of frequencies needed to set up all the points? Find a way to 4 7
assign frequencies so that any two points at distance less than d have 5 2
different frequencies, and the total number of different frequencies used is 5 3
minimal. 7 6
7 8
Input 2 1
The first line of the input contains two positive integers n and d
(1 ≤ n ≤ 2 ⋅ 105 , 1 ≤ d ≤ 109). input
5
The second line contains a sequence of distinct integers x1 , x2 , … , xn
4 3 2 1 0
(1 ≤ xi ≤ 109 ). No two wireless access points are located at the same
point. output
YES
Output 5 4
In the first line print k — the minimal number of frequencies. Print in the 4 3
second line integer frequencies d1 , d2 , … , dn (1 ≤ di ≤ k), where di is 3 2
2 1
the frequency for the i -th wireless access point.

If there are multiple answers, print any of them. input


4
input 0 0 0 0
5 4
9 3 1 5 6
output
NO

3 of 5 17/06/20, 1:42 pm
Problems - Codeforces https://sitstar.contest.codeforces.com/group/v...

input input
5 6 3
1 2 3 4 4 4 2
5 7
output 3 6
4 10
NO
7 1
3 8

J. Roads Inspection output


1 second, 256 megabytes 6 3 1

The mayor of Bytesburg decided to check the condition of the roads after In this example there are 6 orders, and we need to fulfill 3 of them.
reconstruction. To do this, he wants to drive along each road in both
If we choose orders 6, 3, and 1, the maximal time the customer receives
directions.
their order will be 12:
Help the mayor to find the shortest route that goes along each road in
Order 6 will be cooked in time 3, and it will be delivered to the customer in
each direction at least once.
time 11 (3 + 8).
Input
Order 3 will be cooked in time 6 (3 + 3), and it will be delivered to the
There are n intersections and m roads, each road connects two different
customer in time 12 (6 + 6).
intersections. There can be no more than one road between two
intersections. Order 1 will be cooked in time 10 (6 + 4), and it will be delivered to the
customer in time 12 (10 + 2).
It is guaranteed that you can reach each intersection using the roads.

First line contains integers n and m (1 ≤ n ≤ 104 , 1 ≤ m ≤ 105 ). L. Irregular Route


Next m lines contain pairs of integers ai and bi , the numbers of
intersections that the i -th road connects. 2 seconds, 256 megabytes

Output The rectangular field n × m (n and m are even numbers) consists of n


Print the number s, the minimum length of the path, and then s + 1 rows of m identical unit square cells in each row.
integers, the numbers of the intersections in the order in which they need
Mia is a big travel enthusiast, and now she wants to go around this field,
to be passed.
having visited each cell exactly once. Her path begins in the upper left cell
If there are multiple answers, print any of them. and should end in it. In one move, Mia moves to a cell adjacent to the side.

She writes her route as a list of commands L, R and F, where L and R is a


input 90 degree turn to the left or right in the current cell, and F is move forward
3 3 one cell. Thus, there are exactly nm letters F in such a route. Mia does
1 2
not make unnecessary movements, so after each turn (L or R), a forward
2 3
1 3 movement (F) must follow.

output Initially, Mia is in the upper left cell and looks in the direction to the right.
She needs to complete her journey in the same (upper left) cell and look in
6
1 3 2 1 2 3 1 the same direction (to the right). Thus, the route is a cyclic string of letters
L, R and F.

K. Delivering Problem Mia does not like regular patterns, so she wants her route to be irregular.
As a criterion for irregularity, Mia proposed the following. She considers
2 seconds, 256 megabytes the route irregular if there are no two substrings of length
−−−−−−−−−
You work in a small cafe. Today the cafe received n orders for delivery.
[20√max (n, m)] that are equal. In other words, there should not be
two such different positions in the cyclic string corresponding to the route,
For each order you know two numbers: ti is the time needed to cook the −−−−−−−−−
order, and di is the time needed to deliver the order to the customer. that sequences of length [20√max (n, m)] starting at these positions
There are more than n couriers in the cafe, so all deliveries may be done coincide. The brackets in the restriction indicate rounding down.
in parallel, but there is only one kitchen, so the orders can only be cooked Help Mia to find any irregular route.
only one by one.
Input
The cafe can fulfill exactly k orders from the given n, your task is to select Input contains two integers n and m (4 ≤ n, m ≤ 400), size of the field.
the orders and the order they should be cooked, in such a way, that the Both numbers are even.
maximal time the customer receives their order is minimal possible.
Output
Input Print the irregular route as a string of letters L, R and F. The route should
First line contains two integers n and k (1 ≤ k ≤ n ≤ 2000). Next n go through each cell exactly once, it should start from the upper left cell
lines contain pairs of integers ti and di (1 ≤ ti , di ≤ 105 ). facing to the right and end in the same cell in the same position.
Output If there are multiple answers — print any of them.
Print k integers: the numbers of orders you want to fulfill, in the order they
should be cooked. If there are multiple optimal answers, print any of them. input
4 4

output
FFFRFFFRFFFRFRFFLFLFFRFR

For n = m = 4, it is required to find a route so that it does not have


equal substrings of length 40. The answer in the example satisfies this
restriction, the longest equal substrings in it have lengths of 11.

4 of 5 17/06/20, 1:42 pm
Problems - Codeforces https://sitstar.contest.codeforces.com/group/v...

Codeforces (c) Copyright 2010-2020 Mike Mirzayanov


The only programming contests Web 2.0 platform

5 of 5 17/06/20, 1:42 pm

You might also like