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

Problems1 - Codeforces

The document outlines various programming problems presented in a competitive programming context, involving different characters and scenarios. Each problem includes specific input and output requirements, focusing on topics like palindrome strings, geometric relationships, data clustering, and optimal partitioning of electrons. The problems are designed for multiple test cases and require algorithmic solutions within given constraints.
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)
12 views5 pages

Problems1 - Codeforces

The document outlines various programming problems presented in a competitive programming context, involving different characters and scenarios. Each problem includes specific input and output requirements, focusing on topics like palindrome strings, geometric relationships, data clustering, and optimal partitioning of electrons. The problems are designed for multiple test cases and require algorithmic solutions within given constraints.
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

IEEE 2026 Online Qualification

A. Ahmad and allergy First line contains an integer T (1 ≤ T ≤ 50) the number of test-cases.
Each test-case is described as follows: The first line contains two integers
2 seconds, 64 megabytes N and R (1 ≤ N ≤ 800) (1 ≤ R ≤ 100000), R will have exactly 4 digits
after the floating point. each of the following N lines represent a point and
Ahmad is a 5-year old boy, his favorite hobby is programming. He spends
contains two integers X and Y the coordinates of the point (0 ≤ X,Y ≤
about 5 hours daily solving programming problems. One day he came
across a problem about palindrome strings for the first time, while he was 100000).
reading the problem he started to sneeze many times, he then realized Output
that he is allergic to palindrome strings so he immediately closed that Output the answer for each test-case in a new line, the maximum number
problem. of points which can be covered by the circle.

A palindrome string is a string that is read the same from the left and from input
the right, for example and are palindromes while
1
and are not. 5 1.0000
0 0
Now Ahmad moved to practicing on recursion, he wants to generate all 0 1
strings of small English letters of length N that do not contain any 0 -1
palindrome substring of length more than 1. Can you guess how many 2 3
strings he will generate? 4 5

A substring of a string S is a sequence of consecutive characters from S. output


3
Compute the number of generated strings modulo 109 + 7

Input C. Rama and geometric problem


The first line contains a single integer T, the number of test cases. (1 ≤ T
≤ 100) Each test case is described by one line containing one integer N. 2 seconds, 64 megabytes
(1 ≤ N ≤ 109)
Rama is an ambitious student studying in ITE faculty, recently she heard
Output about Aleppo Collegiate Programming Contest and she got interested in it
For each test case, print one line containing one integer, the number of and wanted to participate in it so she started practicing by solving
strings of length N that have no palindrome substrings of length more than algorithmic problems from the internet.
1 modulo 109 + 7.
After she solved many problems she came across a geometric problem
which she couldn't solve, actually she didn't try hard enough because she
input thought she will never solve it anyway because she is weak in geometric
4 algorithms. However, Rahaf -Rama's friend- told Rama that not all
1 geometric problems require knowledge in geometric algorithms, you also
2
12348
agree with Rahaf's opinion and you want to prove it for Rama, so she
9991 gave you the problem statement and you now have to solve this problem.

output The problem that Rama was trying to solve states: Given a circle and a
26 rectangle such that whose sides are parallel to X Axis and Y Axis and, find
650 out if the circle is completely inside the rectangle or the rectangle is
981273898 completely inside the circle. if one of them is inside the other but also
594358895 touches it from inside it's considered to be inside it.

in the first test-case all strings of length 1 should be counted, so the Input
answer is 26 The first line contains an integer T (1 ≤ T ≤ 1000), the number of test-
cases
in the second test-case all strings of length 2 should be counted except
the strings which consist of two equal characters, so the answer is 26*26 - each test-case consist of a single line containing 7 integers: x1, y1, x2, y2,
26 = 650 xc, yc, r (0 ≤ x1 < x2 ≤ 10000),(0 ≤ y1 < y2 ≤ 10000), (0 ≤ xc , yc ≤
10000),(1 ≤ r ≤ 10000).
B. Waleed and Machine learning The lower left vertex of the rectangle is (x1,y1) and upper right vertex is
15 seconds, 64 megabytes (x2,y2), the other vertices are (x1,y2) and (x2,y1), the center of the circle is
(xc,yc) and has radius
Waleed is an experienced programmer, he is now studying machine
learning basics, and one of the basic problems in machine learning is Output
clustering data into groups so that elements of data in same group are Output the answer for each test-case in a new line, if the circle is inside
close to each other, note that each element of data can be represented as the rectangle output CIRCLE, if the rectangle is inside the circle output
a point in a 2D plane. RECTANGLE, if neither one is inside the other then output NONE.

