task stringlengths 0 154k | __index_level_0__ int64 0 39.2k |
|---|---|
Feline Olympics - Mouseball (MBALL)
A popular event at the feline Olympics is watching and wagering on the outcome of the house cats playing Mouseball [which has the same scoring rules as American football] but is played with a catnip mouse. Wagers often involved predicting the score and, of course, some scores are mo... | 31,800 |
Pretty Functions (PRETTY)
Let S = {1, 2, 3 ... N}.
For a given positive integer K, the function f : S → S is called "pretty" if, for every X in S, it holds that
f ( f ( f ( ... f ( X ) ... ) ) ) = X, where f is repeated exactly K times.
How many pretty functions are there, modulo M?
Input
Three natural numbers... | 31,801 |
Mystic Craft (MYSTIC)
In the Ancient Clash of Mystic Pandas (ACM Pandas) game, the player plays the role of a Panda Knight who needs to defend Panda Land by defeating evil Panda Wizards. As the wizards have special magical powers, they need to be defeated using specific types of Mystic Sticks (regular bamboo sticks a... | 31,802 |
Top 10 (TOP10)
Given a dictionary containing less than N = 20000 words labeled from 1 to N. Each word consists of lowercase characters (from 'a' to 'z') with arbitrary length. The total number of characters in the dictionary is at most 100,000.
Your task is to answer at most Q = 100000 queries. Each query qi is also... | 31,803 |
Spam Detection (SPAMD)
It is well-known that the number of occurrences of the term "free" can distinguish spam and non-spam emails.
Your task is to build a spam detection module, based on the number of term "free" in an email. The core of this detection module is a spam classifier, which is represented by two variab... | 31,804 |
Playing with Marbles (TUTMRBL)
Playing with marbles is one of the king's favorite pastimes. He especially enjoys a game which was taught to him by Eratosthenes, a visiting mathematician from Greece. The rules are very complicated but it all boils down to arranging marbles in a (filled) rectangular shape to score point... | 31,805 |
Two "Ways" (SPHIWAY)
There are N places and M bidirectional ways. No two places have more than one direct way. Ana wants to walk from S to T and return to S by an itinerary that satisfies:
No way can be used twice.
Length of itinerary is the minimum.
Input
Line 1: 4 integers: N, M, S, T (N ≤ 10
4
; M ≤ 10
... | 31,806 |
Wine trading in Gergovia (GERGOVIA)
Gergovia consists of one street, and every inhabitant of the city is a wine salesman. Everyone buys wine from other inhabitants of the city. Every day each inhabitant decides how much wine he wants to buy or sell. Interestingly, demand and supply is always the same, so that each inh... | 31,807 |
Minimal Possible String (MINSEQ)
Given two strings A and B, your are to find the lexicographically smallest string after inserting B into A.
For example, string A is "369", and string B is "4799". There are 4 ways that I can insert B into A, and I’ll get 4 different results: 4799369, 3479969, 3647999, 3694799. Thus,... | 31,808 |
Bomb the Bridge (BOMB)
You want to destroy a bridge with bombs. The lower-left corner of the bridge is at (0, 0) and the upper-right corner is at (w, l). There are already b bombs exploded, the i-th bomb created a hole of radius ri centering at (xi, yi). You want to throw exactly one more bomb so that the bridge is sp... | 31,809 |
A Pair of Graphs (PAIRGRPH)
We say that two graphs are equivalent if and only if a one-to-one correspondence between their nodes can be established and under such a correspondence their edges are exactly the same. Given $A$ and $B$, two undirected simple graphs with the same number of vertexes, you are to find a serie... | 31,810 |
Binary Integer (BNYINT)
An antique machine with $\binom{N}{3}$ switches capable of processing integers in the range $0 \ldots 2^N - 1$ has just been discovered. Each switch is associated to a distinct integer in $0 \ldots 2^N - 1$ with exactly three ones in its binary representation. By setting switches associated wit... | 31,811 |
Cryptography Reloaded (Act I) (CRYPTO6)
What do researchers working at ICPC (Institute for Cryptographic Programming and Computing) do for fun? Well, as you probably have expected, in addition to solving algorithm-related problems on online judges, they also like to toy with various cryptographic schemes. Recently one... | 31,812 |
Déjà vu (DEJAVU)
An antique machine with $\binom{N}{3}$ switches capable of processing integers in the range $0 \ldots 2^N - 1$ has just been discovered. Each switch is associated to a distinct integer in $0 \ldots 2^N - 1$ with exactly three ones in its binary representation. By setting switches associated with numbe... | 31,813 |
Experiment on a … Cable (CABLEXPR)
The head technical person, Joey, at ACM (Association for Cyberspace Management)
has just received a weird cable-like device – supposedly invented by programmers
during a competition – for inspection.
The device may be viewed as a straight bi-directional cable, which can be used
... | 31,814 |
Fire-Control System (FCSYS)
A new mighty weapon has just been developed, which is so powerful that it can
attack a sector of indefinite size, as long as the center of the circle containing the
sector is the location of the weapon. We are interested in developing a fire-control
system that calculates firing-solution... | 31,815 |
Get-Together at Stockholm (STCKHOLM)
Peter has recently decided to hold a party at Stockholm, where the ACM/ICPC
2009 World Final will be held. Unfortunately, despite Peter’s affluence, he is not able
to invite all of his friends due to the astronomical price of the air ticket to Stockholm.
He has devised the follo... | 31,816 |
History of Languages (HISTORY)
We are examining two specific classes of languages (a possibly infinite set of
strings) in this problem. Fortunately (or maybe unfortunately), we are not given the
strings contained in each language directly, rather we are given two deterministic
finite automatons that describe such l... | 31,817 |
Junk-Mail Filter (JMFILTER)
Recognizing junk mails is a tough task. The method used here consists of two
steps:
Extract the common characteristics from the incoming email.
Use a filter matching the set of common characteristics extracted to
determine whether the email is a spam.
We want to extract the set ... | 31,818 |
Alice’s Cube (ALICECUB)
Alice has received a hypercube toy as her birthday present. This hypercube has 16 vertices, numbered from 1 to 16, as illustrated below. On every vertex, there is a light bulb that can be turned on or off. Initially, eight of the light bulbs are turned on and the other eight are turned off. You... | 31,819 |
Brute-force Algorithm EXTREME (BFALG)
Professor Brute is not good at algorithm design. Once he was asked to solve a path finding problem. He worked on it for several days and finally came up with the following algorithm:
Function Find(integer n, function func)
If n=1
For i = 1 to a do func()
Elseif n=2
For... | 31,820 |
Compressed String (COMPRESS)
Dealing with super long character strings is Chris’s daily work. Unfortunately, the strings are so long that even the fastest computer in the world cannot work with them.
Chris does her work in a smart way by compressing the strings into shorter expressions. She does her compression for ... | 31,821 |
Cryptography Reloaded (Act II) (CRYPTO7)
In the game BioHazard 4, the American president's daughter has been abducted by some crazy villagers. Leon S. Kennedy, the secret agent of White House, goes to rescue her. He keeps in contact with Hunnigan, the president's secretary. But the time in their contact log has been e... | 31,822 |
Exciting Time (TETRIS2D)
It’s exciting time! Now let’s consider the most famous video game in the world: Tetris.
Tetris is a puzzle video game originally designed and programmed by Alexey Pajitnov. It was created on June 6, 1984. The game is available for nearly every video game console and computer operating system... | 31,823 |
Flowers Placement (FLOWERS2)
Bytetown has a long tradition in organizing an international flower exhibition. Professor Feuerbach, a true flower lover, visited the exhibition this year. He was pleased by the most beautiful flowers and other plants around the world roses, orchids, magnolias, cactuses. All flowers were n... | 31,824 |
Game Simulator (TRACTOR)
Since this problem is added as an classical problem in SPOJ, the users who get this problem Accepted (by himself/herself, I'll look at your code) before 2011.10.25 8:00:00 SPOJ time (two years right after the on-site contest's end) will be e-mailed some pictures of the problem setters of this ... | 31,825 |
Heroes Arrangement (HEROARR)
There are N heroes in the Kingdom of Heroes, each hero has a special range of activity, this "range" is a delta-shaped region (
triangle region including the boundary
; it is guaranteed that all triangles will neither degenerate into a segment nor a point
using the King’s angle of view
),... | 31,826 |
Island Explorer (IEXPOLRE)
A group of explorers has found a solitary island. They land on the island and explore it along a straight line. They build a lot of campsites while they advance. So the campsites are laid on the line.
Coincidently, another group of explorers land on the island at the same time. They also b... | 31,827 |
Jinyuetuan Puzzle (O2JAM)
JinYueTuan is a famous online game which has been in vogue for a long time. Large number of players put themselves in it day after days...
JinYueTuan is a simple game with these rules:
Only
seven keys
on the keyboard will be used in games, each key are assigned to one of the seven
soun... | 31,828 |
Factorial vs Power (FACVSPOW)
Consider two integer sequences
f(n) = n!
and
g(n) = a
n
, where
n
is a positive integer. For any integer
a > 1
the second sequence is greater than the first for a finite number of values. But starting from some integer
k
,
f(n)
is greater than
g(n)
for all
n >= k
. You are to... | 31,829 |
Tower of Vientiane (VIENTIAN)
The Tower of Hanoi is a mathematical game or puzzle. It consists of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks neatly stacked in order of size on one rod, the smallest at the top, thus making a conical shape.
The ob... | 31,830 |
Double Sorting (PAIRSORT)
Here we describe a typical problem. There are
n
balls and
n
boxes. Each ball is labeled by a unique
number from 1 to
n
. Initially each box contains one of these balls. We can swap two balls in adjacent
boxes. We are to sort these balls in increasing order by swaps, i.e. move the ball ... | 31,831 |
Monotonous numbers (MONONUM)
Some integers possess interesting quality: each of their digits is not greater than the digit to the right. Let us define such integers as increasing integers. And let's call integers for which each digit is not lesser than the digit to the right decreasing integers. For example 24558 is i... | 31,832 |
Differential Diagnosis (DIFFDIAG)
Daniel enjoys watching TV series. One of his favorite is "Doctor Chaos". In this series the medical genius is saving people by making difficult diagnosis. In his work he employs the differential diagnosis method. Doctor Chaos writes all the symptoms the patient have on the white board... | 31,833 |
Area of a Garden (GARDENAR)
One rich person decided to make himself a great garden. The garden should have a from of equilateral triangle. There should be a gazebo inside the garden. The gazebo will be connected with the triangle vertexes by roads. The lengths of all three roads are known. Those numbers are sacred for... | 31,834 |
A Coin Game (XOINC)
Farmer John's cows like to play coin games so FJ has invented with a new two-player coin game called Xoinc for them.
Initially a stack of N (5 ≤ N ≤ 2,000) coins sits on the ground; coin i from the top has integer value C
i
(1 ≤ C
i
≤ 100,000).
The first player starts the game by taking the t... | 31,835 |
Recurrence (REC)
Let F0 = 1. Fn = a*Fn-1 + b for n >= 1. Find Fn (mod M).
Input
The first line contains T the number of test cases. Each of the next T lines contains 4 space separated integers a, b, n and M.
Constraints
T <= 20000
0 <= a, b, n <= 10^100
1 <= M <= 100000
Output
Output T lines, one correspo... | 31,836 |
Adjacent Bit Counts (GNYR09F)
For a string of n bits x1, x2, x3 ... Xn the adjacent bit count of the string (AdjBC(x)) is given by
X1*X2 + X2*X3 + X3*X4 + ... + Xn-1 * Xn
which counts the number of times a 1 bit is adjacent to another 1 bit. For example:
AdjBC(011101101) = 3
AdjBC(111101101) = 4
AdjBC(010101010) =... | 31,837 |
Air Combat (COMBAT)
An air combat is on the way, you are asked to command this war. Now planes of enemy are full of the sky. A plane is described with three-dimensional coordinate (x, y, z) (1000 < x, y, z < 1200), and all coordinates are integers. As is shown below:
You have created a missile which can destroy al... | 31,838 |
Interval Challenge (INTERVA2)
Give you N (1 <= N <= 200000) intervals, represented as [A, B], for example, interval s represented as [As, Bs].
For two intervals s and t, we say S covered by T if At <= As and Bs <= Bt. Now my problem is easy, just tell me the question below: For each interval, how many intervals can ... | 31,839 |
Mexican Standoff (MEXICAN)
The town of San Saba is too small for more than one gunslinger. Unfortunately, all of them turned up on the same day, one fine spring morning. As it turned out, love was in the air and they were all trying to woo Alice, the sheriff's daughter. As only one of them could win her love, they dec... | 31,840 |
Query Problem (QUERYSTR)
McFn interested in string problem recently. He found a interesting function and he felt he could use this function to invent a new match algorithm.
For a string S [1 ... n] and i ¡Ê [1, n], define F (i) is the length of the longest common suffix of S and S [1 ... i].
For example, for the stri... | 31,841 |
Tetravex Puzzle (TETRAVEX)
TetraVex is a challenging computer brain teaser. The object of the game is to fill the grid with the tiles so that the numbers on the adjacent edges of each tile match, much like aligning domino tiles.
Given the 9 tiles, you have to find out whether it is possible to solve the puzzle. Each... | 31,842 |
Four Mines (MINES4)
A Company that Makes Everything (ACME) has entered the surface mining business. They bought a rectangular field which is split into cells, with each cell having a profit value. A mine is a non-empty rectangular region, and the profit of a mine is equal to the sum of the values of all its cells. ACM... | 31,843 |
Fishing Net (FISHNET)
In a highly modernized fishing village, inhabitants there make a living on fishery. Their major tools, fishing nets, are produced and fixed by computer. After catching fishes each time, together with plenty of fishes, they will bring back the shabby fishing nets, which might be full of leaks. The... | 31,844 |
Seinfeld (ANARC09A)
I’m out of stories. For years I’ve been writing stories, some rather silly, just to make simple problems look difficult and complex problems look easy. But, alas, not for this one.
You’re given a non empty string made in its entirety from opening and closing braces. Your task is to find the minim... | 31,845 |
Tiles of Tetris, Not! (ANARC09B)
You’ve really messed up this time. “Go buy some square tiles” your supervisor told you. But as usual, you were either busy reading that message, answering that e-email, or updating your wall status on facebook. “Go buy some tiles” was all that you could remember. Your supervisor is now... | 31,846 |
Not So Flat After All (ANARC09C)
Any positive integer v can be written as p
1
a1
* p
2
a2
*... * p
n
an
where p
i
is a prime number and ai ≥ 0. For example: 24 = 2
3
* 3
1
.
Pick any two prime numbers p
1
and p
2
where p
1
!= p
2
. Imagine a two dimensional plane where the powers of p
1
are plotted on the x... | 31,847 |
Hop Do not Walk (ANARC09D)
Kermit The Frog is a classic video game with a simple control and objective but requires a good deal of thinking. You control an animated frog that can walk and hop, in both forward and backward directions. The frog stands in a space between an otherwise a contiguous line of tiles. Each tile... | 31,848 |
Air Strike (ANARC09F)
General Gee is the commander of a military base. He has just received alarming news from one of his spies: the enemy’s preparing an air missile strike. The base contains two magnetic towers. When activated and given sufficient power, each of the magnetic towers creates a powerful horizontal magne... | 31,849 |
Art Plagiarism (AP)
You have pictures of two sculptures. The sculptures consist of several solid metal spheres, and some rubber pipes connecting pairs of spheres. The pipes in each sculpture are connected in such a way that for any pair of spheres, there is exactly one path following a series of pipes (without repeati... | 31,850 |
Bird or not bird (BIRD)
You are studying animals in a forest, and are trying to determine which animals are birds and which are not.
You do this by taking two measurements of each animal – their height and their weight. For an animal to be a bird, its height needs to be within some range, and its weight needs to be ... | 31,851 |
Counting triangles (CT)
Consider a 2D integer grid with lower left corner at (0, 0) and upper right corner at (X, Y). We are interested in isosceles right triangles which all the 3 corners at the grid node (integer coordinates). Your task is to count the number of those triangles.
Input
The input begins with C – n... | 31,852 |
Deliver pizza (DP)
Tom McCoffee owns the only pizza delivery place in the mountains. The terrain is represented as a rectangular grid of squares, where each square either contains a building or is empty. Each empty square has an integer height between 0 and 9, inclusive. Today, each building in the area has ordered on... | 31,853 |
Electronic queue (EQ)
The train station has just used a new electronic queue system. Now passengers who want to buy tickets have to get the service ordering number and wait until it is his turn.
In this station, there are N cashiers; each can serve one passenger at a time. When it’s your turn, you will go to an assi... | 31,854 |
Finding password (FP)
Bom has a list of n favorite numbers which are birthday, driving license, passport number, etc After creating an email account, Bom wants to choose a password as the largest number P among all possible numbers generated by the combinations of k (1 ≤ k ≤ n) positive numbers in the favorite list so... | 31,855 |
Going to school (GS)
Your family has just moved to small town with simple transportation system: there are N junctions and N - 1 roads connecting the junctions. These roads guarantee that it’s possible to travel between any two junctions. Each road connects two junctions and has a preferred value.
You are new here a... | 31,856 |
Houses (HOUSES2)
You are given three triangle houses. Each house is presented by three points in the 2D coordination. Houses do not overlap but can share points on their border.
You stay at point (sx, sy) and want to reach (ex, ey) by a shortest path. Your path can not intersect with a house but you can go a long a ... | 31,857 |
Heavy Sequences (HSEQ)
Given a sequence S of N integers, indexed from 0 to N-1, we define the weight of its continuous subsequence as the product of its length and its number of occurrences in the main sequence, and in case of uniqueness, we say its weight is 0.
Let's see an example:
N = 5
S = { 1, 7, 3, 1, 7 }
... | 31,858 |
Buy Your House (PHU09H)
You are going to buy a house and hence communicated with a real estate development company, which has just started their business and you are going to be the first buyer. So they are offering you something special. The real estate company has a rectangular shaped land of width W and height H. T... | 31,859 |
Highway Patrol (PHU09K)
Crimes in city of Megacity are going high. To fight the crimes, the authorities have created a highway patrol. The city consists of a number of one-way roads. At the ends of each road, there is a base station for the patrol troops. Each base station has a number of troops. At the beginning, eac... | 31,860 |
Math with Bases (Easy) (BSMATH1)
Little Ben had just learned different bases in math. He learned very quickly how to add and subtract in multiple bases, so his teacher provided him with a worksheet to work on. Each section provided a different base and gave an example.
Unfortunately, Little Ben's teacher forgot to w... | 31,861 |
Kutevi Hard (KUTH)
One day Mirko was cleaning up his room and found a straightedge and a compass. He went to the school the next day and challenged his friend Slavko to a geometric construction battle. Mirko knows how to construct some angles using the straightedge and compass and knows how to subtract and add any two... | 31,862 |
Sequoiadendron (SEQUOIA)
"
Sequoiadendron giganteum (giant sequoia, Sierra redwood, or Wellingtonia) is the sole species in the genus Sequoiadendron, and one of three species of coniferous trees known as redwoods, classified in the family Cupressaceae in the subfamily Sequoioideae, together with Sequoia sempervirens (... | 31,863 |
Counting pairs (CPAIR)
You're given a sequence A of N non-negative integers. Answer Q queries, where each query consists of three integers: v, a, b. The answer is number of pairs of integers i and j that satisfy these conditions:
1 <= i <= j <= N
a <= j-i+1 <= b
A[k] >= v for every integer k between i and j, inc... | 31,864 |
Math with Bases (BSMATH2)
With
your previous help
, Little Ben managed to get a perfect score on his homework. He came running home to show his brother, Big Ben. Big Ben had done this type of thing before, you see, so he naturally wasn't too impressed. Big Ben boasted, "Back in my day, we had to multiply and divide a... | 31,865 |
Knight Moves (KMOVES)
A knight is located at the (black) origin of an infinite chessboard. Let
f(n)
define the number of black squares the knight can reach after making exactly
n
moves. Given
n
(0 <=
n
<= 10
8
), output
f(n)
.
Input
The first line of the input contains a single integer T, the number of te... | 31,866 |
LL and ErBao (ISUN1)
When LL and ErBao were young, they liked jumping rubber-rope (Tiao Pi Jin) very much. They jumped every day happily. But one day HH came and brought away the peaceful days. HH sometimes threw stones to them, and sometimes pushed them down suddenly. Seeing ErBao crying sadly, LL got angry finally, ... | 31,867 |
Mobile Service Hard (SERVICEH)
A company provides service for its partners that are located in different towns. The company has three mobile service staff employees. If a request occurs at some location, an employee of the service staff must move from his current location to the location of the request... | 31,868 |
Fractions on Tree (NG0FRCTN)
A fraction tree is an infinite binary tree defined as follows:
Every node of tree contains a fraction.
Root of tree contains the fraction 1/1.
Any node with fraction i/j has two children : left child with fraction
i / (i + j)
and right child with fraction
(i + j) / j
.
For e... | 31,869 |
Divide Polygon (DTPOLY)
Determine the number of ways to cut a convex polygon with
N
sides if the only cuts allowed are from vertex to vertex, each cut divides exactly one polygon into exactly two polygons, and you must end up with exactly
K
polygons. Consider each vertex distinct. For example, there are three ways... | 31,870 |
Snow White and the N dwarfs (PATULJCI)
Snow White and the N dwarfs live in the forest. While the dwarfs mine away Snow White hangs around social networks.
Each morning the dwarfs form a long line and go whistling away to the mine. Snow White runs around them and snaps pictures to upload onto her favorite social netw... | 31,871 |
Captain Selection (CAPTAIN)
There are N people and M teams. Each team is a subset of N people.
For each team, we need to pick a captain.
No people could be a captain of more than one team.
A person
a
is said to be a subordinate of a person
b
if there is some team including both a and b in which b is the capta... | 31,872 |
Fractions on Tree ( reloaded !) (NG1FRCTN)
A fraction tree is an infinite binary tree defined as follows:
Every node of tree contains a fraction.
Root of tree contains the fraction 1/1.
Any node with fraction i/j has two children: left child with fraction i / (i + j) and right child with fraction (i + j) / j.
... | 31,873 |
The last digit re-visited (LASTDIG2)
Pappu was doing the work of his math class about three days but he is tired of make operations a lot and he should deliver his task tomorrow. His math’s teacher gives two numbers a and b. The problem consist in find the last digit of the potency of base a and index b. Help Pappu wi... | 31,874 |
Primes of Lambda (LPRIME)
Lambda
checks primality in a weird way. He checks the following two conditions.
All the digits of the number in the decimal system are primes or one, namely 1, 2, 3, 5 or 7.
It isn't a multiple of 2, 3, 5, 7, 11 or 47 (Why 47? I don't know).
In order to estimate the accuracy of his... | 31,875 |
123 Sequence (KSEQ)
A 123 sequence is defined as a non-decreasing sequence of length ≥ 2, where each number is 1 or 2 or 3. The difference between all unique pairs of numbers is given i.e. for a 123 sequence a
1
, a
2
, a
3
... and the differences are a
j
-a
i
for 1 ≤ i < j ≤ n.
Since the 123 sequence contains onl... | 31,876 |
Paradox (PARADOX)
A paradox is a statement or group of statements that leads to a contradiction. Consider the following two statements.
"The statement below is false."
"The statement above is true."
If we assume that 1st statement is true then according to 1st statement the 2nd statement is fal... | 31,877 |
Alternating Permutations (ALTPERM)
You are given K indices, A[1], A[2] ... A[K].
A[1] < A[2] < ... < A[K].
A[1] = 1 and A[K] = N.
A permutation of the numbers between 1 and N is called valid if:
The numbers in the permutation between indices A[1] and A[2] (inclusive) form an increasing sequence, the numbers in... | 31,878 |
Permutation Jumping (PERMJUMP)
John likes playing the game Permutation Jumping. First he writes down a permutation A of the first n numbers. Then, he chooses any cell to start on. If he is currently at cell x and hasn't visited the cell A[x], he jumps to cell A[x]. He keeps doing this till he cannot move to the cell A... | 31,879 |
AND Rounds (ANDROUND)
You are given a cyclic array A having N numbers. In an AND round, each element of the array A is replaced by the bitwise AND of itself, the previous element, and the next element in the array. All operations take place simultaneously. Can you calculate A after K such AND rounds?
Input
The fir... | 31,880 |
XOR Rounds (XORROUND)
You are given a cyclic array A having N numbers. In an XOR round, each element of the array A is replaced by the bitwise XOR (Exclusive OR) of itself, the previous element, and the next element in the array. All operations take place simultaneously. Can you calculate A after K such XOR rounds?
... | 31,881 |
Troops of Sand Monsters (TROOPS)
Under the command of the Evil Vizier there are N unique troops of sand monsters, where each troop contains Ci sand monsters. The Vizier in his desperate battle against the Prince of Persia has ordered all his troops to attack him simultaneously.
The Prince realizes that he cannot d... | 31,882 |
Tri (CEOI09TR)
You are given
K
points with positive integer coordinates. You are also given
M
triangles, each of them having one vertex in the origin and the other 2 vertices with non-negative integer coordinates.
You are asked to determine for each triangle whether it has at least one of the
K
given points in... | 31,883 |
Square-free Integers Factorization (SQFFACT)
Given the positive integers N = p
1
* p
2
* ... * p
k
and M = (p
1
- 1) * (p
2
- 1) * ... * (p
k
- 1), i.e. M = φ(N) (Euler's totient function), where k ≥ 1, p
i
≠ p
j
for all i ≠ j with i, j = 1, 2 ... k and p
i
is prime number for all i = 1, 2 ... k, your task... | 31,884 |
Factorial length (LENGFACT)
Given integer
n
, print length of
n!
(which is factorial of
n
).
Input
The first line of the standard input contains one integer
t
(t < 10001) which is the number of test cases.
In each of the next
t
lines there is number
n
(0 <= n <= 5*10^9).
Output
For each test, print... | 31,885 |
Finding Maximum (FINDMAX)
One way of finding the maximum element in an array is to initialize a variable to the first element in the array, iterate through the remaining array, and update the variable whenever a value strictly greater than it is found. Assuming that the array contains N elements each in the range 1..K... | 31,886 |
Finding Primes (FINDPRM)
One commonly used method to calculate all primes in the range [2 .. n] is to start with the number 2, mark it as prime, and mark all its multiples (excluding itself) as not prime. Then, we find the next smallest unmarked number, mark it as prime, and mark all its multiples (excluding itself) a... | 31,887 |
LCM Sum (LCMSUM)
Given n, calculate the sum LCM(1, n) + LCM(2, n) + .. + LCM(n, n), where LCM(i, n) denotes the Least Common Multiple of the integers i and n.
Input
The first line contains T the number of test cases.
Each of the next T lines contain an integer n.
Output
Output T lines, one for each t... | 31,888 |
Maximum Sum Sequences (MAXSUMSQ)
Given an array A having n elements, let X be the maximum sum of any contiguous sequence in the array. How many contiguous sequences in A sum up to X?
Input
The first line contains T the number of test cases. There follow 2T lines, 2 for each test case. The first line contains the... | 31,889 |
Selecting Teams (SELTEAM)
There are n players out of which at most k players are chosen to form the team squad. Out of those players, some subset of them are selected to form a team, and a player of the selected team is appointed as the captain of the team. Given n and k, determine how many possible configurations exi... | 31,890 |
Travelling Knight (TRKNIGHT)
Your task is simple. A knight is placed on the top left corner of a chessboard having 2n rows and 2n columns. In how many ways can it move such that it ends up at a corner after at most K moves?
Input
The first line contains T the number of test cases. Each of the next T lines contain ... | 31,891 |
Traversing Grid (TRGRID)
Starting at the top left corner of an N×M grid and facing towards the right, you keep walking one square at a time in the direction you are facing. If you reach the boundary of the grid or if the next square you are about to visit has already been visited, you turn right. You stop when all the... | 31,892 |
Weird Function (WEIRDFN)
Let us define:
F[1] = 1
F[i] = (a × M[i] + b × i + c) % 1000000007 for i > 1
where M[i] is the median of the array {F[1], F[2] ... F[i-1]}.
The median of an array is the middle element of that array when it is sorted. If there are an even number of elements in the array, we choose ... | 31,893 |
Frequent Prime Ranges (FRQPRIME)
A range [L..H] is called a K-Frequent Prime range if there are at least K primes amongst the numbers L, L+1 ... H. Given N and K, calculate how many subranges of the range [2..N] are K-Frequent Prime.
Input
The first line contains the number of test cases T. Each of the next T line... | 31,894 |
Yet Another Permutations Problem (YAPP)
How many permutations of the first N numbers exist such that the maximum element between the indices [i..j] is either present at index i, or at index j?
Input
The first line contains the number of test cases T. Each of the next T lines contains an integer N.
Output
Outpu... | 31,895 |
Matrix Game (MATGAME)
Two players, A and B, play the following game.
First, a matrix M of size N × M is chosen, and filled with non-zero numbers.
Player A starts the game and the players play alternately.
In his turn, a player chooses any row which has at least one non zero number in it. In this row, the left-... | 31,896 |
Dinner (DINGRP)
On the way to dinner, the CCC competitors are lining up for their delicious curly fries. The
N
(1 ≤
N
≤ 100) competitors have lined up single-file to enter the cafeteria.
Doctor V, who runs the CCC, realized at the last minute that programmers simply hate standing in line next to programmers who ... | 31,897 |
Mountain Walking (QCJ1)
In this problem your task is to program a robot that will output some data about a terrain after traversing it. Input will be in the form a 2D picture containing only 4 types of characters:
'/' : Forward slash, indicating ascent.
'\' : Backward slash, indicating descent.
'_' : Unders... | 31,898 |
Another Box Problem (QCJ2)
There are N numbered boxes placed on a table, let Bi denote the ith box in the line. Write a program that finds the total number of ways to place N identical balls such that at most k balls are present in the boxes B1 .... Bk for 1 ≤ k ≤ N. Since the number can be quite large you are suppose... | 31,899 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.