Since Waleed likes algorithms more than AI he started to think if we can Pay attention that any misspelling of the words or using lower-case letters
change the problem a bit so that it can be solved with a deterministic will result in rejecting the solution.
algorithm, and he came up with this problem:

Given N points on a 2D plane and a positive real number R, what is the


maximum number of points that can be inside a circle of radius at most R?
a point that is on border of the circle is considered inside it.

Input
input Amjad is an ITE faculty student, currently he is attending practical
electronics course and he is going to make an experiment, he has N
7
electrons, each one has an amount of charge, it's well-known that when
0 0 100 100 25 25 15
8 10 13 15 10 12 15 two electrons are placed next to each other a repulsion force arises which
12 10 18 16 15 13 3 moves the electrons away from each other, this force is equal to the
0 0 10000 10000 5000 5000 5000 product of the charges of the two electrons, the total amount of repulsion
1000 2000 9000 8000 5000 5000 5000
forces in a field is equal to the sum of forces which arise from all pairs of
12 10 13 11 5 3 7
7 5 13 11 5 3 7 electrons in that field.

output Now Amjad wants to partition his N electrons into two fields so that sum of
CIRCLE
total forces in both fields in minimized, each electron must be put in
RECTANGLE exactly one field.
CIRCLE
CIRCLE Help Amjad by choosing the optimal partition of the electrons.
RECTANGLE
NONE Input
NONE The first line contains T (1 ≤ T ≤ 50) the number of test-cases

Drawing of the first test-case: The first line of each test-case contains N (1 ≤ N ≤ 40) the number of
electrons.

The second line of each test-case contains N integers, the amount of


charges of each electron. the charge will be between 1 and 107

at most 2 test-cases will have N bigger than 30

Output
Output the answer for each test-case in a new line, the minimum possible
sum of total amount of forces in the two fields.

input
2
2
10 20
3
3 4 100

output
Drawing of the second test-case:
0
12

E. Ahmad and drinks


2 seconds, 64 megabytes

Ahmad -Aleppo university site director- wants everybody to enjoy Aleppo


Collegiate Programming Contest, so he decided to give everyone cold
drink, there are N types of these drinks numbered from 1 to N, and for
each of which there are Ci cups, unfortunately each person likes only one
type of drink, there are exactly Li contestants who like the type of drink
number i. You can make a person happy if you give him a cup of drink he
likes, help Ahmad to determine the maximum number of contestants
which can be made happy.

Input
Drawing of the sixth test-case: The first line contains T (1 ≤ T ≤ 100) the number of test-cases.
The first line of each test-case contains N (1 ≤ N ≤ 1000) the number of
the types of the drinks.

The second line of each test-case contains N integers, the number of cups
of each type Ci. the number will be between 1 and 105

The second line of each test-case contains N integers, the number of


contestants who like each type Li. the number will be between 1 and 105

Output
Output the answer of each test case in a new line.

input
2
5
1 2 3 4 5
5 4 3 2 1
9
D. Amjad and electrons 1 9 4 2 7 6 8 5 3
1 9 8 4 5 6 7 2 3
15 seconds, 64 megabytes
output
9
39
in the first test-case we can make only 1 person happy of those who like
first type of drink because we have only 1 cup, and we can make 2 people
happy of those who like second type of drinks because we have 2 cups
only, all people who like any of the last 3 types of drinks will be happy
because there are enough drinks for them so total number of happy
people is 1 + 2 + 3 + 2 + 1 = 9.

F. Yasmeen and wasted paint Drawing of the sample.


3 seconds, 128 megabytes

Aleppo Collegiate Programming Contest 2017 is coming soon, and the


G. Husam and projects
organizers want it to be an unforgettable event, that's why the judging 2 seconds, 64 megabytes
team is now preparing the problem-set, the technical team is preparing
computers, network and operating system, volunteers are preparing the Husam is a very experienced programmer, his experience is already 30
balloons, the organizing team is preparing for the Opening and Award years long and he already wrote 10N-1 projects numbered from 1 to 10N-
Ceremony the media team are making plans for the event coverage. 1 and each project is a cpp file named with the number of the project
without leading zeroes, for example [Link], [Link], [Link] and so on...
The walls of the hall in which the contest is going to be held currently have
very old paintings and they should be repainted, that's why they hired a Husam stores all his projects in the same folder. However, there's a small
specialist painter. problem, for easiness of finding a particular project all projects should be
sorted according to their numbers but unfortunately this is not the case
The wall that will be painted can be represent as 2D plane with the X axis with the windows file explorer. Actually, it sorts the files according the
represent the floor lexicographical order of the files, for example if there are 100 files in the
The way that the painter paint the wall is by choosing some rectangles folder with numbers from 1 to 99 the first few files in the list would be
whose sides are parallel to X and Y Axis and the lower side of each of the [Link], [Link], [Link], [Link] ...
rectangles lies completely on the X Axis.
Given N and K, find out the name of the file which appears Kth in the list.
After choosing a rectangle, the painter is going to paint all the area
Input
covered by this rectangle, even if there are some parts which are already
First line contains an integer T (1 ≤ T ≤ 10000) the number of test-
painted.
cases.
Yasmeen -One of the Organizers- noticed that the painter's method is
Each test-case consists of a single line containing N and K (1 ≤ N ≤ 6)
wasting a lot of paint because it repaints some areas multiple times. Now
(1 ≤ K ≤ 10N-1)
she wants to calculate the amount of wasted paint (1 unit of area is equal
to 1 unit of paint) Output
Output the answer for each test-case in a new line, the answer is the file
Input
name which appears Kth in the list.
First line contains an integer T (1 ≤ T ≤ 32) the number of test-cases.
The first line of each test case contains an integer N (1 ≤ N ≤ 103), the
input
number of painted rectangles.
5
9
The next N lines contain three integers, x1, x2, h (0 ≤ x1 < x2 ≤ 10 ) (1 1 1
≤ h ≤ 1000), where x1 is the x Coordinate of the lower left corner, x2 is 2 79
3 159
the x Coordinate of the lower right corner, and h is the height of the
5 6549
rectangle. 6 999999

Output output
For each test case, print one line, the answer to the test. [Link]
[Link]
input [Link]
[Link]
1 [Link]
6
0 2 2
1 5 4
4 7 1 H. Khaled and Tarneeb
6 12 3
2 seconds, 64 megabytes
9 11 2
10 11 1

output
9
Khaled likes playing card games, especially Tarneeb. In this game, a deck
of 52 playing cards are arbitrarily distributed among four players, 13 cards
for each player. Each card has a number on it between 1 and 13, and has
I. Sarah and interview
one of the four suits: club , diamonds , hearts and spades. No two cards 5 seconds, 64 megabytes
have the same number and same suit at the same time, thus there are a
total of 13*4=52 different cards and each card exists once in the deck. The Sarah recently graduated from ITE faculty and she's now looking for a job,
game involves 13 rounds, in each round each player should play one of after she applied to a full-time position at one of the software companies
his cards from his hand, in the first round Khaled starts playing and in all the company decided to interview her.
other rounds the winner of previous round will play first in the current during the interview they asked Sarah some questions about her
round, it doesn't matter who plays second, third and last. After each player experience and then asked her to solve a programming task.
plays his card, the winner of the round is determined as follows: If there's
at least a card of spades suit then the winner is the one who plays the The task is simple: given two positive integers A and B find the greatest
card with highest number on it and it is of spades suit. If there's no card of common divisor (GCD) of A and B.
spades suit, then the winner is the one who plays the card with highest
At first Sarah thought it's an easy task especially she remembers the
number which has a suit same as the suit of the card which is played first.
Euclidean algorithm she took from algorithms course during her study in
The score of each player is equal to the number of rounds he has won.
ITE faculty. however, when she realized that A and B are very huge
Khaled has an awesome idea, he wants to play Tarneeb with his friends numbers that can't be stored in a single 64-bit variable she realized the
online but that requires him to have a Tarneeb application and you are task is not easy at all, the interviewer told her that A and B will not be
hired to implement it. given directly, instead, she will be given two sequences X and Y of
positive integers.
You are given what card each player played in each round, calculate the
score of each player. The number A is equal to the product of all integers in the sequence X.

Note: The game described in this problem is a bit different from the real The number B is equal to the product of all integers in the sequence Y.
Tarneeb game, don't assume anything that is not mentioned in the
Since A and B are very huge numbers, their GCD might be huge too, so
statement.
find GCD of A and B modulo 109 + 7.
Input Unfortunately, Sarah couldn't solve the task during the interview and she
First line contains a single integer T (1 ≤ T ≤ 50) the number of test- ended up being rejected by the company, but she's still curious about the
cases. solution of this task, can you help Sarah solving it?
Each test-case contains 13 lines, the ith line contains A1, S1, A2, S2, A3,
Input
S3 , A 4 , S4 . The first line contains an integer T (1 ≤ T ≤ 20) the number of test-
Aj and Sj in ith line means that player j played a card with number Aj and cases.
suit Sj in ith round. Sj can be one of the following characters (C , D , H , The first line of each test-case contains two integers N and M (1 ≤ N ≤
S) to represent clubs , diamonds , hearts and spades respectively. 20000) (1 ≤ M ≤ 100), the length of sequence X and the length of
It's guaranteed that all cards will be valid and distinct. sequence Y respectively.

The first player is Khaled and he starts playing in the first round. The second line of each test-case contains N integers, the elements of
sequence X.
Output
Output the answer to each-test case in a new line, each line should have The third line of each test-case contains M integers, the elements of
four integers, the ith integer is the score of the ith player. sequence Y.

Elements of X and Y are between 1 and 1018


input
There will be at most 2 test-cases having N or M bigger than 50.
1
8 H 6 H 1 D 13 D Output
9 D 2 S 1 S 2 D
for each test-case output a single integer in new line, the answer to the
13 C 11 C 10 S 2 C
5 D 4 C 10 H 3 H test-case
12 C 8 D 9 H 11 D
9 S 8 C 3 S 3 D input
4 S 10 D 12 D 11 H
10 C 12 H 7 D 7 H 2
3 C 9 C 1 C 2 H 3 4
8 S 6 D 5 S 4 H 2 3 4
5 H 13 H 13 S 6 C 5 2 2 3
11 S 7 S 5 C 12 S 2 2
4 D 1 H 7 C 6 S 10000000000000000 10000000000000000
10000000000000000 10000000000000000
output
output
5 2 4 2
12
In round 1: first to play is player 1 and winner is player 1 In round 2: first to 965700007

play is player 1 and winner is player 2 In round 3: first to play is player 2


In the first test-case we have
and winner is player 3 In round 4: first to play is player 3 and winner is
player 3 In round 5: first to play is player 3 and winner is player 3 In round A = 2 * 3 * 4 = 24
6: first to play is player 3 and winner is player 1 In round 7: first to play is
B = 5 * 2 * 2 * 3 = 60
player 1 and winner is player 1 In round 8: first to play is player 1 and
winner is player 1 In round 9: first to play is player 1 and winner is player 2 and GCD of 24 and 60 is 12
In round 10: first to play is player 2 and winner is player 1 In round 11: first
to play is player 1 and winner is player 3 In round 12: first to play is player In the second test-case both A and B are equal to 1032 so their GCD is
32 32 9
3 and winner is player 4 In round 13: first to play is player 4 and winner is also 10 , and 10 modulo 10 + 7 is 965700007
player 4
J. Mohammad and communication skills Each of the following T lines contains a string S of lower-case English
letters. (1 ≤ |S| ≤ 10000).
2 seconds, 64 megabytes
Output
Mohammad is an ITE student, he likes his study field, especially For each test case, print one line containing YES if the string can be
programming and algorithms, but he doesn't like attending classes at all transformed into a palindrome, and NO otherwise.
since they are very boring, but sometimes he is forced to attend in order to Pay attention that any misspelling of the output or using lower-case
maintain his attendance rate otherwise he will be prevented from doing English letters will result in rejecting the solution.
final exams!

Currently Mohammad is attending Communication skills class and he is input


now feeling very bored especially that he thinks such course should not 2
belong to an ITE faculty program, luckily he remembered a problem that abc
one of his friends has given him so he decided to spend the time thinking cdababc

about it, the problem states: output


You are given a string S. You are allowed to reverse a substring of S of NO
YES
odd length, you can do it as many times as you want (You don't have to
minimize the number of reverses), can you transform the string into a
In the first test-case we cannot make the string palindrome.
palindrome?
In the second test-case if we reverse substring "dab" (from second
Since you also don't like communication skills classes you decided to
character to fourth character) the string will become "cbadabc" which is a
solve this problem too.
palindrome.
Input
The first line contains a single integer T (1 ≤ T ≤ 100), the number of
test cases.

Codeforces (c) Copyright 2010-2026 Mike Mirzayanov


The only programming contests Web 2.0 platform

You might also like