task stringlengths 0 154k | __index_level_0__ int64 0 39.2k |
|---|---|
Mines of Moria II (MORIA2)
This problem is similar but not identical to the problem
MORIA
.
In the Mines of Moria, the job of Gakrobera Silverborn the dwarf is still to load minecarts with
N
stones. The stones are numbered, from 1 to
N
, and a given minecart can only be loaded with consecutive stones.
The minecart have an optimal load
L
.
1
Each stone has an integer weight between 1 kg and
L
kg. The score of a minecart loaded with
W
kg of stones is
(
W
−
L
)
2
. After all stones have been loaded in minecarts, the total score is the sum of the score of each minecarts. The lower the total score is, the better it is.
To help Gakrobera, find the best possible way to load minecarts, given the weights of each stone from
1
to
N
.
For example, with an optimal load
L
= 2000 kg
, given four stones of 700 kg, Gakrobera will prefer to load them all in a single minecart (total score
800
2
= 640 000
). But given four stones of 800 kg, Gakrobera will prefer to load two minecarts with two stones (total score
400
2
+ 400
2
= 320 000
).
Beware: the situation in the Mines of Moria has gone wild, the Dwarves push cupidity too far, the optimal load can be very high! The Balrog will soon be awaken…
Input
The input begins with an integer
T
(
1 ≤
T
≤ 1000
), the number of test cases. Then
T
test cases follow.
Each test case is a line of space-separated integers. The first integer
L
(
1 ≤
L
≤ 10
6
) is the optimal load. The second integer
N
(
1 ≤
N
≤ 10
6
) is the number of stones to be loaded. Next come
N
integers
w
1
, …,
w
N
(
1 ≤
w
i
≤
L), where
w
i
is the weight of the stone
i
.
Output
For each test case, output the smallest possible total score.
Example
input
3
2000 4 700 700 700 700
2000 4 800 800 800 800
2000 10 100 200 300 400 500 600 700 800 900 1000
output
640000
320000
270000
Compared to the situation in the problem
MORIA
, the optimal load is not fixed. | 34,600 |
Watching over the Mines of Moria (MORIA3)
Soon after they settled in the Mines of Moria, the Orcs wanted to install a video surveillance system. The Mines of Moria are simple: they are straigh-line tunnels connecting crossings. There is at most one path to go from one crossing to another.
The Orcs want to install cameras at crossings. A camera can watch over the crossing where it sits, but also the crossings next to it, that is separated by one tunnel.
Find the smallest number of cameras that the Orcs need to watch over all the crossings.
We don’t know precisely, but here is what the Mines of Moria may look like. The crossings are numbered from 1 to 10. The node 0 represents the outside world and need not be covered by a camera. In this example, it is possible to watch over all the crossings with only three cameras.
Input
The inputs that with an integer
T
(
1 ≤
T
≤ 1000
), the number of test cases. Then follows
T
lines, one for each test case.
Each test case start with an integer
N
(
1 ≤
N
≤ 2×10
6
), the number of crossings. Then
N
integers
a
1
, …,
a
N
follow, where
a
i
is the crossing next to the crossing
i
that when going towards the outside. The integer
a
i
is zero if
a
i
is directly connected to the outside.
The depth of the tree is at most
10
4
.
Output
For each test case, output the cardinality of the smallest subset
S
of the crossings such that each crossing is in
S
or adjacent to a crossing in
S
.
Example
input:
3
3 0 0 0
3 0 1 2
10 2 0 2 5 8 5 8 0 7 9
output:
3
1
3 | 34,601 |
A Simple Sieve (ASSIEVE)
You are given a commutative associative unitary function \(x(i,j)\) defined over all \(0\le i,j,x(i,j)\lt 4\). In other words, this function satisfies, for all \(0\le i, j, k \lt 4\):
\(x(i,j)=x(j,i)\)
\(x(x(i, j), k)=x(i, x(j, k))\)
\(x(0, i)=i\)
Define a function \(f(n)\) for all positive integers \(n\) such that:
\(f(p^k)=(pk)\bmod 4\), that is, the remainder when \(pk\) is divided by 4
If \(\gcd(a, b)=1\), then \(f(ab)=x(f(a),f (b))\)
Define:
$$g(n,k,r)=\sum_{i=1}^ni^k[f(i)=r]$$
where \([f(i)=r]\) is the
Iverson bracket
.
Given the function \(x\) and two integers \(m\), \(k\), for all integers \(1\le i\le\lfloor\sqrt n\rfloor\), calculate \(g(\lfloor\frac ni\rfloor, k, 0...3)\) modulo \(998\ 244\ 353\).
Input
The first line contains two integers \(m\) and \(k\). (\(1\le m\le 10^{10}\), \(0 \le k \le 1000\))
The following 4 lines contains 4 integers each. The i-th row j-th integer contains \(x(i-1,j-1)\).
Output
Output \(\lfloor\sqrt n\rfloor\) lines containing 4 integers each. The i-th row j-th integer contains \(g(\lfloor\frac ni\rfloor, k, j-1)\) modulo \(998244353\).
Example
Input:
10 0
0 1 2 3
1 2 3 0
2 3 0 1
3 0 1 2
Output:
2 2 3 3
2 1 1 1
1 0 1 1
Input:
100 100
0 1 2 3
1 0 3 2
2 3 0 1
3 2 1 0
Output:
457599333 476580683 403589597 762762658
361221912 612412943 661908092 483645330
242804711 682542199 535167020 465246643
913280460 516845083 917292729 390364642
39265044 919790719 181416471 421087779
530140662 31014314 181416471 226287885
982924733 31014314 851084249 226287885
982924733 938693280 851084249 226287885
982924733 938693280 851084249 435036575
982924733 938693280 851084249 138976409 | 34,602 |
Stacks of boxes (STACKOFBOXES)
There are
N
stacks of boxes, all boxes have same dimensions as 1 unit. The height of a stack is defined as the number of boxes in it. The initial height of
i
th
stack is given as
h
i
. We need to equalize the heights of stacks by adding, removing or moving the boxes across the stacks.
The cost of each operation is defined as following:
Add a box on top of a stack costs
A
.
Remove a box from top of a non-empty stack costs
R
.
Moving a box from top of non-empty stack to top of another stack costs
M
.
Input
First line contains one integer
N
.
Second line contains 3 integers the costs
A, R, M
.
Third line contains the
N
integers as heights
h
i
for
i
th
stack.
1 <= N <= 10
5
0 <= A, R, M <= 10
4
0 <= h
i
<= 10
9
Output
One integer in a line - the minimum cost of equalising the heights of all stack by using above operations.
Example
Input:
5
1 2 2
5 5 3 6 5
Output:
3
(Move 1 box from 4th stack to 3rd stack now height are (cost 2) → 5 5 4 5 5 → now add one box on 3rd stack (cost 1), total cost = 3. | 34,603 |
Escape the New America (RDR2_1)
So, Mr. Intelligent, have you played the game
Red Dead Redemption 2
? Yeah, man, this game deserves a Heavenly place in the hearts of gamers.
Our hero
Arthur Morgan
is now on Newyork city in the modern civilization of America. As always, he is now being chased by some Cops. As the civilization has developed a lot, now there are a lots of Police Stations in different places of Newyork. And there are also a lots of buildings and shopping malls spreading all around the city. Besides there are also some docks from which our hero Arthur can get out of the New America as well as escaping from the cops. There are some roads in between all the obstacles of the city which will lead our hero to any docks from which he can escape.
In this problem, we will consider Newyork city as an N × M matrix. Where each police station is denoted as the letter 'S' and the roads are considered as '.'. And whenever you find the character '#', that means
nobody
can get through this as it is an obstacle. Arthur and the Cops can only travel through the roads. Each Police Station contains exactly one cop. Each one cop will start his journey from a police station and will move along the road. And by any means,
if our hero Arthur can get to any border of the given matrices without being caught by the cops, that means, he has escaped. Remember, that border should not contain any obstacle nor any police station.
You're given the initial position of Arthur ('A'). Note that,
the cops can start their journey from any police station and can also move only along the roads. Arthur has to move in such a way that, there are no cops at that time when he get through that certain point of road
.
Now, as being an intelligent companion of Arthur, you have to tell, if it is possible to get out of the New America. If it is possible, you have to tell the path which Arthur should follow and the length of that path.
Constraints
1 ≤ n, m ≤ 1000
Input
The first input line has two integers n and m: the height and width of the map.
After this there are n lines of m characters describing the map. Each character is . (road), # (obstacles), A (starting position of Arthur), or S (Police Stations). There is exactly one A in the input.
Output
First print "YES" if your goal is possible, and "NO" otherwise.
If your goal is possible, also print an example of a valid path (the length of the path and its description using characters D, U, L, and R). You have to print the shortest path, as long as its length is at most n × m steps.
Sample
Input 1:
4 4
#.#S
#.##
#A..
####
Output 1:
YES
2
UU
Input 2:
4 4
#..S
#.##
#A.#
####
Output 2:
NO | 34,604 |
Chips Challenge (CHIPSLL)
Chip’s Challenge is a classic top down puzzle game played on a
N × M
grid. Released in 1989, the protagonist of the game is the high-school nerd Chip McCallahan, who has met Melinda The Mental Marvel in the school science laboratory and fell in love at first sight! Chip must navigate through Melinda’s clubhouse, consisting of several increasingly difficult puzzles, in order to prove himself and acquire Melinda’s heart and also gain access to the very exclusive Bit Busters Club. Such is the premise of this vintage game, cliched, but who cares about the plot when the gameplay is so cool?
The game consists of more than one hundred two-dimensional levels. Gameplay involves using the arrow keys of the numeric keyboard or mouse to move Chip around each of the levels in turn. To progress through each level, Chip needs to interact with various game elements like computer chips, buttons, locked doors, water and lethal monsters. There are also some levels containing block-pushing puzzles and dodging enemies. Below is an example of a level from the actual game.
In this problem, we will attempt to solve a simplified variation of the game Chip’s Challenge. You will be given a
N × M
grid with Chip’s starting position and also the position of Melinda The Mental Marvel. The grid will consist of empty cells, water, lethal monsters and locked doors only. The rules of this game are a bit different than the original version, so pay close attention to the following details. Chip starts from his initial position and wants to travel to Melinda’s location. To do so, he can navigate to any four of the adjacent cells from his current position using the arrow keys up, down, left and right. Provided the cell he wants to move to is empty and inside the grid, he will move to the cell and the whole process takes
exactly 1 second
. Otherwise, Chip is not allowed to make a move.
He can also click on any cell that is not empty and attempt to destroy it. Any cell that is not empty can be destroyed and once destroyed, the cell becomes empty for the rest of the game. Note that the cell does not necessarily have to be adjacent to Chip’s current position while destroying it. Initially empty cells are marked using the character ‘.’ (dot) and both Chip’s starting position and Melinda’s positions are initially empty cells and are different. Every non-empty cell has a power value and destroying a cell with power value
X
takes exactly
X
clicks, hence
X
seconds in total. That is, per click it takes 1 second. Keep in mind that the non empty cells can either consist of water, monsters or locked doors.
Cells containing water are marked using lowercase letters, therefore there can be
26
different types of water. The power value of a cell containing water is equivalent to its position in the alphabet. That means if a cell contains the character
'a'
, it’s power value is
1
, if a cell contains the character
'b'
it’s power value is
2
, and similarly for
'z'
it’s power value is
26
. Monsters are marked with uppercase letters, and their power values are calculated by adding
26
with its position in the alphabet. So if a cell contains
'A'
, the power value of it will be
27
, for
'B'
it will be
28
and similarly for
'Z'
it will be
52
. Lastly, cells containing locked doors will be represented by the digits
0-9
. The power value of a cell containing a locked door will be the value of the digit plus
53
. If a cell contains a locked door labeled
'0'
, it’s value will be
53
, for a cell having locked door labeled '1', the power value will be
54
and for the locked door
'9'
, the power value will be
62
.
Chip can’t wait to rejoin the love of his life and join the Bit Busters club with her and he wants to reach her in the shortest time possible. Given the description of the maze, the initial position of Chip McCallahan and Melinda The Mental Marvel, can you suggest how to play Chip’s Challenge optimally so that Chip can reach Melinda as fast as possible?
Input
The first line will contain a single integer
T
and then
T
test cases follow. Every test case contains two lines. The first line contains
6
integers -
N, M, Cx, Cy, Mx, My
. The grid dimensions are denoted by
N
and
M
,
(Cx, Cy)
indicates the starting position of Chip and
(Mx, My)
the starting position of Melinda. The maze will be generated pseudorandomly. The second line of every case contains one integer called seed, and the maze is generated by following the C++ code snippet described below. Note that
seed
is a global variable that is initialized once at the start of every test case with the value given, and gets updated after each
update_seed()
call.
long long seed;
char maze[2021][2021];
void update_seed(){
seed = (seed * 1000003 + 10007) % 1000000009;
}
void gen_maze(int N, int M, int Cx, int Cy, int Mx, int My){
for (int i = 1; i <= N; ++i){
for (int j = 1; j <= M; ++j){
if ((i==Cx && j==Cy) || (i==Mx && j==My)){
maze[i][j] = '.';
continue;
}
update_seed();
int power = seed % 63;
if (power == 0)
maze[i][j] = '.';
else if (power <= 26)
maze[i][j] = power - 1 + 'a';
else if (power <= 52)
maze[i][j] = power - 27 + 'A';
else
maze[i][j] = power - 53 + '0';
}
}
}
Constraints
1 ≤ T ≤ 10
1 ≤ N, M ≤ 2000
1 ≤ Cx, Mx ≤ N
1 ≤ Cy, My ≤ M
(Cx, Cy) ≠ (Mx, My)
0 ≤ seed ≤ 1000003
Output
Print the case number followed by the shortest time to complete Chip’s Challenge if played optimally. Check the sample for more details.
Example
Input:
2
3 3 1 1 3 3
3
1 3 1 1 1 3
1
Output:
Case 1: 29
Case 2: 59
Explanation
For the first test case, the maze looks like:
.bl
JaS
Gv.
The shortest path from (1,1) -> (3,3) is the following:
Destroy cell (1, 2) in 2 seconds.
Destroy cell (2, 2) in 1 second.
Move right from cell (1, 1) to cell (1, 2) in 1 second.
Move down from cell (1, 2) to cell (2, 2) in 1 second.
Destroy cell (3, 2) in 22 seconds.
Move down from cell (2, 2) to cell (3, 2) in 1 second.
Move right from cell (3, 2) to cell (3, 3) in 1 second.
Therefore the overall journey takes
2 + 1 + 1 + 1 + 22 + 1 + 1 = 29
seconds. | 34,605 |
The Revenge Of Anti Hash (AHASHREV)
Given a base
B
and a modulus
M
, the polynomial hash of a string
S
, consisting of only lowercase letters
(a-z)
is defined as below:
int GetHash(string str, int B, int M){
long long hash = 0;
for (auto chr: str)
hash = (hash * B + chr - 'a' + 1) % M;
return hash;
}
In other words, first the letters of the string are replaced by numbers (equivalent to their position,
'a'
gets mapped to
1
,
'b'
to
2
, ... and
'z'
to
26
). This is then considered to be a number in base
B
(the rightmost number is the least significant digit), and the value of this number taken modulo
M
is called the polynomial hash of the string.
Limak the bear loves to hack other contestants in Codeforces. After the recent educational round, he came to know that his friend Swistak used the polynomial hash function stated above to solve the hardest problem! And believe it or not, he was the only one to solve that problem which eventually made him the round champion! Limak is very angry, how can Swistak solve a problem which Limak himself couldn't solve? And worst of all, Swistak used hashing to solve that problem. Limak believes people who use hashing have no real skill, getting 'Accepted' just implies getting lucky, nothing more.
Limak is just a little bear, he is not very good at solving problems. But after hours of scratching his head, he was able to come up with a solution involving birthday attacks. That should hack Swistak’s solution since educational rounds allow hacking for 24 hours after the round ends. And voila! When he coded it later that night, he was finally able to come up with a case that broke Swistak’s solution. And down he goes. From the top place to 153, even below Limak! Limak was overwhelmed with joy.
When Swistak woke up the next morning and casually checked the rank list he was furious. He could not believe what he saw, rolling his eyes in disbelief. He was the only contestant to solve the last problem and that earned him the top place. But alas! No more, because someone hacked his solution and he dropped down more than a hundred fifty places. He clicked on the problem to see who hacked him, and his disbelief grew to anger and frustration when he realized it was his friend Limak! He couldn’t believe his eyes. “I thought he was my friend, how could he do this to me?”, he wondered. He vowed to take revenge. He modified his solution to use double hashing. But just to be extra sure so that Limak can never hack his solution ever again, he hashed it a few more times resulting in
K
total hashes. Then he submitted his solution which passed the tests and Limak’s initial hack as expected.
Afterward, he rushed to Limak’s place and challenged him to a duel. He claimed Limak was jealous and just got lucky while hacking his solution and has no real hacking skills. Feeling overconfident with his new solution, Swistak challenged Limak to hack his new solution and suggested he will retire from competitive programming if Limak can hack his new solution. But if however, Limak fails, then Limak must retire instead!
Limak, being provoked like this, takes up the challenge without thinking it through. But he has no clue how to solve it, he is just a little bear after all. He thought about it throughout the whole day but has no idea how to crack it. With just 4 hours left before the hacking phase ends, he desperately turns to you for help. He knows this isn’t exactly fair, but nothing’s fair in love and war as they say and he doesn’t want to retire from competitive programming. Not now and not ever. Please help Limak solve the following problem and beat Swistak once and for all, thereby saving his career.
Limak will give you
K
pairs of numbers,
(B
1
, M
1
), (B
2
, M
2
), … , (B
K
, M
K
)
. Each pair consists of a base
B
and a modulus
M
. These are the numbers Swistak used to hash strings
K
times in his new solution. Limak needs you to find
two different strings
consisting of lowercase letters only. The strings must have the same hash value when hashed with each of the
K
base/mod pairs with the above described function. Since Codeforces will not accept just any string of arbitrary length as hack inputs, each of the strings also need to be non-empty and cannot exceed more than
65536
characters in length. They can be of different lengths though.
Input
The first line contains
T
, denoting the number of test cases. Then
T
test cases follow. The first line of each case contains an integer
K
. The next
K
lines consist of two integers
(B
i
, M
i
)
. These are the base and mod pairs Swistak used in his hash function.
Constraints
1 ≤ T ≤ 20
1 ≤ K ≤ 12
32
≤ B
i
≤ 256
1
≤ M
i
≤ 256
Output
For each test case, output the required two strings separated by a single space. If there is more than one solution satisfying all the above criteria then you may output any of them. You can be assured that there will always be at least one pair of strings.
Sample Input
1
1
32 1
Sample Output
hello world
Challenge
You might also enjoy:
Anti Hash
Anti Hash II | 34,606 |
Ambitious XOXO (DEV_CP)
Life is a growth.
If we stop growing,
Technically and spiritually,
We are as good as DEAD
- Morihei Ueshiba
Our hero
XOXO_Bunnyface
is a programmer. He loves to append his name just after the precious word, “Competitive”. He is not much intelligent, nor much logical. But he loves to learn new algorithms and he loves to practice.
The world he is currently living has
N
algorithms. You will be given an
array of efficiency
of size
N
, where if the i
th
element is x, that means the initial efficiency of XOXO on that algorithm is
x
.
XOXO will do
M
tasks in this month in order. The tasks will be of two types.
1 K X
That means, the efficiency of XOXO on the
k
th
algorithm will be changed to
X
. It’s not guaranteed that the new value of
k
th
index will be greater than the initial value. The efficiency might also decrease. XOXO is a human being after all.
2 A B
There will be a contest arranged on which the efficiency of XOXO will be tested on the algorithms in the range between
A
and
B
inclusive. In that case, you have to tell the performance of XOXO on that contest which will be the sum of efficiencies inside that range.
Input
The first input line has two integers
N
and
M
: the number of values and tasks. The second line has
N
integers e1, e2 ... eN: the values of the array of efficiency. Finally, there are
M
lines describing the tasks list. Each line has three integers: either "
1 K X
" or "
2 A B
"
Output
Print the result of each query of type 2.
Constraints
1 ≤ N, M ≤ 2×10
5
1 ≤ e
i
, X ≤ 10
9
1 ≤ k ≤ N
1 ≤ A, B ≤ N
Samples
Input:
5 5
2 3 6 4 8
2 1 4
2 5 5
1 3 1
2 1 4
2 2 4
Output:
15
8
10
8 | 34,607 |
Where Proofless Assumption Fails (XUDOKU)
Observe the Patterns,
Your assumptions might DO.
But, what will be your approach,
When there will be no CLUE...?
--- XUDOKU
XOXO_Bunnyface
is learning Bit masking. While watching the tutorials on Bit masking with his friend
George Boole
, an idea came upon the mind of
George
. As being the inventor of the Boolean algebra,
George Boole
invented a game to trick
XOXO
, who always prefer assumptions than proof.
George
named the game as
XUDOKU
. The game consists of a
3 × N matrices
. Where 3 is the constant number of rows and N is the number of columns. Initially the first row is filled with N integers. To win the tricky game,
XOXO
has to fill the remaining two rows with some integers in such a way that, the following conditions are true.
X
(3, i)
= X
(1, i)
⊕ X
(2, i)
; for all i (1 ≤ i ≤ N).
X
(3, i)
= X
(3, i + 1)
& X
(3, i)
; for all i (1 ≤ i ≤ N - 1).
The number sequence of the 2
nd
row should be
lexicographically smallest
.
The number sequence of the 3
rd
row should be
non-decreasing.
(
X
(i, j)
means the j-th element of the i-th row of the XUDOKU matrices).
Input
The first line contains G (1 ≤ G ≤ 1000), the number of games to be played.
The second line contains N (2 ≤ N ≤ 2×10
5
), the width of the XUDOKU board. I.e. number of columns.
The Third line contains N integers of the First row. X
(1, j)
(0 ≤ X
(1, j)
< 2
30
)
Output
For each G, you have to print the output in the following manner.
Game #G
i
X
(1, i)
X
(1, i + 1)
X
(1, i + 2)
X
(1, i + 3)
X
(1, i + 4)
... X
(1, N)
X
(2, i)
X
(2, i + 1)
X
(2, i + 2)
X
(2, i + 3)
X
(2, i + 4)
... X
(2, N)
X
(3, i)
X
(3, i + 1)
X
(3, i + 2)
X
(3, i + 3)
X
(3, i + 4)
... X
(3, N)
Samples
Input:
3
4
9 3 7 13
8
18 6 3 2 4 0 0 4
4
16 18 17 14
Output:
Game #1
9 3 7 13
0 8 8 2
9 11 15 15
Game #2
18 6 3 2 4 0 0 4
0 16 20 21 19 23 23 19
18 22 23 23 23 23 23 23
Game #3
16 18 17 14
0 0 2 17
16 18 19 31 | 34,608 |
Crowded Music Festival (FESTIVAL)
You are the organizer of a music festival, which lasts for N days. Every day a new band arrives, and plays during K days, as long as the festival is still running. Hence in total N bands are playing at the festival, but not necessarily all on the same day. For the band arriving on day
i
, you know that X
i
people are going to attend each of their concerts. Every day you have up to K concerts, and you need to scale the facilities to accommodate for the maximum attendance to the concerts on that day. Scaling the facility on a specific day to accommodate a public of size y, costs you y Euros. Your goal is to compute the total cost over the N days.
Input
The first line contains two integers N and K separated by a space. It is followed by N lines, each containing a single integer X
i
.
Constraints
1 ≤ N, K ≤ 1 000 000
1 ≤ X
1
... X
N
≤ 1 000 000
Output
Output a single line containing the total cost.
Example
On day 1 you need to accommodate for the unique concert of the day, that is for 6 people. On day 2 you need to accommodate for two concerts, the first one for 6 people and the second one for 2 people, hence for the whole day you need to accommodate for 6 people. On day 3 you need to accommodate for 4 people only. This gives a total cost of 6 + 6 + 4 Euros.
Input:
3 2
6
2
4
Output:
16 | 34,609 |
Internet Spamming (SPAM_ATX)
Two Years from now,
Spam will be solved.
Bill Gates (2004)
Let’s imagine...
The World has evolved so much. Nowadays, the anger of rivalries is being extinguished by the help of internet. You’re the Mr. Despicable of the underworld and you have invented a new cyber virus, which acts like a SPAM.
As people are getting more and more virtual, the count of Social sites are being raised on the peak rate. You want to deal damage to some Social Sites. Remember, “Suffering is more painful than Death”. So, your goal is to
deal damage to as many sites as possible, rather than totally destroying a site
.
Each of the viruses will send some spam mails. If a user receives a Spam, the account of the user will be removed forever from the site that the user is using and the site will lose one of its users.
Now, being a Programmer, you know a virus is nothing but a set of instructions. You have coded everything a virus has to follow except one thing, “On which site a certain virus should attack?” Now, you have to write a program that will tell each virus on which site it should attack. There is also a bug on your viruses.
A virus cannot attack a site, unless the count of users on that site is more than or equal to the count of spams the virus can produce. Moreover, the viruses will start attacking maintaining the order in which they are given in the input. The first virus will start sending Spams first, then the second one, and so on...
Now, write a program that will tell a virus, on which site it should attack.
Input
Line 1: N (≤ 2e5), M (≤ 2e5) [Number of Sites and Number of Viruses]
Line 2: U
1
, U
2
, U
3
... U
n
(U
i
≤ 1e9) [Number of Users on the i
th
site]
Line 3: P
1
, P
2
, P
3
... P
m
(P
i
≤ 1e9) [Number of spam mails the i
th
virus can produce]
Output
Line 1: I
1
, I
2
, I
3
... I
m
(1 ≤ I
i
≤ N) [Index of the Site the i
th
virus should attack on]
Note:
If there are no sites, the i
th
virus can attack, print 0 on the i
th
index.
Sample
Input:
10 10
7 2 9 5 1 2 1 1 2 5
7 5 6 4 8 3 9 10 1 6
Output:
1 3 0 3 0 4 0 0 2 0
Explanation
1
st
virus attacked the 1
st
site, after that the users of the 1
st
site decreased to 0. Now, no virus can attack the 1
st
site.
2
nd
virus attacked the 3
rd
site, and then the users of the 3
rd
site decreased to 4 and later on, it was attacked again by the 4
th
site and got users count decreased to 0.
Now, there remains no sites, which has users more than or equal to the spam mails of the 3
rd
virus. That’s why, it can attack no site. | 34,610 |
Teleporters and Gems II (TLPNGEM2)
Last time Duck was playing "
Teleporters and Gems
" online game, but this time he is going to collect a big gem in person! To solve this problem, it is not necessary to solve the previous one.
Duck has 5 teleporters, he wants to collect a big gem with the help of these teleporters. These teleporters not only help him teleport to any coordinates, but also receive the signal from that gem, which is measured by the manhattan distance from the target coordinates to the big gem. In other words, whenever Duck uses a teleporter, he will be sent to the place (x, y) he wants to visit and knows the distance from there to the gem |x - x
gem
| + |y - y
gem
|.
Unfortunately, Duck doesn't know the exact location of the big gem. He wants you to help him collect that gem by using
at most 5 teleporters
, meaning that for the last time to use a teleporter, the return distance must be 0. Once you receive 0, you must process next test case immediately. You can start at any random coordinates.
Interactive protocol
This is an interactive problem, you are going to communicate with the judge via standard input and output. To make sure your program output actually goes out, remember to
flush the output buffer after printing each line
.
Initially, your program should read a single line containing an integer
T
indicating the number of test cases. Then you need to process T test cases.
For each test case, your program needs to use standand output to send a single line with two integers "
X Y
" (with a whitespace between them, without double quotes), indicating the target coordinates you want to teleport to. In response, the judge will print a single line with one integer
D
to your input stream, which your program must read through standard input, indicating the manhattan distance between (X, Y) and the big gem.
If D is 0, the gem is found so you must process next test case immediately
. Otherwise, you can repeat the above procedure to start a new exchange. Note that the
maximum number of exchanges is 5
, which means you should not output something more than 5 times via standand output for each test case. Otherwise, you will receive wrong answer.
Constraints
1 ≤ T ≤ 100
-10
9
≤ X, Y ≤ 10
9
Sample interaction
Judge:
2
// Number of test cases
You:
7 10
// Start test case 1, you teleport to (7, 10)
Judge:
3
// Manhattan distance between (7, 10) and gem is 3
You:
5 11
// You teleport to (5, 11)
Judge:
2
// Manhattan distance between (5, 11) and gem is 2
You:
5 9
// You teleport to (5, 9)
Judge:
0
// Manhattan distance between (5, 9) and gem is 0. You found it by 3 teleporters.
You:
-3 1
// Start test case 2, you teleport to (-3, 1)
Judge:
7301
// Manhattan distance between (-3, 1) and gem is 7301
You:
-2451 -4852
// You teleport to (-2451, -4852)
Judge:
0
// Manhattan distance between (-2451, -4852) and gem is 0. You found it by 2 teleporters. | 34,611 |
Układanie kart - Card stacking (MWPZ017)
Grając w karty pewnie zetknąłeś się z koniecznością ułożenia w pewnej kolejejności dużej liczby kart trzymanych w ręku. Nierzadko trzeba to zrobić bardzo szybko, żeby nie blokować gry.
Rozważmy pewne uproszczone zasady sortowania kart. W jednym korku możemy wyciągnąć dowolną (dokładnie jedną) kartę z wachlarza trzymanego w ręce i włożyć ją w dowolne inne miejsce. Twoim zadaniem jest dla zadanej kolejności kart w wachlarzu, który trzymasz na pocztąku, podać w ilu najmniej krokach można go posortować.
Wejście
Pierwszy wiersz wejścia zawiera liczbę zestawów testowych. Każdy zestaw składa się z dwóch wierszy. Pierwszy zawiera liczbę kart
N
(1 ≤
N
≤ 1000) trzymanych w ręce. Drugi wiersz zawiera permutację zbioru liczb {1, 2 ...
N
}, który reprezentuje kolejność kart w wachlarzu, jaki trzymamy na pocztąku.
Wyjście
Dla każdego z zestawów należy wypisać w ilu najmniej krokach da się posortować karty rosnąco.
Przykładowe wejście
3
3
1 2 3
3
3 2 1
5
1 5 3 2 4
Przykładowe wyjście
0
2
2
---
When playing cards, you have probably experienced the necessity of arranging the large number of cards held in your hand in a certain order. It is not uncommon to want to do this very quickly so as to not block the game.
Consider some simple rules for sorting cards. In one turn, you can remove any (exactly one) card from the fan held in your hand and put it in any other place. Your task is, for the given order of cards in the hand at the beginning, to specify in how many least steps it can be sorted in the sorted order.
Input
The first line of input contains the number of test sets. Each set consists of two lines. The first contains the number of N (1 ≤ N ≤ 100000) cards held in hand. The second line contains a permutation of the set of numbers {1,2 ... N} that represents the order of the cards in hand at the very beginning.
Output
For each set, write out in how many least steps the cards can be sorted ascendingly.
Sample Input
3
3
1 2 3
3
3 2 1
5
1 5 3 2 4
Sample Output
0
2
2 | 34,612 |
Kamil (KAMIL)
Some kids cannot pronounce all letters, some of them they sometimes pronounce correctly and sometimes incorrectly. Kamil sometimes says T instead of K, but he never says K instead of T. Similarly he sometimes says D instead of G. Instead of R he sometimes says L and sometimes F. Of course it happens that he pronounces the letter correctly. Kamil's father always thinks how many words can mean the word spoken by his son (it doesn't matter if they are real English words).
Task
Write a program which
reads from standard input the words spoken by Kamil,
counts how many different words can that mean,
writes the outcome on standard output.
Input
Ten test cases (given one under another, you have to process all!). Every test case is a single line - a word spoken by Kamil. Only 26 capital letters are used. The length of the word is at most 20.
Output
For every testcase write an integer in a single line with a single integer, denoting the number of words which Kamil's word can mean.
Score
The score awarded to your program is the number of bytes the source code you submit. The fewer points you score, the better. Submissions are not allowed to exceed 256 bytes.
Remark. It may turn out impossible to solve this problem in some languages.
Example
Input:
FILIPEK
[and 9 test cases more]
Output:
4
[and 9 test cases more] | 34,613 |
Food Shortage in Byteland (BYTEFOOD)
Fanatics from the BBFO blew up all the food factories in the Bytelandian capital! Hurry up! There is still some food left in shops. Some shops are located in the centre, others in the suburbs, so Johnny has to decide which of them are worth visiting. Some shops can be very big and have plenty of food in them, others may be so small that food dissappears from them at an alarming rate... So? Help Johnny buy as much food as possible.
There are
n
open shops, each of them located at position (
x
i
,
y
i
), for
i
=1,...,
n
, where 0 <=
x
i
,
y
i
<= 250. The distances between shops are measured using the Manhattan metric (i.e. as sums of absolute values of differences of x and y coordinates). Besides, every shop is characterized by a linear time function describing how much food is left in the shop at the moment:
f
i
=
max
{0,
a
i
-
b
i
*
time
}
where 0 <=
a
i
<= 1000000, 0 <=
b
i
<= 1000, while
time
is the time (in minutes) that has elapsed from the moment Johnny left the house (assume that Johnny does not live in the same place as any shop). If Johnny decides to stay in a shop, he can buy at most
b
i
units of food per minute. Otherwise, he can move along the ortogonal system of streets of the city at a constant speed of unit distance per minute. Johnny only ever changes the action he is performing at the full minute. Because his family is slowly beginning to starve, he should be back at home not later than
m
minutes after he left.
Since there are thousands of starving families in the capital, Johnny can't spent more that 1 <=
c
i
<= 10 minutes in a shop. Moreover, he will never go into the same shop twice for fear of being lynched...
Input
The first line of input contains a single positive integer
t
<= 1000, the number of test cases.
Each test case begins with the number of shops in the city 1 <=
n
<= 1000 and the deadline 1 <=
m
<= 5000.
Then the following
n
lines consist of four integers
x
i
y
i
a
i
b
i
c
i
each, describing the position and the parameters of the function for food availability of the
i
-th shop. At the end of every test case comes a line with two integers
p q
(between 0 and 250), corresponding to the x and y coordinates of the position of Johnny's house.
All the input data are integers.
Output
Process all test cases. The correct output for the
i
-th test case takes the following form:
i
[the number of the test case, in the input order]
s m
[
s
is the number of the target shop and
m
> 0 is the number of minutes spent in it].
At the end of the series of moves you should always write a line conisting of two zeros ('0 0').
All the output data should be integers.
Scoring
The score of your program is the total amount of food that Johnny bought (summed over all the testcases in which he managed to come back home before the deadline).
Example
Input
4
2 20
0 0 100 5 5
10 0 200 10 10
5 0
2 20
0 0 180 15 10
10 0 200 20 10
5 0
4 101
0 0 1000 20 5
20 0 200 1 5
0 20 5000 200 5
20 20 300 5 10
10 10
1 15
1 0 10 1 5
5 0
Output
1
2 10
0 0
2
1 10
0 0
3
3 5
4 10
2 1
0 0
4
1 5
0 0
Score
Score = 1261 | 34,614 |
Solovay-Strassen Inverted (SOLSTRAS)
Let us denote the set of all prime numbers by the symbol
P
. The
Solovay-Strassen algorithm determines whether a given positive odd integer
n
>2
belongs to
P
.
The
Legendre function
sig
for number
n
N
with parameter
s
N
(
s
<
n
) is defined by the formula
sig
(
n
,
s
)=
s
(
n
-1)/2
mod
n
. The symbol
mod
is defined in such a way as to return the result with the smallest possible absolute value, from the range (-n/2, n/2].
The
Jacobi function
jac
for number
n
N
with parameter
s
N
(
s
<
n
) is given as:
jac
(
n
,
s
)=
sig
(
n
,
s
),
if
n
P
k
i
=1
sig
(
p
i
,
s
),
if
n
=
k
i
=1
p
i
, where all
p
i
P
It is interesting to note that for given
n
and
s
, the values of
sig
(
n
,
s
) and
jac
(
n
,
s
)
can be computed in
O
((log
2
n
)
2
)
time. For particulars consult an encyclopedia, such as
MathWorld
.
The deterministic version of the Solovay-Strassen primality-test algorithm is
given below.
algorithm
Solovay-Strassen
(
n
)
var
s
;
begin
for
s
in
{1,2,3,4,...,
n
}
do
if
sig
(
n
,
s
)
jac
(
n
,
s
)
then return
"
n is composite
(
detected at attempt <
s
>)";
return
"
n
is prime
";
end
.
Task
We are not asking you to implement the Solovay-Strassen algorithm, this would
be far too easy :). Instead, try to find values of
n
, for which the
output of the algorithm would be "
n
is composite (detected at attempt 1)",
"
n
is composite (detected at attempt 2)", and so on. Write out as many of
these values as you can in consecutive lines, and try to keep them as small as
possible.
Scoring
The score awarded to your program is the total of all points given for its
individual lines.
The
i
-th line output by your program should contain exactly one positive
odd integer
n>2
of no more than 500 decimal digits. If
Solovay-Strassen(
n
) yields the answer "
n
is composite (detected at
attempt
i
)", you will receive
i
/log
10
n
points for this line, if not - your program will be considered
incorrect. Output 0 if you don't want a line to be assessed. Only the first
1000 lines of output are taken into account.
Example
A program outputing:
0
0
561
will receive 3/log
10
561 = 1.091 points. | 34,615 |
Johnny Goes Shopping (JOHNNY)
Johnny visited his favourite supermarket to purchase as many sweets as he could afford. Since daddy had left his credit card at home untended, this was not really a problem. Once he had (barely) managed to push the trolley laden with chocolate bars past the cash desk, he began to wonder how to carry all the shopping home without breaking his back.
You must know that Johnny is a perfectly normal child, and has exactly 2 hands. Help him distribute his load between both hands so as to minimise the difference in load between both hands.
Input
The first line of input contains a single integer
n
<= 10000 denoting the number of sweet packets Johnny has bought. In each of the next
n
lines a single positive integer is given, describing the weight of the respective packet (the weight is an integer value never exceeding 10
14
).
Output
In separate lines, output the numbers of the packets which Johnny should carry in his left hand. Assume packets are numbered in the input order from 1 to
n
.
Scoring
Your program shall receive log
10
(
s
/(|
d
|+1)) points, where
s
is the total weight of all parcels, while
d
denotes the difference in weight between the load carried in Johnny's left and right hand.
Example
For the sample input:
3
5
8
4
a program outputting:
2
3
will score log
10
((5+8+4)/(|8+4-5|+1))= 0.327 points. | 34,616 |
Solving the Puzzle (SOLVING)
The 15 puzzle is a classic puzzle made famous in the 19th century. It consists of 4x4 board with 15 sliding tiles numbered from 1 to 15. The objective is to get them into this pattern:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Here we will deal with a generalized version of the above puzzle. You should write a program that given some initial state of the nxn board finds a sequence of moves that transforms it so that in the i-th row there are tiles with
numbers i*n+1,i*n+2,...,i*n+n (from left to right) - with the exception of the lower right corner where the hole should be. The less moves you use, the more points you get.
Input
The first line of input contains the number of test cases c (c<=200). Then c test cases follow, each of them begins with a line with a single integer n (3<=n<=10) in it. The next n lines describe the initial state of the board - the i-th line consists of exactly n integers describing the i-th row. The position of the hole is indicated by 0.
Output
For each test case output one line - the found sequence of moves. Write 'D' to move the hole down, 'U' to move it up, 'R' to move it right and 'L' to move it left. You shouldn't use more than 10000 moves. All moves should be valid (so for example don't try to move the hole up when it is in the first row).
Scoring
Your program will receive n^3/(m+1) points for each test case where m is the number of moves.
Example
Input:
2
4
1 2 7 3
5 6 0 4
9 10 11 8
13 14 15 12
3
0 1 2
4 5 3
7 8 6
Output:
URDDD
RRDD | 34,617 |
Points on a Sphere (PSPHERE)
Imagine a number of identically charged weightless dimensionless particles placed on the surface of a ball. They will instantly reach a state of equilibrium (a stable state of minimum energy), becoming distributed fairly evenly all round the sphere.
You probably won't be surprised to hear that Byteland has a sadly distorted electrostatic field, and the energy of the system is not governed by ordinary laws. Instead, it is inversely proportional to the distance between the closest pair of charges on the sphere.
Please help the charges find positions in which they will feel as comfortable as possible. Charges should be regarded as points in 3D space, located on the surface of the unitary sphere (with center (0,0,0) and a radius of 1).
Input
An integer t denoting the number of test cases (t<=10), followed by t test cases, each consisting of a line with a single integer n - the number of points on the sphere (2<=n<=1000).
Output
For each test case, output n lines consisting of three floating point numbers, corresponding to the x y z coordinates of successive points.
Scoring
The score of your program is the total of scores awarded for individual test cases.
For each test case you will receive n*d points, where d denotes the minimum distance between the closest pair of points in the solution output by your program. If you place some of the points further than 10
-5
from the surface of the sphere, your solution will be regarded as incorrect.
Example
For the sample input:
1
2
a program outputting:
0.0 0.0 1.0
0.0 1.0 0.0
will receive 2.828 points. | 34,618 |
Pawns Gone Wild (PAWNS)
Imagine a game played on an
n x n
chessboard by two players sitting at opposite ends, one having n white pawns, the other - n black pawns. Pawns are arranged in the row closest to the player. Moves are made in turn by both players and resemble those in chess: in a single move, a player can move exactly one pawn, either a square forward (if the square it is moving onto is free), or on the bias, one square forward and one square to the left or right (if the square it is moving onto is occupied by an enemy's pawn, which is considered beaten and removed from the game).
Pawns may never be moved backwards or off the board, and if a pawn reaches the final line it just has to stay there. The game ends if a player can't make a move. The winner is then the player who... oh, it doesn't matter really (possibly the players have a fight with beer bottles, and the one who isn't knocked out, wins). Your task is different - seeing snapshots of a game at two moments of time, try to reenact a sequence of moves that may have led from the first situation to the second.
Input
The first line of input contains a single positive integer t<=25, the number of test cases. t test cases (of successively increasing size) follow.
Each test case begins with an integer n (2<=n<=26) denoting the size of the board. Then, the snapshot of the earlier situation is given, followed by a snapshot of the later situation. Each snapshot is a sequence of n lines of n characters, corresponding to the squares of a chessboard oriented as in the figure above. Character '.' - denotes an empty square, 'W' - a square with a white pawn, 'B' - a square with a black pawn. Assume that it is black's turn to move after the earlier position (though black needn't have necessarily started the game as such).
Output
For each test case, output the number k of moves which could have led from the first to the second position (output 0 if you don't know a solution, even though such a solution exists for certain). In the next k lines, print the determined sequence of moves. Each move should be given in a seperate line, using the format:
old_column old_row new_column
to describe the change of coordinates of a pawn (assume board orientation as in the exemplary figures).
Scoring
The score of your program is the total of scores awarded for individual test cases.
For each test case for which you find a solution in k moves you will receive k points.
Example
For the sample input:
1
6
....W.
.WWW.W
B.B...
......
......
B..BBB
......
.BWW..
.....W
......
.....B
B..BB.
a program outputting:
5
A 3 B
F 2 F
C 3 D
E 1 D
F 6 F
will receive 5 points. | 34,619 |
The Burning City (BURNCITY)
Terrorists from the BBFO have raised fires in the capital of Byteland! As is it is a hot summer day, most of the fire brigade have quite naturally taken a day off, and so the noble task of extinguishing all the fires falls to the only officer on duty. By now you will probably not be surprised to learn that he is in fact... Johnny. This enterprising youth remains undaunted by the challenge facing him, and, taking advantage of the absence of his superiors, he decides to use his favourite fire fighting technique. So, he loads the fire station's helicopter with as many dynamite charges as it can carry, and takes off on his errand of mercy.
From up there in the sky Johnny can see the city as a square, sliced into smaller, identical squares by a regular grid of streets. Every square contains one of three kinds of terrain - buildings, grassland or water (perhaps most firemen would go into further detail when analysing terrain, but you really can't expect that from a firefighter whose preferred method of extinguishing fires is dynamite, can you?).
Johnny starts out in the centre of the square corresponding to the fire station. In the time from the start of a minute to the end of that minute he can move to the center of one of the four adjacent squares (but he is not allowed to leave the city). While over the center of a square he can choose to drop a single dynamite charge on it. He starts preparing the charge at the beginning of a minute, and it is dropped from the helicopter at the end of the same minute. Everything on the square on which the bomb was dropped is blown apart, and in its place a crater is formed and instantly flooded by subterranean waters.
The fire spreads in a most predictable way: if a square starts burning at the beginning of minute m, then all four adjacent squares will catch fire at the start of minute (
m
+2). The only exception is a square filled with water (either naturally, or by Johnny's bombs) which never catches fire. If a square starts burning, all property on it is instantly destroyed. Once a square starts burning it will only stop burning if Johnny blows it up, or when the monsoon rain comes and floods the city, at the end of the
h
-th minute of firefighting.
Johnny's main objective is to save as many squares with buildings as possible (from fire and dynamite).
An example of the fire fighting process is presented below.
Input
The first line of input contains a single integer
t
<=500, the number of test cases.
The first line of every test case contains five integers
n c h s
x
s
y
, respectively denoting:
n
- the length of one side of the city (measured in squares),
c
- the number of dynamite charges Johnny can use,
h
- the number of minutes after which the rain falls,
s
x
,
s
y
- the
x
and
y
coordinates of the square containing the fire-station from which Johnny starts, measured relative to the North-West corner of the city (1<=
s
x
,
s
y
<=
n
<=50, 0<=
c
<=
h
<=5*
n
; there are about 10 test cases for all possible values of
n
). Finally, the map of the city is given in the form of
n
lines of
n
characters each, each corresponding to the state of a square at the start of the fire fighting ('b' - building, 'g' - grassland, 'w' - water, 'f' - fire).
Output
For the
i
-th test case output a line containing the text 'city
i
Y' if you want to solve the test case or 'city
i
N' if you wish to leave it out.
If you chose to the solve the test case, in the next line output a sequence of exactly
h
characters 'N', 'S', 'W', 'E', '+' or '-', corresponding to Johnny's actions in successive minutes (moving North, South, West and East on the map, dropping dynamite, not doing anything, respectively).
Score
The total score is the total number of rescued squares with buildings taken over all test cases.
Example
Input:
5
3 2 9 1 1
bgg
bbg
bbf
4 2 8 3 1
bbbb
bgwg
fwgg
gbbb
4 3 15 2 1
bbbb
bbbb
bbbb
fbbb
4 3 15 2 1
bbbf
bbbb
bbbb
fbbb
4 3 15 2 1
bbbf
bbbb
bbbb
fbbb
Output:
city 1 Y
S+E---N+-
city 2 Y
W+SSS+--
city 3 Y
ESE+SW+S+------
city 4 Y
+EES+W+--------
city 5 Y
+ES+-E+--------
Score:
9
(The first test case is illustrated in the figure and Johnny can save one building. In testcases 2, 3, 4, 5 Johnny saves 4, 2, 2 and 0 buildings, respectively).
Bonus info
: The three digit number after the decimal point of your score denotes the number of test cases you have solved correctly, rescuing at least one building.
Warning: large Input/Output data, be careful with certain languages | 34,620 |
Nightmare in the Towers of Hanoi (HANOI)
Consider the folowing variation of the well know problem Towers of Hanoi:
We are given
n
towers and
m
disks of sizes 1,2,3,...,
m
stacked on some towers. Your objective is to transfer all the disks to the
k
-th tower in as few moves as you can manage, but taking into account the following rules:
moving only one disk at a time,
never moving a larger disk one onto a smaller one,
moving only between towers at distance at most
d
.
You can assume that all the problems can be solved in not more than 20000 moves.
Input
The first line of input contains a single positive integer
t
<= 1000, the number of test cases.
Each tests case begins with the number of towers 3 <=
n
<= 100, the number of target tower 1 <=
k
<=
n
, the number of disks
m
<= 100 and the maximum distance 1 <=
d
<=
n
- 1.
Then, the following
m
lines consists of pairs of numbers describing the initial situation, in the form: the tower and disk on it. Assume according to the rules that on every tower smaller disks are on larger disks.
Output
Process all test cases. The correct output for the
i
-th test case takes the following form:
i
[the number of the test case (in input order)]
a b
[a sequence of lines of this form, where
a
is the tower with the moved disk on top of it and
b
is the target tower].
The test case is considered solved if after performing the sequence all disks are on the
k
-th tower. At the end of the series of moves you should always write a line consisting of two zeros ('0 0').
Scoring
The score awarded to your program is the sum of scores for individual test cases. For the i-th test case you will receive
T
i
/ (
T
i
+
A
i
) points, where
T
i
<= 20000 and
A
i
is the number of moves in your solution. If you don't want to solve a test case, you may output the line '0 0' without a list of moves, for which you will not be awarded any points. Your program may not write more than 30000 kB to output (this will result in SIGXFSZ).
Example
Input
5
3 3 3 2
1 1
1 2
1 3
3 1 3 2
1 1
1 2
1 3
4 4 4 2
1 1
1 2
1 3
1 4
4 4 4 2
1 1
1 2
2 4
4 3
4 4 4 3
1 1
4 2
4 3
4 4
Output
1
1 3
1 2
3 2
1 3
2 1
2 3
1 3
0 0
2
0 0
3
0 0
4
4 3
2 4
3 4
1 2
1 3
3 4
2 4
0 0
5
1 2
0 0
Score
Assuming:
T
= {7,6,15,7,1} the output will receive
2
points.
Bonus info:
If score =
xxx
.
xxxaaa
,
aaa
means the number of test cases with non-zero score... | 34,621 |
Bytelandian Telecom (BYTELE)
King Johnny has a serious drink problem, which has recently become the focus of attention of all Bytelandian tabloids and colour magazines. In a desperate effort to divert the public's attention and ingratiate himself with his subjects, he decides to start giving out valuable gifts. This time he has chosen to harass the peaceful life of the CEO of Bytelandian Telecom, and requested him to create a Metropolitan Area Network for the citizens of the capital of Byteland, as part of an "our King is a good man" campaign.
The CEO has no choice but to obey the orders he receives. This rational and business-minded man would obviously like to perform the installation at the smallest possible cost, and he asks you for your help.
The King has stated the topology of the network plainly enough in the form of a graph (not necessarily connected), with vertices corresponding to nodes (computers), and edges to the cable connections between them. It is now your task to select the points of the city to place the nodes of the network at. The city is a regular mesh of streets (depicted as vertical and horizontal segments on a map), with crossroads located at points with integer coordinates. Nodes may only be located at crossroads of streets (no two nodes at the same crossroad). Cables may only run along streets and must connect nodes by the shortest possible route under this constraint. Moreover, a cable of precisely such length must be currently in stock (you are provided with a list of possible cable lengths).
Try to layout the network in such a way as to minimise the total length of cable used.
Input
The input starts with a line containing integer
t
<= 1000, the number of test cases.
t
test cases follow.
The first line of a test cases begins with integer
k
, denoting the number of different available cable lengths, followed by
k
space separated integers
p
j
corresponding to the allowed lengths of cables (1 <=
k
<= 100, 1 <=
p
j
<= 100). The next line contains two integers
n m
, denoting the required number of nodes and cables in the network, respectively (1 <=
n
<= 100, 1 <=
m
<= 1000). The next m lines contain a pair of integers
a
j
b
j
each, signifying that nodes
a
j
and
b
j
should be connected by a cable (1 <=
a
j
,b
j
<= n
).
Output
A valid solution to the
i
-th test case consists of a line with the text '
city
i
Y
', followed by
n
i
lines each containing two integers, the x- and y-coordinates of successive nodes in the solution (0 <=
x
,
y
<= 100).
It is guaranteed that for every test case there exists at least one possible solution. You can however leave out a test case by outputting the line '
city
i
N
' instead of a valid solution.
Score
For each correctly solved test case you are awarded (
m
/
sum
) * ((
p
1
+p
2
+...+p
k
)/
k
) points, where
sum
is the total length of all cables used.
The score awarded to your program is the sum of scores for individual test cases.
Example
Input:
4
2 1 2
4 5
1 2
2 3
3 4
1 4
2 4
1 2
4 5
1 2
2 3
3 4
1 4
2 4
2 1 2
5 8
1 2
1 3
1 4
1 5
2 4
2 5
3 4
3 5
1 1
2 1
1 2
Output:
city 1 Y
0 0
0 1
1 1
1 0
city 2 Y
2 0
1 1
0 2
0 0
city 3 Y
0 1
0 2
1 1
1 2
0 0
city 4 N
Score:
score = 3.340003
Bonus info:
If score =
xxx
.
xxxaaa
,
aaa
means the number of test cases with non-zero score... | 34,622 |
Santa Claus and the Presents (SANTA)
Every year Santa Claus faces a more and more difficult task. The number of children in the world is increasing rapidly, while Santa's old patched up sack can only accommodate a few presents at a time. And every child wants their own very special present... This means that, ever so often, once his sack is partially or completely empty, Santa has to fly back to his base in Lapland to replenish his supplies. So irksome has this become that Santa has decided to resort to modern operational research to aid him in his sack-packing and route planning. Please write a program which will guide Santa through his daily chores.
Input
The input starts with a line containing a single integer t<=100, the number of test cases. t test cases follow.
The first line of every test case consists of four integers n x y S, denoting the number of good children who will receive a present from Santa, the x and y coordinates of Santa's home base, and the amount of space in the sack, respectively (1<=n<=10000, -10000<=x,y<=10000, 1<=S<=100000). n lines follow, each consisting of three integers x
i
y
i
s
i
- the x and y coordinates of the i-th child's home, and the amount of space taken up by this child's present when in Santa's sack, respectively (-10000<=x
i
,y
i
<=10000, 1<=s
i
<=S).
Output
For each test case output a sequence of space separated integers, corresponding to successive actions that should be taken by Santa:
-i
(1<=i<=n) signifies that Santa should travel to his base and pack the present for the i-th child into his sack (he needs to have sufficient room in his sack to do this).
i
(1<=i<=n) signifies that Santa should travel to the i-th child's home and leave a present for him/her.
0 signifies that Santa should travel back to his base and end his Christmas activity (and that you want to proceed to the next test case).
Assume that Santa starts in his base and always travels between points by the shortest possible route (along straight lines). All distances are measured using the Euclidean metric.
Score
The score awarded to your program is the total of all scores obtained for its individual test cases. The score for a test case is calculated as I/P, where P stands for the distance covered by Santa in your solution, while I is a test case specific constant (I= n*d+D*(s
1
+...+s
n
)/S; d is the mean distance between two homes, while D is the mean distance between Santa's base and a child's home for the given test case).
No points are awarded for incompletely solved test cases (when not all the children receive presents). Any other violation of transport rules results in Wrong Answer.
Example
Input:
1
3 0 0 3
1 0 1
1 0 2
1 0 3
Output:
-1 -2 1 2 -3 3 0
Score:
2/(1+1+1+1)= 0.5 | 34,623 |
Plant a Christmas Tree (CTQUINE)
Evergreen trees are really wonderful. They were treasured by all civilisations of the Western world, from ancient Egiptian priests to Celtic druids in the British Isles. In the late Middle Ages a tradition of placing an evergreen tree at home for Christmas developed in Germany and spread throughout the Old and New World, reaching the Asia Pacific and America in the XIX-th century.
Surely, you must have noticed the sad fact that nowadays this global custom, however beautiful it may be, results in the death of millions of coniferous trees worldwide. Help us in our effort to restore the healthy balance. In the Christmas period, draw & plant your own tiny fir tree!
Since we are limited to text mode, there is little room for creative art, and solid, well built trees are definitely favoured. An
ideal tree
consists of several lines (at least 1) of the same length, consisiting of ASCII characters -- both whitespace ("spaces"), and non-whitespace ("relevant characters"). Counting from the top, the number of characters between the first and last relevant characters in a line (inclusive) is equal to 1, 1, 3, 1, 3, 5, 1, 3, 5, 7, 1, 3,... for consecutive lines. The line for which this distance is the largest begins and ends with relevant characters. All other lines contain exactly the same number of spaces to the left of the leftmost relevant character and to the right of the rightmost relevant character (this gives the ideal tree a nice, vertical trunk).
Please write a program which outputs a tree as close to an ideal tree as you can get, and keeps it as small as possible (such a tree has the largest chance of sprouting roots when planted).
And it can hardly come as a surprise to you to learn that the source code of the program you submit has to be identical to the text it writes to output (character by character, there are no exceptions)!
Score
Your program will be judged as follows: if the program is not a quine (i.e. if it contains no relevant characters or outputs text different than its own source code) it will be judged as a Wrong Answer. Any other program will receive some number of penalty points depending on its size and quality as a tree (the fewer points, the better). One penalty point is given for every line of code used. 10 penalty points are given for a line without any relevant characters (how can you expect a broken tree to grow?). For non-empty lines, the position of the leftmost and rightmost relevant characters in the analyzed tree are compared with respect to corresponding positions in an ideal tree with the same number of lines. The squared differences in position between these two pairs of characters are added to the penalty score.
Technical note: a single newline character (ASCII 10) should be used to terminate all lines. ASCII characters 32 (space) and 9 (tab) are treated as single spaces, all other characters are considered relevant. Notice that the problem description doesn't penalise for left out or excessive spaces after the last relevant character of a line (but doesn't allow any difference between the source code and output text in this respect).
Example
C source code:
;
;
;;;
;
main(
) {;
;
; ;
/* */
;return
0
;;}
This code would be judged as Wrong Answer, since it isn't a valid quine. Were it a quine, it would receive 16 penalty points (12 for 12 lines, 4=2
2
additional penalty points for a misplaced rightmost relevant character in line 5).
Solutions to this problem may only be submitted in the following languages: C, C++, Pascal, Java, C#, Python, Haskell, OCaml, Brainf**k, Intercal. | 34,624 |
Digits of Pi (PIVAL)
In this problem you have to find as many digits of PI as possible.
Output
Output must contain as many digits of PI as possible (not more than 1000000).
Score
The score awarded to your program will be the first position of the digit where the first difference occured.
Example
Output:
3.1415926535897932384626433832795
will be awarded with 33 points. | 34,625 |
Herdkeeper (MFENCE)
After the tragic end of the watermelon plantation, Johnny has switched to farming. More precisely, he is now a Certified Livestock Supervisor (i.e. shepherd) tending herds of antelope. It is his task to divide the animals into herds, and to build a fence around each herd, trying to keep the total length of all fences as small as possible. Each herd must consist of at least 2 antelope, and the antelope may stand arbitrarily close to the fence itself.
Input
t
[the number of test cases <= 1000]
n
[2 <= the number of antelope <= 100]
x
1
y
1
[coordinates of the antelope, between -1000 and 1000]
x
2
y
2
.....
x
n
y
n
[next test cases]
Output
case
i
Y [N - if you want to skip the testcase]
c
[the number of herds]
a s
1
s
2
... s
a
[2 <=
a
- the number of antelope in the first herd, and the numbers of the antelope in this herd in the order from the input sequence]
[next test cases]
Scoring
The score awarded to your program is the sum of scores for individual test cases. For the i-th test case you will receive 1 / ( 1 +
sum
/
conv
) points, where
sum
is the sum of circumferences of all convex hulls of herds in your solution, and the
conv
is the circumference of the convex hull of the set of all antelope. If you don't want to solve the
i
-th test case, you may output the line 'case
i
N' and nothing else.
Example
Input:
6
2
0 0
5 0
3
4 0
-4 -5
2 3
5
20 10
10 10
40 50
-20 -40
-30 -20
4
2 4
2 -4
2 0
-5 -3
3
2 4
-4 -4
2 3
4
-1 -3
-1 5
3 -5
-1 5
Output:
case 1 Y
1
2 1 2
case 2 Y
1
3 1 2 3
case 3 Y
2
3 1 2 3
2 4 5
case 4 Y
2
2 1 4
2 2 3
case 5 Y
1
3 1 2 3
case 6 Y
1
4 1 2 3 4
Score:
3.079001
Bonus info:
If score =
xxx
.
xxxaaa
,
aaa
means the number of test cases with score > 0.5 | 34,626 |
Atomic Shelters (ATSHELT)
The election campaign of the mayor of Byteland continues. His advisors firmly believe that a military touch might do good to his image. On the other hand, aggressive use of arms might arouse the insane anger of the pacifist part of the electorate. So, investing in national defence seems to be the best solution. And this is why the capital of Byteland will receive its first ever atomic shelters.
The Bytelandian capital consists of exactly
n
buildings and the mayor intends to build shelters underneath exactly
k
of them. Now it is your task to layout the shelters in the city in such a way as to minimise the maximum distance a citizen of Byteland may have to cover to reach the nearest atomic shelter. After all, there is nothing more important than a mayor who guarantees your safety by putting an atomic shelter not far from your house.
Input
t
[the number of test cases <= 1000]
n k
[2 <= the number of different buildings <= 100, 1 <= the number of shelters <=
n
-1]
x
1
y
1
[-1000 <= coordinates <= 1000]
x
2
y
2
.....
x
n
y
n
[next test cases]
Output
case
i
Y [N if you wish to skip this test case]
b
1
b
2
...
b
k
[numbers of buildings to put shelters in, in increasing input order]
[next test cases]
Scoring
The score awarded to your program is the sum of scores for individual test cases. For the i-th test case you will receive
diam
/
dist
points, where
diam
is the distance between the furthest two buildings of the city, while
dist
is the longest distance from a building to the nearest shelter in your solution. If you don't want to solve the
i
-th test case, you may output the line 'case
i
N' and nothing else.
Example
Input:
5
5 2
-3 -4
-4 3
2 -3
-2 -3
-5 5
5 4
2 0
-5 -4
1 -1
-1 0
5 -5
5 2
-3 0
5 -2
-1 -5
2 4
4 5
5 3
5 0
-1 -5
3 2
-5 1
-1 3
5 4
-1 2
1 1
5 4
0 5
-2 2
Output:
case 1 Y
3 4
case 2 Y
1 3 4 5
case 3 Y
4 5
case 4 Y
1 2 3
case 5 N
Score:
5.592004
Bonus info:
If score =
xxx
.
xxxaaa
,
aaa
means the number of test cases with Y answer. | 34,627 |
The Turing Music Box (TMBOX)
If you've ever dealt with the theory of information, you are no doubt familiar with the theoretical notion of a
Turing Machine
. But have you ever wondered what you could do if you got a
real
Turing Machine -- one of those big metal things with all the cranks and levers and rolls of infinite tape that looks suspiciously like toilet paper?...
The sad answer is: there are few interesting things that can be done with such a machine. Even problems that have a little charm in the theoretical model (like the intractable Halting Problem) can be solved very efficiently with practical brute-force algorithms (see e.g. the figure at the end of the problem description). But there is one thing that you can do with a practical Turing Machine, and can't do with a theoretical one, and it is: to use it as a music box.
Our Turing Machine has exactly one state variable (an integer in the range 0 to 999) and is equipped with an infinite tape, consisting of cells with symbols from a given alphabet encoded on them. A movable read/write head is positioned over some cell of the tape, and is operated according to the list of rules encoded in the machine. The rules are of the form
S1 C1 S2 C2 M
, which means: if the machine is in state S1 and C1 is written in the current cell, change state to S2, write C2 in the current cell, and move the head as described by move M (one cell left, one cell right, or not at all). If no matching rule is found for the given state the machine should halt.
Now, here is the good bit. The head makes a creaking sound when performing each rule. It goes
da
when moved right,
di
when moved left, and
um
when left in place. Suppose that each cell of the tape can contain one of 16 possible symbols, formed as the concatenation of exactly two of the words:
da
,
di
,
um
and
sh
for silence. Initially, nearly all the cells of the tape are filled with the symbol
shsh
. Only a few (not more than 500) consecutive cells form a piece of music, each cell encoding a pair of sounds (one of 9 combinations of
da
,
di
or
um
, without any silences). The head of the machine is initially positioned over the leftmost of the cells containing sounds.
Now it is your task to use the Turing machine to play the piece of music written on its tape (as read from left to right, starting from the initial position of the head, as far as the first silence) as accurately as possible, using the head itself to produce the sounds required.
Output
The output of your program must contain a set of rules describing the behaviour of the Turing Machine designed for playing music. Each rule must be of the form
S1 C1 S2 C2 M
, where S1 and S2 are integers from the range 0..999, C1 and C2 belong to the 16 symbols of the alphabet, while M describes the move direction of the head by the sound it makes (
da
,
di
or
um
).
Score
Your program will be tested multiple times for different pieces of music written on the tape. The score of your program is equal to the total of non-negative scores, taken over all test cases.
For a test case with n notes (n/2 non-silent cells) your program will receive n-d points, where d denotes the edit distance between the music played and the music required (i.e. the minimum total number of notes that have to be inserted into or changed in both the pieces to obtain the same piece of music).
Example
Consider the following set of rules output by a program:
000 dada 000 dada da
000 umda 000 dada da
000 shsh 000 shsh da
000 didi 001 didi di
001 dada 002 didi di
Then the results of exemplary testing could be as follows:
Music:
da da|da da|da da|di di|um um
Plays:
da da da di di
Score:
5
Music:
um da|um da|um da|da um|di di
Plays:
da da da
Score:
3
Total:
5 + 3 = 8 points
Bonus info:
There are no more than 100 tests. The score format is
s.xxyy
, where
xx
denotes the number of tests for which your machine played the music perfectly,
yy
- the number of tests for which it received a positive score. | 34,628 |
Johnny and the Optimisation of Homework (HWORK)
One day when Johnny was still a schoolboy he got caught red-handed by his teacher while doing a Very Mischievous Thing (of the sort that you would expect of Johnny). As a punishment he was told off and assigned additional homework. The teacher underlined quite a few words in a dictionary and asked Johnny to rewrite all of them to his notebook.
Johnny wasn't at all pleased about this, since writing by hand is always a painful burden. Fortunately, Johnny's dad took pity on the crying boy and offered to help. He presented his son with a few sheets of carbon paper, thanks to which any text Johnny wrote was at once ready in exactly
k
copies. Some of the characters of particular copies could then be erased using a white correction pen, so as to obtain only the words required by the teacher. All the characters forming a single word have to be directly adjacent, but words can be written in any order on the sheets and different words can be separated by an arbitrary (possibly 0) amount of space.
Johnny has cheered up considerably by now, since the bit with the carbon paper and correction pen sounds rather fun. All that remains to be done is to write down an appropriate text, obviously keeping it as short as possible. Please advise Johnny what to write.
Input
Input begins with a single integer t (t=1000). t test cases follow.
Each test case starts with a line containing two integers n k, respectively denoting the number of words the teacher has asked Johnny to write and the total number of carbon copies that Johnny creates, including the original (1<=k<=n<=512). Each of the next n lines contains a word assigned by the teacher - a string of between 4 and 12 characters 'a', 'b', 'c' or 'd'. All words given at input are Bytelandian nouns in common use.
Output
For the i-th test case output a line with the text
case i Y
or
case i N
, specifying whether you wish to solve the given case. Then in the former case
print a single line containing the text that should be written by Johnny. Exactly n lines with a single integer on each should follow, the i-th representing the position of the first letter of the i-th word (on the page on which this word eventually appears, before applying the correction pen).
Scoring
The score awarded to your program is the sum of scores taken over all test cases you chose to solve.
For each test case, the score is the difference between the total number of characters of the words provided by the teacher and the number of characters of the text eventually handwritten by Johnny. Programs which receive a negative score for some test case will be considered incorrect.
Example
Input:
1
4 2
aaaa
aaaa
aaaa
bbaaa
Output:
case 1 Y
aaaabbaaaa
1
1
7
5
Score:
17 - 10 = 7
When given in to the teacher, the 2 pages of homework may look as follows:
aaaa__aaaa
aaaabbaaa_ | 34,629 |
Bytelandian Origami (BRIGAMI)
Many of Johnny's school friends have perfected the art of folding a square sheet of paper into beautiful shapes (known as
origami
). Johnny attempted to follow suit, but to his dismay he found that his fingers were a little to clumsy for the task in hand. After spending yet another day creating something especially disastrous (later named "From the series:
Crumpled Pieces of Paper Seen with an Artist's Eye
, No. 27"), Johnny decided he'd had enough. Therefore he proudly proclaimed to all his friends that origami was not fit for serious people, and that he intended to become the master of
kirigami
, the art of cutting paper. But after experimenting with kirigami for a few weeks, he sold the rather miserable results of his labour to the local confetti store, and announced that true beauty lay in convex polygons, and that they were the only shapes a true artist should ever cut. Still, if a person is as lazy and inapt as Johnny, even such a seemingly simple task may turn out a real challenge.
The method Johnny uses to create works of art consists of several steps. First, he takes a sheet of paper in the shape of a convex polygon and uses a ruler and pencil to draw a convex polygon (lying entirely within the sheet). Then, he proceeds to cut it out using a ruler and a razor-edged paper cutter. Every cut is thus a segment of a line, reaching from one edge of the sheet of paper to another, and adjacent to one side of the drawn polygon. Johnny then discards the cut off corner of the sheet and continues cutting until the shape outlined in pencil is completely cut out. Since he is extremely disinclined to perform hard work, please write a program to help him minimise the total length of the lines along which the paper is cut.
Input
Input begins with a single integer t (t=200). t test cases follow.
Each test case starts with a line containing two integers m n, denoting the number of vertices of the sheet of paper and the shape drawn on it, respectively (3<=m,n<=600). The next m lines contain two integers
a
i
b
i
each (-20000<=
a
i
,
b
i
<=20000), corresponding to the x and y coordinates of vertices of the sheet of paper (given in clockwise order). The description of the shape drawn on the sheet follows, given in the next n lines in a similar form.
Output
For the i-th test case output a line with the text
case i Y
or
case i N
, specifying whether you wish to solve the given case. In the former case, in the next line output a permutation of the numbers 1...n denoting the order in which Johnny is supposed to cut out the respective sides of the shape drawn on the sheet (vertices are numbered from 1 to n in the input order, and side
s
connects vertices
s
and 1 +
s
mod n).
Score
The score awarded to your program is the sum of scores taken over all test cases you chose to solve.
For each test case, the score awarded to your program is equal to the ratio of the perimeter of the sheet of paper and the total length of the lines along which the paper is cut.
Example
Input:
3
4 4
0 0
0 2
2 2
2 0
0 1
1 2
2 1
1 0
4 3
0 0
0 3
3 3
3 0
1 1
1 2
2 2
4 3
0 0
0 3
3 3
3 0
1 1
1 2
2 2
Output:
case 1 Y
1 2 3 4
case 2 Y
1 2 3
case 3 Y
3 2 1
Score:
4.94 | 34,630 |
Closing down Railway Lines (DERAIL)
Many cities in Byteland look back on the days when Johnny the First was king, and when nobody bothered about public spending. One of things that the citizens liked most about Johnny was that whenever he had a hangover, he would sign any public petition brought forth to him, just for the sake of peace and quiet. Rail travel was extremely popular, and lots of cities and villages requested railway lines connecting them directly, to which King Johnny always graciously agreed (even if he wasn't quite sure what he was agreeing to). Seeing that money was no object, the railway tracks were built in such a way as to connect pairs of cities directly, along straight lines. If two railroads intersected, a complex intersection involving bridges and tunnels was built and everyone seemed perfectly happy.
And then after Johnny's abdication, democracy returned, and the happy days of Byteland ended. One of the first things that had to be done was closing down most of the railway lines. The new government intends to disassemble a large part of the direct railway connections, preserving barely enough to make travel possible between any two cities (perhaps via other cities on the way). The total cost of maintenance of the lines which remain open, equal to
k
Bytelandian Dollars per kilometer of track open and
l
Bytelandian Dollars per intersection of 2 used tracks, is to be as low as possible. Please help the government decide which railroads should remain open.
Input
Input starts with a single integer t, the number of test cases (t<=100). t test cases follow.
Each test case begins with a line containing two integers n m k l, denoting the number of cities, the number of direct connections between cities, the cost of upkeep of a kilometer of track, and the cost of upkeep of a single railway line intersection, respectively (3<=n<=m<=10000, 0<=k,l<=100000). Each of the next n lines contains two integers x
i
y
i
, corresponding to the X and Y coordinates of the i-th city, measured in kilometers, respectively (-40000<=x
i
,y
i
<=40000). Then exactly m lines follow, containing a pair of integers a
i
b
i
each, which denote that cities a
i
and b
i
, numbered in input order, are connected by a direct railway track (1<=a
i
, b
i
<=n). No three cities are collinear and no three tracks intersect at one point. All tracks are bidirectional.
Output
For the i-th test case output a line containing the text
case
i
Y
or
case
i
N
, specifying whether you wish to solve the given case. Then in the former case, write exactly n-1 lines containing one integer each -- the numbers of the railway connections that ought to be left open (numbered in input order). It is guaranteed that for the input data some solution always exists.
Score
The score awarded to your program is the sum of scores received for the test cases you chose to solve. For each such test case you will receive (s/c)-1 points, where s is the cost of maintenance of the original configuration, while c is the cost of maintenance of only those railway lines which you've selected.
Example
Input:
1
4 5 1 100
0 0
0 1
1 1
1 0
1 2
2 3
1 3
3 4
4 2
Output:
case 1 Y
3
2
5
Score:
(100+1+1+1+1.414+1.414) / (100+1+1.414+1.414) - 1 = 0.019 | 34,631 |
The Game of Crosses & Crosses (CROSSES)
The game of gomoku (otherwise known as naughts & crosses), played on an
n x n
board has many interesting variations. One of them is the Game of Crosses & Crosses, with the following set of rules:
Two players - red and black - take it in turns to place one cross of their respective color on an unoccupied square of the
n x n
gaming board. Red starts the game.
After each player's move any rectangles with sides equal to at least 2, lying entirely within the gaming board and covered completely by crosses, are simultaneously removed (cut off) from the gaming board and the game continues.
When all the squares remaining in the gaming board are covered by crosses, the game comes to an end. The score of each player is equal to the number of crosses of his color left standing on the gaming board, and the player with the higher score is considered the winner.
The game of crosses & crosses feels rather like playing a degenerated game of Go with an army of suicide bombers. For many years now it has been the favourite passtime of Bytelandian schoolchildren during their lessons. Little Johnny was no different, and among his friends he actually became a notable crossing champion.
But not many people knew about Johnny's crossing talent, and Johnny often used this to his advantage. So when a few years after Johnny's abdication from the throne of Byteland an unsuspecting publisher signed a million dolar contract with the ex-king for a series of memoirs entitled
The famous victories of Johnny the Great
, he was certainly not prepared for what he received -- a detailed account of Johnny's childhood games of crosses & crosses. To make matters worse, all accounts are written by Johnny in exciting prose, rich in action, e.g.: "
Then I played yet another game on a 3x3 board. I placed my first cross at (1,1). Then I placed a cross at (2,3). The next cross I placed at (2,2). The cross after that I placed at (3,3). Finally, I placed a cross at (1,2) and I won the game 2:1.
".
In a desperate effort to save the day, the publisher employed you to create illustrations for the book. You are given a free hand in reinacting the games (and in particular the oponent's moves, which Johnny has modestly left out), provided your version of events is not an evident contradiction of Johnny's text.
Input
Input begins with a line containing a single integer t (t=100). t test cases follow.
Each test case starts with a line with three integers describing a single game: n sr sb, denoting the length of the side of the playing board, the number of points scored by the red player (Johnny) and the number of points scored by the black player (Johnny's oponent), respectively (3<=n<=250, 0<=sb< sr). The next ceil(n
2
/2) lines contain 2 integers x
i
y
i
each - the coordinates of the squares where Johnny placed his crosses in successive moves (1<= x
i
, y
i
<= n).
Output
For the i-th test case output a line with the text
case i Y
or
case i N
, specifying whether you wish to solve the given case. Then in the former case print exactly floor(n
2
/2) lines containining 2 integers each - the coordinates of the squares where Johnny's anonymous oponent placed his crosses in successive moves.
Scoring
The score awarded to your program is equal to the number of correctly solved test cases. For each case, the game defined by yours and Johnny's description must have the outcome (final score) defined at input.
Example
Input:
1
3 2 1
1 1
2 3
2 2
3 3
1 2
Output:
case 1 Y
3 1
1 3
2 1
3 2
Score:
1
Warning: large Input/Output data, be careful with certain languages | 34,632 |
Digits of e (EVAL)
In this problem you have to find as many digits of E as possible.
Input
There is no input for this problem
Output
Output must contain as many digits of E as possible (max = 1000000)
Score
The score awarded to your program will be the first position of digit where first difference occured.
Example
Output:
2.7182
will be awarded with 6 points. | 34,633 |
The Secret Fellowship of Byteland (BFORG)
The relationship between The University of Byteland and King Johnny was never a friendly one. The king was the easy-going, open-minded sort of person who is prepared to turn a blind eye to the embezzlement of public funds, but inwardly revolts at the thought of money going to waste, and supporting a university was to the king a perfect example of a waste of money. On the other hand, the chancellor of the university showed no tolerance whatsoever, and frequently stated in public that Byteland was being governed by a monarch who took terrible decisions when he was drunk and even worse ones when he was sober. After some time of bad-tempered coexistence, the king had had enough and decided to close down the university. However, the king's councillors advised against this move, suggesting it might cause social unrest. The king yielded to their advice, and instead established a law which banned all organisations, clubs and associations active at the university.
This action had a rather curious effect on the usually lazy students of the university. They had never before even thought of organising any sort of fellowship, but now they immediately decided they needed to set one up. And this is how the
Secret Fellowship
came to life.
The main problem faced by the management of the Fellowship was how to organise members' meetings in such a way as to minimise the risk to the participants. It was decided that the
n
members of the fellowship should be split into
k
secret divisions, each consisting of at least 2 members. All members belonging to the same division would then meet regularly, and they would take it in turns to host the meetings of the division in their houses.
But one more important factor has to be taken into account -- the laziness of students. It is therefore your task to form the divisions in such a way that the furthest distance a student may ever be asked to walk is as short as possible.
Input
The first line of input contains a single integer t, the number of test cases (t=1000). t test cases follow.
Each test cases starts with a line containing two integers
n k
, denoting the number of students and the number of divisions to be formed, respectively (2<=2
k
<=
n
<=200). Each of the next
n
lines contains two integers
x
i
y
i
each (-1000 <=
x
i
,y
i
<= 1000), denoting the coordinates of the houses of successive students.
Output
For the
i
-th test case output a line with the text
case
i
Y
or
case
i
N
, specifying whether you wish to solve the given case. Then in the former case print exactly
k
lines. Each line should start with integer
n
j
(
n
j
>=2) and be followed by a space separated list of exactly
n
j
increasing integers
s
jl
, denoting the students belonging to the
j
-th division, numbered in input order (1<=
s
jl
<=n). All divisions must be disjoint and the sum of all numbers
n
j
must equal
n
.
Score
The score awarded to your program is the total of scores for the test cases you chose to solve.
For each solved test case you will receive
diam
/ (
d
*
k
) points, where
diam
denotes the distance between the two furthest houses of members of the fellowship, and
d
is the distance between the two furthest houses of members belonging to the same division.
Example
Input:
3
6 2
0 0
1 0
0 1
1 1
2 0
2 1
6 2
0 0
1 0
0 1
1 1
2 0
2 1
6 2
0 0
1 0
0 1
1 1
2 0
2 1
Output:
case 1 Y
3 1 2 4
3 3 5 6
case 2 Y
3 1 2 5
3 3 4 6
case 3 Y
2 1 3
4 2 4 5 6
Score:
1.849003
Bonus info:
If score =
xxx
.
xxxaaa
,
aaa
means the number of test cases with Y answer. | 34,634 |
Japan Crossword (JCROSS)
Japan crossword is a very popular game. It represents encoded picture which consists of filled block of cells.
At the start of game you see empty grid. Each row (column) has some numbers in beginning of the row (column).
Each number means how many continious cells are filled in a hidden picture (length of the filled blocks).
Filled blocks of cells are arranged from left to right and from top to bottom.
Between filled blocks must be at least one empty cell. For example, numbers are 4, 2, 7 mean that there are three groups
with 4, 2, and 7 filled cells in it.
Your task is decode hidden picture using hints.
Input
The first line of input contains a single positive integer t<=300 - the number of test cases.
Then for every test case first line specifies integer numbers R and C (number of rows and columns) of the picture (1<=R<=50, 1<=C<=100).
Below R lines are follow. Each line consists of any integers for horizontal hints. The very last number for every line is 0. Then C lines are follow. Each line consists of any integers for vertical hints. And again every line ends with 0.
Output
For every test case you should write decoded picture in the form of rectangle with R rows and C characters in each line.
Symbol '#'(sharp) means filled block and symbol '.'(point) means empty cell.
Score
The score awarded to your program is the total of all scores obtained for its individual test cases.
The score for a test case is calculated so that for each 'right' row or column you get 1 points. The row(column) is counted as a 'right' if there is a group of filled cells for every number in beginning of the row(or column) and lenght of every cell
is equal corresponded number. If All rows and columns are 'right' your score multiply by 1.5 for this test case.
Example
Input:
1
10 5
3 0
2 2 0
5 0
5 0
3 0
1 0
1 0
3 0
2 0
3 0
3 0
5 0
1 8 0
5 3 0
3 1 1 0
Output:
.###.
##.##
#####
#####
.###.
..#..
..#..
..###
..##.
..###
Score:
(10+5)*1.5 = 22.500
Bonus info:
If score =
xxx
.
xxxaaa
,
aaa
means the number of entirely correct test cases | 34,635 |
Simple Image Recognition (IMGREC1)
One of the hard problems that borrows human minds and can find the practical application in creating Artifical Intelegence is problem of Image Recognition. This problem in its simplest form can be applied in many spheres of manufactures. In given problem we interest in one elementary case of Image Recognition. You have to make choise form only two possible images that are represented on a bicoloured picture. This images is "dagger" or "zero". This images can be rotated, deformed, scaled, moved, have some noise or different width of lines on the picture. But human always can correctly define that is represented on a picture.
Input
t
– number of test cases, than
t
test cases follows. [
t
<= 100]
[empty line]
Eache test case starts with integer N equals to number of pictures in this test, than N pictures follows. [4 <= N <= 10]
[empty line]
Description of each picture starts from two integers H and W - height and width of picture accordingly. [5 <= H, W <= 50]
than follows exactly H lines each consists of W chars.
Description of picture consists of two simbols only: 'x' - painted square and '.' - empty square.
You can be assured, that no other symbols are present at the description of a picture.
Output
For each test it is necessary to deduce on a separate line a string of chars with length equals to N. The string should consist of a set of two chars 'x' and '0'. Where 'x' corresponds to a dagger on a picture, and '0' corresponds to a zero.
If answer will contains other chars or length of a string won't equals to N you will receive status "Wrong Answer".
Score
The score awarded to your program is the sum of scores for individual test cases. The score for individual correctly solved test equals to N (Number of pictures in this test).
Example
Input:
1
5
5 5
x...x
.x.x.
..x..
.x.x.
x...x
5 5
xxxxx
x...x
x...x
x...x
xxxxx
6 6
..x...
..x...
xxxxxx
..x...
..x...
......
5 5
.xxx.
x...x
x...x
x...x
.xxx.
5 5
.xxx.
.x.x.
.xxx.
.....
.....
Output:
x0x00
Output:
You will recieve 5 points for this solution | 34,636 |
X-Words (XWORDS)
It is quite simple really: I'll give you a list of words and you use them to make a crossword puzzle
in a 16x32 grid. You'll be able to use the words more than once in the grid and there is a special
"flipper" square you can use as a wild card. The winner will be the program that can create the "best"
fully connected crossword in one minute. The original problem appeared here:
Programmer of the month contest (Feb. 2005)
.
The Starting Grid
- The grid will consist of 32 columns and 16 rows
The Word List
- There will be at least one word and fewer than 512 words in the wordlist
- Each word will be two letters long or more (WORDLENGTH >= 2)
- Each word will be sixteen letters long or less (WORDLENGTH <= 16)
- Words in the wordlist will contain only letters "A" through "Z" in upper case letters with no white space
- Words will appear in the wordlist with one word per line
- Words will not be repeated in the wordlist, but they may be used multiple times in your solution
- Do not assume anything (like sorting) about arrangement of the words in the list
- Do not assume anything about whether a "word" is contained in any dictionary: POTM, ABCDEFG, and XYZZY are all possible "words"
- Words in the list may be subsets of one another: SCAT, CAT, CATS and XCATS may all appear in the same wordlist ... there is no bonus for using words containing other words ... see scoring note below
- There may be words in the wordlist which are not possible to connect to any other words in the wordlist
Placement of the Words onto the Grid
- Any word from the word list may be used in your solution as many times as you wish
- You may use any subset of words in the wordlist, or all of them
- All words placed on the grid must read left-to-right or downwards
- All words placed on the grid must be connected to one another
- ONLY words on the wordlist may be used and empty squares or grid boundaries must be used immediately before and after all words
- Words may not "wrap-around" the grid boundaries in any sense
- Your solution does not need to be symmetric in any sense
- Output which is not connected, or contains words which do not appear in the wordlist, will receive a score of zero
The Flipper Square
- There is one (and only one) "flipper" square (denoted by an asterisk) permitted in your output
- You may place the flipper square within any word you place on the grid
- When used, it may represent a different letter in the horizontal and vertical words of which it is a part
- Any words formed using the "flipper" square must be part of the wordlist (if C*T is placed on the grid, then there must be a three letter word in the wordlist that begins with "C" and ends in "T")
- The "flipper" will likely be used at a word intersection, although this is not required (why would you use it elsewhere??)
Input
t
– number of test cases [
t
<= 10]
N
- number of words for given test case, then
N
lines follows
each line contain one word, in upper case. Word will contain no whitespace or characters other than [A-Z].
Output
For each testcase your output must contain exactly 16 lines with 32 characters followed by a line feed as in printf("\n") on each line. The letters in your output must be upper case [A-Z} as in the wordlist. The "Flipper" (if used) in your output should be an asterisk "*". Squares that do not contain a letter or a flipper should contain an underbar "_". There should be no white space in your output. Your output must be exactly t*528 bytes.
Score
Your "SCORE" will be the total number of letters in all the words used in your solution. If a word is contained within a longer word, only the longer word will contribute to the score ... for example, using POTM would not score for the word POT even if both are in the wordlist. The "flipper" square contributes to the word length as though it was a part of each word. The total score will be the sum of scores for individual test cases.
Example
Input:
1
28
NECESSARY
POLITICAL
CONNECTED
SEPARATE
OPINIONS
REQUIRES
SEPARATION
SELFEVIDENT
UNALIENABLE
HAPPINESS
GOVERNMENTS
INSTITUTED
DERIVING
GOVERNMENT
DESTRUCTIVE
INSTITUTE
FOUNDATION
PRINCIPLES
ORGANIZING
ESTABLISHED
TRANSIENT
ACCORDINGLY
EXPERIENCE
SUFFERABLE
THEMSELVES
ABOLISHING
ACCUSTOMED
USURPATIONS
Output:
CONNECTED__USURPATIONS_CONNECTED
O_E___R___R_U____R_P___O_E___R__
NECESSARY_E_FOUNDATION_NECESSARY
N_E___N___Q_F____N_N___N_E_U_N__
E_S_INSTITUTED_INSTITUTE_S_F_S__
C_S_N_I___I_R____I_O___C_S_F_I_E
TRANSIENT_R_A_GOVERNMENT_A_E_E_S
E_R_T_N_H_E_B____N_S_X_E_R_R_N_T
D_Y_I_THEMSELVES_T___P_D_Y_A_T_A
____T___M___E__E_____E_____B___B
HAPP*NESS______P____PRINCIPLES_L
____T___E_SEPARATION_I_____E___I
SUFFERABLE_____R_____E_________S
____D___V_SEPARATION_NECESSARY_H
________E______T_____C_________E
HAPPINESS_THEMSELVES_ESTABLISHED
Score:
341 | 34,637 |
Enjoying a Multiplayer Game (MGAME)
One of the most popular types of computer multiplayer games in existence is the simple deathmatch shooter, in which it is the player's task to eliminate all other players on the gaming board. Usually, at the start of the game the players are distributed fairly randomly over the board, and run around in order to find and shoot opponents.
But there is a fair percentage of players (especially the younger ones) who enjoy the shooting most and give up the running altogether. To achieve this, at the start of the match all players are arranged very close to each other, and everyone opens fire in the very first second of the game. The gunfire continues until everyone within sight of everyone else is dead, and then the game ends, since no one feels like moving from their selected camping point.
Parents are often helpless when their children get addicted to this sort of entertainment, and don't know how to make them stop playing without causing a major quarrel. But Johnny's dad has developed the perfect method. He always says to his son:
Sure, I'll let you play another round, but tell me please how long it'll take!
And no, the answer
only a minute or two
is just not good enough.
At the start of the game, the players are positioned on the board and each player has a list of other players he is capable of eliminating (from his location). At the start of every second, each living player fires a round towards one of the opponents on his list (provided the list is not yet empty). Players who have been hit are eliminated from the game directly after the shots were fired. The situation continues until the lists of all surviving players are empty.
We are not asking you to give an exact answer the question posed by Johnny's dad, but only for an honest estimate. Given an arrangement of players on the board, try to find scenarios of shooting leading to the longest possible and the shortest possible game.
Input
The first line of input contains a single integer
t
, the number of test cases (t=100).
t
test cases follow.
Each test case starts with a line containing integer
n
, denoting the number of players on the board (2<=
n
<=500). Each of the next
n
lines contains a list of integers: first,
d
i
the length of the i-th player's list, followed by the considered list of exactly
d
i
other players (numbered in input order from the range 1 to
n
).
Output
For the
i
-th test case output a line with the text
case
i
Y
or
case
i
N
, specifying whether you wish to solve the given case. Then in the former case print a description of the longest known game scenario, followed by a description of the shortest known game scenario. Each scenario starts with an integer
t
, the duration of the game measured in seconds (0<=
t
<=
n-1
). Each of the next
t
lines contains a list of integers, representing the identifiers of players eliminated by respective players in the given second (one integer for each player left alive and capable of hitting an enemy at the start of the second, ordered according to the input identifiers of the shooting players).
Score
The score awarded to your program is the total of scores for the test cases you chose to solve.
For each solved test case you will receive
t
max
/
t
min
-1 points, where
t
max
is the length of the first presented scenario, while
t
min
- the length of the second one.
Example
Input:
1
4
2 2 3
2 1 3
3 1 2 4
1 3
Output:
case 1 Y
2
3 3 4 3
2 1
1
2 1 4 3
Score:
2/1 - 1 = 1.00 | 34,638 |
Displace (DISPLACE)
You are given two strings S1, S2 of not more than 250 characters each. S1 does not contain characters ‘(‘ and ‘)’. You can swap two consecutive characters in S1.
Your task is to do it in as small a number of swapping operations as possible to obtain a string which contains S2 as a substring (you can assume that for the given input, this can always be done).
Input
The first line of the input file contains an integer t representing the number of test cases (t < 20). Then t test cases follow. Each test case has the following form:
The first line contains S1
The second line contains S2
Output
For each test case, output 0 iff you do not want to solve this test case. Otherwise, output a line containing the number 1 and two more lines of the following form:
The first line contains an integer k representing the number of swap operations
The second line contains k integers p1 p2,..., pk separated by single spaces, pi means that in the i-th operation, you swapped the i-th character and the (i+1)-th character in S1.
Score
Your task is to minimise your score for this problem. If you choose to solve a test case and the number of swap of operations is smaller than 5000, your score is equal to the number of operations. Otherwise, your score is 5000.
Your total score is equal to the sum of scores for individual tests.
Example
Input:
1
ABCDEFGH
FC
Output:
1
3
5 4 3
Score:
3 | 34,639 |
Tethering the Mammoths (MAMMOTH)
Whereas most parks in different parts of the world are inhabited by pleasant little creatures like birds or squirrels, the nature park in Byteland's capital has somewhat larger inhabitants -- a herd of mammoths. As you may well imagine, this does lead to peculiar problems sometimes.
On one occassion the King of Bitland came on a state visit to Byteland, and, to everybody's surprise, decided he would take a stroll in the Mammoth Park. Since mammoths tend to be a little unpredictable and know nothing of the protocol of royal visits, they had to be tied up for the time being. But tying mammoths
properly
is not as easy as it sounds.
The park consists of little clearings connected by alleys, and on every clearing there stands a mammoth. Due to the lack of sterdy trees in the park, the only things you can tie a mammoth to are other mammoths. Since tying a mammoth by too few ropes may actually be more dangerous than leaving them alone, it is required that each mammoth has to be tied to
exactly k
other mammoths (that way all animals are kept safe and none of them has a feeling of being unfairly treated). The ropes connecting two mammoths must run along the park alleys and can only be 1 or 2 alleys long (in the latter case, the rope is assumed not to touch the mammoth in between). Finally, no two ropes may run a long a single alley, since this might result in an awful tangle.
It is your task to design which mammoths to tie together, or to determine that the required tethering is impossible to attain.
Input
The first line of input contains integer t, the number of test cases (t<=100). t test cases follow.
The first line of each test case contains three integers n m k, denoting the number of clearings (each with a mammoth on it), the number of alleys in the park, and the number of mammoths to tie each mammoth to, respectively (1<=k<=n<=m<=2000).
Each of the next m lines contains a pair of integers a
i
b
i
, denoting that clearings a
i
and b
i
are connected by an alley (1<=a
i
,b
i
<=n).
Output
For the i-th test case output a line containing the text
case
i
YES
if you know a solution to the given problem and
case
i
NO
in the opposite case. In the former case, you should then output exactly (k*n)/2 lines, containing the description of a rope between two mammoths. Each such line should begin with integer l, the length of the rope measured in alleys (l=1 or l=2) and be followed by exactly l+1 integers corresponding to successive clearings on the path of the rope.
It is possible that for the given test case no answer exists; in that case the only allowed solutions is
case
i
NO
.
Your score is equal to the number of test cases for which you gave the answer
case
i
YES
.
Example
Input:
3
4 4 2
1 2
2 3
3 1
1 4
4 4 1
1 2
2 3
3 1
1 4
3 3 2
1 2
2 3
3 1
Output:
case 1 NO
case 2 YES
1 2 3
1 1 4
case 3 NO
Score:
1+0+0 = 1
For the presented example, the optimal solution would score 2 points (for test cases 2 and 3). | 34,640 |
Size Contest (SIZECON)
Given the set of integers, find the sum of all positive integers in it.
Solutions can be sent in any language supported by SPOJ except
Whitespace
.
Input
t
– number of test cases [
t
< 1000]
On each of next t lines given a integer N [-1000 <= N <= 1000]
Output
One integer equals to sum of all positive integers.
Score
Score equals to size of source code of your program except symbols with ASCII code <= 32.
Example
Input:
4
5
-5
6
-1
Output:
11 | 34,641 |
Fractions Calculator (TFRACAL2)
The input consists of exactly 1000 test cases in the following recursive format:
Input
case
i
[
i
-th test]
< list_eq >:=< eq >'\n'[< list_eq >]
< eq >:=< var >=(< onp >,< fraction >)
< onp >:=(_< var >,< onp >)(_< var >,< onp >)< op >
< var >:=(a,c,g,t)[< var >]
< op >:=(+,*,/)
< fraction >:=< number >/< number >
< number >:=(1-9)[< number >]
< id >:=
the definition of the expression
< id >
on the right side: just use the definition of the expression
(
x
,
y
)
choose exactly one from the list:
x
or
y
[
x
]
process (choose)
x
or not
The definition of every variable (on the left side) appears only once and follows its last appearance on the right side.
Output
The output should contain the list of variables in nondecreasing lexicographic order of identifiers and all values should be represented as simple fractions in lowest terms, i.e. in the form
N
/
D
, where
N
and
D
are relatively prime.
Score
The score is equal to the number of correctly solved test cases divided by 100.
Example
Input
case 1
c=_g_a/_cg_g/*
cg=_a_ct_a++
g=_a_a/_ct*
ct=_a_a*
a=2/2
case 2
t=_ct_ta*_ta*
ta=_c_a_a**
c=_ct_a+
ct=_a_a+_a_a*+
a=2/4
case 3
c=_t_cg_cg//
t=_g_g+_cg_g**
cg=_g_ct/
ct=_g_g/
g=6/71
case 4
g=_tt_tt_gt+*
t=_gt_tt*_tt/
gt=_tt_tt+_a_a*/
a=_tt_tt_tt/*
tt=2/62
case 5
c=_cc_t*
ca=_a_a/_a/
a=_cc_cc_t*+
cc=_t_t_t/*
t=76/13
Output
case 1 Y [write 'Y' and the correct answer, write 'N' if you don't wish to answer]
a 1 1
c 3 1
cg 3 1
ct 1 1
g 1 1
case 2 Y
a 1 2
c 7 4
ct 5 4
t 245 1024
ta 7 16
case 3 Y
c 432 357911
cg 6 71
ct 1 1
g 6 71
t 432 357911
case 4 Y
a 1 31
g 1923 961
gt 62 1
t 62 1
tt 1 31
case 5 Y
a 6764 169
c 5776 169
ca 169 6764
cc 76 13
t 76 13
Score
0.05 | 34,642 |
Shortest Superstring (TSSTR)
Input
Input begins with a single integer
t
(
t
= 1000). t test cases follow.
Each test case starts with a line containing integer
n
denoting the number of words (1 <=
n
<= 100). Each of the next
n
lines contains a word - a string of between 4 and 16 characters 'a', 'b', 'c' or 'd'.
Output
For the
i
-th test case output a line with the text
case
i
Y
or
case
i
N
, specifying whether you wish to solve the given case. Then in the former case
print a single line containing the shortest superstring. Exactly
n
lines with a single integer on each should follow, the
i
-th representing the position of the first letter of the
i
-th word.
Scoring
The score awarded to your program is the sum of scores taken over all test cases you chose to solve.
For each test case, the score is the fraction of the total number of characters of the words and the number of characters of the text. Programs which receive a negative score for some test case will be considered incorrect.
Example
Input:
1
4
aaaa
aaaa
aaaa
bbaaa
Output:
case 1 Y
aaaabbaaaa
1
1
7
5
Score:
17/10 = 1.7
Bonus info:
If score =
xxx
.
xxxaaa
,
aaa
means the number of test cases with Y answer. | 34,643 |
Rectangles in a Square (RIS)
In two fundamental branches of modern science -- electronics and telecommunication -- progress is so marked that it may be perceived nearly as a natural power, controlling the fate of people and companies and transforming human life. Mainframes, computers, LAN, internet, built-in systems, Wi-Fi - generation upon generation of technology has sprung up within a time interval shorter than that of human life. Progress has its own life cycle, and periods of growth of semiconductor device production are interleaved with periods of decline, approximately once every five years.
Experts believe that the main reason for such decline is the lack of new tools for Electronic Design Automation (EDAs), which can take full advantage of the latest technological achievements.
You are employed by the designers of a modern EDA and you have been asked by your boss to solve one of the stages of the design process. More specifically, you are to present a piece of software which, given a square-shaped board and a list of rectangular semiconductor devices, tries to place them on the board. No element may lie outside the board (even partially) or overlap with another element.
You are rather vague about the details of your task, and so (surprisingly) is your boss. "Just make sure the guys from Marketing can feature <<
Efficient Automated Semiconductor Placement
>> in our sales brochure" -- he says, and leaves you to it.
Eventually, you decide to pack as many of the listed chips as possible on the given board (leaving out those that simply won't fit in), and go off for the evening to the local whisky bar, wondering whether the next recession in the technological cycle won't come sooner than in 5 years' time...
Input
t
– number of test cases, then
t
tests follow. [t <= 500]
In the first line of each test there is an integer N, and in the second line an integer K. N is the length of the side of the square [2 <= N <= 1000], and K is the number of available rectangles [1 <= K <= 10000]. Then exactly K lines follow, with 3 numbers on each of them: wi, hi, li. wi - length of rectangle [wi <= N], hi - height of rectangle [hi <= N], li - number of rectangles of this type [li <= 200000]. You may rotate a rectangle by a multiple of 90 degrees.
Output
For each test case output integer R - number of used rectangles, and then exactly R lines. On each of these lines output integer coordinates of opposite corners of rectangle xi1, yi1, xi2, yi2. Solution will be accepted if all rectangles won't intersect with each other and won’t overrun the bounds of square.
Score
The score awarded to your program is the sum of scores for individual test cases. For individual test case you will receive points equals to area cover with rectangles divided by area of square. For test in which square doesn't have empty area, you will receive 4 points. If score = xxx.xxxaaa, aaa means the number of test cases with fully covered square.
Example
Input :
1
10
8
3 5 2
2 2 1
2 3 1
2 5 1
4 5 1
1 3 2
3 8 1
1 1 1
Output :
9
1 1 5 3
6 1 8 5
9 1 10 2
1 4 5 7
6 6 10 7
9 3 10 5
1 8 1 10
2 8 2 10
3 8 10 10
Example explanation :
On the figure rectangles marked with numbers in accordance with position in example output.
For this test case you will receive 4.000001 points, because square fully covered with rectangles. | 34,644 |
Literature List (LIB)
In separate lines of a file you are given the titles of publications, written in lower-case letters. With nothing at your disposal but the Brainf**k language, write a converter from this style of naming to a format in which the first letter of each word is upper-case and a title ends with a dot.
The Brainf**k language consists of eight commands, listed below. A Brainf**k program is a sequence of these commands, possibly interspersed with other characters (which are ignored). The commands are executed sequentially, except as noted below.
The Brainf**k language uses a simple machine model which (apart from the executed code) consists of an array of 32,768 int32 cells initialized to zero, a movable pointer to an array cell (initialized to point to the leftmost cell of the array), and two streams of ints for input and output (most often connected to a keyboard and a monitor respectively, and using the ASCII character encoding).
The eight language commands, each consisting of a single character, are the following :
'>' : increment the pointer (to point to the next cell to the right).
'<' : decrement the pointer (to point to the next cell to the left).
'+' : increment (increase by one) the byte at the pointer.
'-' : decrement (decrease by one) the byte at the pointer.
',' : accept one byte of input (stdin), storing its value in the byte at the pointer.
'.' : output (to stdout) the value of the byte at the pointer.
'[' : jump forward to the command after the corresponding ']' if the byte at the pointer is zero.
']' : jump back to the command after the corresponding '[' if the byte at the pointer is nonzero.
Brainf**k programs can be translated into C using the following interpreter:
http://spoj.com/bf2c.c
The program should be as small as possible of course.
Input
t
– the number of lines [10 <=
t
<= 99].
In each of the following t lines there is one publication title consisting of several words (length of a line <= 1000 symbols, length of a word <= 40). Each line ends with the ASCII symbol '\n' = 10. Publication names consist of lower-case letters: 'a'-'z' and space: ' '.
Output
Each publication title should be placed in a separate line. Each word of the publication title should begin with an upper-case letter and there should be a dot at the end of the publication title.
Score
The score of the program is inversely proportional to its source size, i.e. score = 100/(1+R), where R stands for the source code size in bytes (only Brainf**k commands are counted, all other characters are ignored).
Example
Input:
06
joint power management of memory and disk
instruction scheduling for dynamic hardware configuration
hierarchical variance analysis for analog circuits based on graph modeling
lifetime modeling of a sensor network
symmetric multiprocessing on programmable chips made easy
a time slice based scheduler model for system level design
Output:
Joint Power Management Of Memory And Disk.
Instruction Scheduling For Dynamic Hardware Configuration.
Hierarchical Variance Analysis For Analog Circuits Based On Graph Modeling.
Lifetime Modeling Of A Sensor Network.
Symmetric Multiprocessing On Programmable Chips Made Easy.
A Time Slice Based Scheduler Model For System Level Design. | 34,645 |
Tetris AI (TTR)
In the very heart of a well known producer of microelectronic products, a mobile phone with a built in game of Network Tetris is being prepared for release. The owners of such mobile phones can arrange duels when at a small distance from each other. Data transmission between players is carried out using the Bluetooth protocol.
However -- now we are coming to the point -- it sometimes happens that there may be no other similar phone nearby and the player may need to play alone. For this purpose it is necessary to write a computer player (AI) with a very hard difficulty level.
The rules of Network Tetris are pretty simple :
The game has two playing fields, each with the rules of standard Tetris: figures of 4 blocks keep falling from the top of the field, and have to placed in such a way as to form horizontal lines. Once a line is filled up, it is removed and all lines above it are appropriately shifted downwards. There is however one difference with respect to standard Tetris -- a player receives additional penalty lines as soon as his opponent clears a line. The game is over when one of players fills his own field, either on his own or with his opponent's help, to such an extent, that the next figure cannot fully enter the field.
The width of the field is 10, and the height of field is 20. There are 6 types of figures in the game:
I (1) -
L (2) -
J (3) -
Z (4) -
S (5) -
O (6) -
It is your task to write a bot which starts with an empty field and, knowing the sequence of figures dropping on its field, plays in such a way as to do as much harm as possible to the opponent.
Input
t
– number of test cases [
t
<= 150], then
t
tests follow.
Each test case starts with integer
N
equal to the number of figures which drop onto the field [10 <= N <= 50000]. Then N integers follow, numbered from 1 to 6 – denoting one of the figures, in the same position as they appear in the pictures. (Look at numbers in parenthesis).
Output
For each test you should output line
case 1 Y
if you wish to solve this test case or
case 1 N
otherwise. If you output
Y
, then exactly N lines must follow. Each of them should contain exactly two integers: A and X, where A is the clockwise angle of rotation in the given move, numbered from 0 to 3 (0 - 0 degrees, 1 - 90 degrees, 2 - 180 degrees, 3 - 270 degrees), while X is the horizontal coordinate of leftmost cube of the figure [1 <= x <= 10]. The
i
-th figure at input corresponds to the
i
-th figure at output. If the figure falls outside the field or the parameters have incorrect value, or any falling figure stops with at least one cube in a line of number larger than 20, then the solution will be judged as Wrong Answer.
Score
The score will be equal to the total number of cleared lines, taken over all test cases. For one cleared line your solution will receive 1 point, for two simultaneously cleared lines – 5 points, for three simultaneously cleared lines – 15 points, for four simultaneously cleared lines – 30 points.
Example
Input :
1
14
3
2
4
5
3
2
1
6
6
1
1
4
1
5
Output :
case 1 Y
0 1
0 8
0 1
0 8
1 7
3 3
1 5
0 7
0 9
0 1
1 6
1 6
0 1
1 4
Score :
score = 30 + 1 = 31 | 34,646 |
Hard Image Recognition (HIR)
It is a well established fact that every civilization goes through one key stage of technological development, which is best illustrated by the rapid transition from typewriters to GUI based word-processing computer software. What is more remarkable, during this transition period taste and fashion is turned upside down, and good old esthetic sensibility is replaced by the urge to show off the whole repertoire of fonts available in the typists brand new word-processor to the wide, wide world. Even if some of the fonts look like the handwriting of a 1-year-old chimpanzee.
All civilizations which have already gone through this stage of transition look back on it with a smile. All, with one notable exception -- that of Byteland. When the multiple font craze in Byteland reached its heights, it engulfed everyone (including the usually conservative passport department officials), and now everyone is paying the price. Automating the process of passport scanning is turning out a real nightmare, since all 6-digit passport numbers are written in different fonts. Not surprisingly, you've been asked to help out.
You should write a program for recognizing images of 6-digit numbers. Naturally, in some cases, the image may be blurred or deformed, but a human can always recognize the number written (possibly after overcoming the initial surprise). The picture is black & white, and consists of a white background with a black raster image on it (character “.” denotes the color white and character “X” - the color black).
Input
t
– number of test cases [
t
<= 250], then t tests follow.
Each test case starts with 2 integers,
H
and
W
, denoting height and width of picture [10 <= H, W <= 200]. Then H rows with W characters ('.' or 'X') in each follow.
Output
For each test case you should output the numerical value of the recognized 6-digit number in separate lines.
Score
The score is equal to the number of images successfully identified.
Example
Input :
2
13 40
........................................
........................................
......XX...XX...XX......X..XX...XX......
.....X..X.X..X.X..X....XX.X..X.X..X.....
.....X..X.X..X.X..X....XX.X..X.X..X.....
.....X..X.X..X.X..X...X.X.X..X.X..X.....
.....X..X.X..X.X..X...X.X..XX....X......
.....X..X.X..X.X..X..X..X.X..X...X......
.....X..X.X..X.X..X..X..X.X..X..X.......
.....X..X.X..X.X..X.X...X.X..X..X.......
.....X..X.X..X.X..X.XXXXXXX..X.X........
......XX...XX...XX......X..XX..XXXX.....
........................................
12 60
..........................................................XX
............XXXXX.....X...XXXXXX.XXXX......X...XXXX.........
XX..........X.......XX....X...X.X....X....XX..X....X........
............X......X......X...X.X....X...X.X..X....X........
............XXXX..X..........X..X....X...X.X......X.........
............X...X.X.XXX......X...XXXX...X..X....XXX.........
................X.XX...X....X....X..X...X..X.......X........
................X.X....X....X...X....X.XXXXXX......X........
................X.X....X...X....X....X.....X..X....X........
...........X...X...X..X....X....X....X.....X..X...X.........
............XXX.....XX....X......XXXX....XXXXX.XXX........XX
XX..........................................................
Output :
000482
567833
Score :
score = 1 (the first answer is correct,
the second one has one incorrect digit)
Picture examples : | 34,647 |
Minesweeper (MSWP)
The puzzle “Minesweeper” is based on the widely known game "Minesweeper", available for almost all MS Windows users, starting from version 2.0. The goal is simple -- to discover (or more precisely: uncover) the positions of all mines in rectangular grid. After a field without a mine on it is uncovered, the revealed value shows how many neighboring cells (at most 8) are occupied by mines. In the puzzle, just as in the game, you know the total number of mines on the board. But unlike in the game, you are not asked to risk your life by uncovering fields. Instead, you are given a list of uncovered fields (without mines, with numbers on them) and are requested to hazard a guess at the locations of all the mines.
Input
t
– the number of test cases, and then
t
tests follow [
t
<= 500].
Each test starts with three integers H, W, N equal to the height, width and number of mines on the grid, respectively [5 <= H, W <= 50] [1 <= N <= H*W]
Then exactly H lines follow, each of them consisting of W symbols.
The description of the grid consists of ASCII characters: '1'-'8' – the number of mines in neighbouring cells and '.' – a cell with unknown content. You can be sure that no other characters are present in the grid description.
Output
For each test you should output the text
char Y
in a separate line if you wish to solve this test, or
char N
otherwise. In the former case, you should then output a grid with the same size as that of the test, with mines placed on it in stead of some characters '.'. Mines are defined by the character 'X'. The number of mines should be equal to the number of mines N given in the test description.
Score
The score of your program is the total of scores awarded for individual test cases. The score for a test is equal to the number of cells around which mines are placed correctly (i.e. the number of mines is equal to the integer displayed in the cell). The number of cells for which mines are placed incorrectly is subtracted from this sum. Negative test case scores are treated as zero scores. If a test case is solved entirely correctly, the score is multiplied by 10.
Additional info:
The score is given as xxx.aaa, where aaa is number of tests solved entirely correctly.
Example
Input:
2
8 8 19
........
2323..2.
..23...2
.3..33..
2.321...
....1.32
.3...3..
1...2..2
6 6 6
111.1.
1.2121
112.21
..112.
122111
1..1..
Output:
Y
X.X.....
2323X.2X
.X23XX.2
X3X.33.X
2.321X.X
.XX.1.32
.3...3X.
1X.X2XX2
Y
111X1.
1X2121
112X21
..112.
122111
1.X1XX
Score:
The first test is solved entirely correctly, for which 23*10 = 230 points are awarded. The score for the second test case is equal to 10-15 = -5, treated as 0. The total score is thus 230.001. | 34,648 |
Prime checker (PRIC)
For this task you will have to check as many numbers as possible to see if they are prime. As not to make the problem I/O oriented, consider the numbers you should check in the following order: first take 1 and then construct the numbers in the sequence after the recursion: a
i
=(a
i-1
+1234567890) mod 2
31
. Be careful not to use more than 4096 bytes of code.
Output
For each number you should write to output the digit "1" if the number is prime or the digit "0" if it is not prime.
Score
The score of your program will be the index of the first number in the sequence after which you do not have a correct answer. Because of some limitation you should not write more than 33 333 333 characters to output. If you reach this limit, your score will be adjusted in accordance to your runtime.
Example
Output:
01000000000000000000000000001000010000000001100000
should receive 50 points. | 34,649 |
SuDoku Puzzle (SUD)
The name "Sudoku" is the Japanese abbreviation of a longer phrase, "suji wa dokushin ni kagiru", meaning "the digits must occur only once". Sudoku is a logic-based number placement puzzle. The objective is to fill a 9x9 grid so that each column, each row, and each of the nine 3x3 boxes contains the digits from 1 to 9. The puzzle setter provides a partially completed grid.
Unlike in magazines and newspapers, the digital representation of Sudoku a puzzle is a string of length 81, with all rows of the puzzle placed one after another. The representation uses ASCII symbols ‘1’-‘9’ for digits and ‘.’ for an empty space. For example, the puzzle from figure above can be represented as:
7..25..98..6....1....61.3..9....1.......8.4.9..75.28.1.94..3.......4923.61.....4.
In this task you are to solve such puzzles automatically. The score will depend on the number of solved puzzles and on the speed of your solution. Some of the puzzles have multiple possible solutions, so be careful. A solution is correct if it satisfies the given puzzle. You can be sure that all given Sudokus are correct.
Input
t
– the number of test cases; then
t
test cases follows. [
t
<= 500]
Each test case describes one SuDoku puzzle and consists of an 81-character-long string.
Output
For the i-th test case output a line containing
Y
if you want to solve the test case or
N
if you wish to leave it out. If you chose to solve the test case, in the next line output a sequence of exactly 81 characters corresponding to the solution for the i-th Sudoku puzzle.
Score
The score for this task calculated using the formula:
score = 200*total_solved/(200+time)
, where
total_solved
- number of correctly solved puzzles,
time
- running time of your program.
If the score has the following form:
xxx.xxxaaa
, then
aaa
- is the number of correctly solved puzzles.
Example
Input:
3
..41..3.8.1....62...82..4.....3.28.9....7....7.16.8...562..17.3.3.....4.1....5...
1.......4....1.38.27.9.4...91.7...........5..86.4.5.9..3......8..9....2.4.......7
7..25..98..6....1....61.3..9....1.......8.4.9..75.28.1.94..3.......4923.61.....4.
Output:
Y
294167358315489627678253491456312879983574216721698534562941783839726145147835962
Y
198563274654217389273984615915726843347198562862435791731642958589371426426859137
N
Score:
In this case
total_solved
= 2. If the program runs for 10 seconds,
then the score of this solution will be equal to 1.905002 | 34,650 |
Electrification (ELC)
We are trying to develop the electrical power infrastructure in the small country of Byteland. For this purpose not far from each city we have built a nuclear power plant (NPP). We have also connected the nearest house to this NPP with a cable. The goal of this project is to connect all houses of each city to the source of electricity. Each house already connected to electricity become a source of electricity. Since there is a severe shortage of electrical cable, the total length of the electricity network should be kept as small as possible. In some places we can set up transformer/splitter boxes to which we can potentially connect several cables; all their endpoints are then considered connected.
Input
t
– the number of cities; then follows the description of each of
t
cities. [
t
<= 50]
The description of each city begins with
N
- the number of houses in the city [3 <=
N
<= 3000]. Then exactly
N
lines follow, with two real numbers:
x, y
in each, representing the coordinates of a house. [0.0 <=
x, y
<= 10000.0]
Output
For each test case you must output a connected electrical net, e.g. all houses must be connected with each other, directly, through other houses or through transformers. For each test output integer
M
[0 <=
M
<=
N
] - the number of required transformers. On each of following
M
lines output the coordinates of the transformers
x, y
[0.0 <=
x, y
<= 10000.0]. Next output the number
K
which is equal to the number of required cables [
N+M-1 <= K <= (M+N)*(M+N-1)/2
]. On the following
K
lines output two integers
i, j
- indexes of houses or transformers. Indexes for houses begins with 0 and end with
N-1
, indexes for transformers begin with
N
and end with
N+M-1
.
Score
The score for the problem is given as:
total_score = (200+time)*(score_1+score_2+...score_t)/200
. In the above formula,
score_i
is equal to the length of the electrical cable used for electrification of the
i
th city, and
time
is the runtime of your solution.
Example
Input:
1
4
1.0 1.0
1.0 11.0
11.0 1.0
11.0 11.0
Output:
1
6.0 6.0
4
0 4
1 4
2 4
4 3
Score:
Suppose that the solution ran for 10 seconds. The length of the cable is
score_1
= 20*sqrt(2). In this case number of points awarded to the program will be equal to 29.698485. | 34,651 |
Digital Image Processing (DIP)
One of the most interesting problems of contemporary times is digital image processing to remove noise. A good solution to this problem is very important e.g. when developing digital cameras. In this task we are given a set of pictures, each of which is a grayscale image, transferred by some communication channel with failures. During the transfer some data was corrupted. A picture is defined as a rectangular matrix of integers from the range from 0 (black) to 255 (white). A number X at position (i, j) means that the pixel in the picture at the point with coordinates x = i and y = j has color RGB(X, X, X). The considered form of corruption generates noise in the following way: each pixel of the picture has its color replaced with probability between 2 and 20% by a random value from the range [0; 255].
Thus, you now receive a set of corrupted pictures, which were originally e.g. avatars, banners or photos. You are to restore the picture with maximum quality. The more exact a picture you obtain, the fewer penalty points you get.
Original Picture
Grayscale Picture
Noised Picture
Denoised Picture
Input
t
– the number of test cases [
t
<= 60] (total number about 250), then
t
test cases follows.
Each test case begins with three integers:
Q
,
H
and
W
, denoting the noise probability for the generator in percent, and the height and width of picture respectively [2 <=
Q
<= 20], [10 <=
H, W
<= 200]. Then
H
rows follow with
W
integers in each of them.
Output
For each test case you must output a picture after noise reduction in following format: In the first line output the two integers
H
and
W
. Then
H
rows must follow with
W
integers in each of them. Each integer is the color value of a pixel after the restoration process.
Score
The score of the program will be equal to the sum of scores for each single test case + 1. The number of points for a single test case is calculated from the formula:
score = sqrt((x[1][1]1 - x[1][1]2)^2 + (x[1][2]1 - x[1][2]2)^2 + .... + (x[H][W]1-x[H][W]2)^2),
where x[i][j]1 is the color of the pixel at position i, j in the restored picture
and x[i][j]2 is the color of the pixel at position i, j in the original picture.
Example
Input:
1
6 20 20
255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 028 255 255
255 255 200 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
255 000 255 255 096 255 079 079 079 079 255 045 255 045 255 068 043 043 043 255
255 000 255 255 096 255 079 255 255 255 255 045 129 045 255 068 255 255 043 255
255 000 255 255 096 255 079 255 255 255 255 045 255 045 255 068 255 255 189 255
255 058 058 058 096 255 079 079 079 079 255 045 255 045 255 068 255 255 068 255
255 076 255 255 096 255 079 255 255 255 255 185 255 045 255 068 255 255 068 255
255 000 255 255 096 255 079 255 242 255 255 045 255 045 255 068 255 255 068 255
255 000 255 255 096 255 079 079 079 079 255 045 255 043 255 048 048 048 048 255
255 255 255 255 255 255 255 255 058 255 255 255 198 255 255 255 255 255 255 255
036 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
255 255 100 195 002 167 002 002 002 002 002 002 002 002 002 002 255 255 255 255
255 255 255 255 002 002 002 002 002 002 002 002 002 002 002 088 255 255 255 255
255 255 255 255 002 002 002 002 002 002 046 002 002 002 002 002 255 255 143 255
255 255 255 255 002 002 002 002 002 013 002 002 002 002 002 002 255 255 255 255
255 255 177 255 255 255 255 104 255 255 255 255 255 255 255 255 012 133 255 255
022 022 022 022 066 022 022 022 022 022 022 022 022 022 022 022 022 022 022 022
255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
255 255 255 079 079 079 079 079 079 079 079 079 079 079 079 079 079 255 255 255
255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 203 255 255
Output:
20 20
253 253 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
254 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
255 000 255 255 096 255 079 079 079 079 255 045 255 045 255 068 043 043 043 255
255 000 255 255 096 255 079 255 255 255 255 045 255 045 255 068 255 255 043 255
255 000 255 255 096 255 079 255 255 255 255 045 255 045 255 068 255 255 043 255
255 058 058 058 096 255 079 079 079 079 255 045 255 045 255 068 255 255 068 255
255 000 255 255 096 255 079 255 255 255 255 045 255 045 255 068 255 255 068 255
255 000 255 255 096 255 079 255 255 255 255 045 255 045 255 068 255 255 068 255
255 000 255 255 096 255 079 079 079 079 255 045 255 043 255 048 048 048 048 255
255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
255 255 255 255 002 002 002 002 002 002 002 002 002 002 002 002 255 255 255 255
255 255 255 255 002 002 002 002 002 002 002 002 002 002 002 002 255 255 255 255
255 255 255 255 002 002 002 002 002 002 002 002 002 002 002 002 255 255 255 255
255 255 255 255 002 002 002 002 002 002 002 002 002 002 002 002 255 255 255 255
255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
022 022 022 022 022 022 022 022 022 022 022 022 022 022 022 022 022 022 022 022
255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
255 255 255 079 079 079 079 079 079 079 079 079 079 079 079 079 079 255 255 255
255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
Score:
Original picture:
20 20
255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
255 000 255 255 096 255 079 079 079 079 255 045 255 045 255 068 043 043 043 255
255 000 255 255 096 255 079 255 255 255 255 045 255 045 255 068 255 255 043 255
255 000 255 255 096 255 079 255 255 255 255 045 255 045 255 068 255 255 043 255
255 058 058 058 096 255 079 079 079 079 255 045 255 045 255 068 255 255 068 255
255 000 255 255 096 255 079 255 255 255 255 045 255 045 255 068 255 255 068 255
255 000 255 255 096 255 079 255 255 255 255 045 255 045 255 068 255 255 068 255
255 000 255 255 096 255 079 079 079 079 255 045 255 043 255 048 048 048 048 255
255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
255 255 255 255 002 002 002 002 002 002 002 002 002 002 002 002 255 255 255 255
255 255 255 255 002 002 002 002 002 002 002 002 002 002 002 002 255 255 255 255
255 255 255 255 002 002 002 002 002 002 002 002 002 002 002 002 255 255 255 255
255 255 255 255 002 002 002 002 002 002 002 002 002 002 002 002 255 255 255 255
255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
022 022 022 022 022 022 022 022 022 022 022 022 022 022 022 022 022 022 022 022
255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
255 255 255 079 079 079 079 079 079 079 079 079 079 079 079 079 079 255 255 255
255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
score = sqrt(2^2 + 2^2 + 1^2) + 1 = 1 + 3 = 4 (three pixels differ in the top-left corner)
Original picture:
Noisy picture: | 34,652 |
Digits of SQRT(2) (SQRT2)
In this task you are to find as many digits of the square root of 2 as possible. You have to make it within the limit of time and source code length.
Input
There is no input for this problem
Output
The output must contain as many digits of the square root of 2 as possible (max = 2000000)
Score
The score awarded to your program will be the first position of the digit where the first difference occurs.
Example
Output:
1.41421356237309504
will be awarded with 19 points. | 34,653 |
Yet another computer network problem (PT07E)
ACRush and Jelly are practising in the computer room for next TCO. Suddenly, they found the network is very slow.
After a few diagnoses, they realized that there are many redundant wires. So they plan to repair the network, change it to an optimal tree topology. And they can't spend too much money to purchase wires. Then.. too easy? Are you thinking about minimum spanning tree?
But the real trouble is the connectors have their own limitation. They can only allow one computer connects with at most
B
computers.
There are totally 10 cases, arranged in increasing order of the size of
N
(number of computers). Weight of case i-th is w[i] = i. We define
infinity
= 4 * 10
9
. And in a tree, let's call number of computers that computer i connects with is
degree
of computer i.
For case i-th you must show us a satisfied tree with total cost C[i] and maximum degree M[i], considering all computers of that tree.
The formula to compute score is as below:
With case i-th:
If your M[i] <= B then Score[i] = w[i] * C[i]
If your M[i] > B then Score[i] = (w[i] + 10) * C[i] * M[i]
To make the challenge more interesting, with a simple brute force program, we generated 10 upper bound degrees U[i] (1 <= i <= 10) for each of 10 cases.
For any case i-th:
If your M[i] > U[i] then Score[i] = infinity
Finally, TotalScore = (Score[1] + Score[2] + ... + Score[10]) / 10
Try to minimize the
TotalScore
.
Input
First line contains 3 integers
N, M, B
-- number of computers, number of pairs of computers can be connected and the maximum number of computers that a computer can connect with.
(1 <=
N
<= 10
4
, 1 <=
M
<= 10
5
, 1 <=
B
<= N)
Next
M
lines, line i-th contains a triple (u[i], v[i], c[i]) -- means if we want to connect computers u[i] and v[i] we should purchase a wire, cost c[i] (1 <= u[i], v[i] <= N, 1 <= c[i] <= 20000). The wires are bidirectional.
Output
The first line contains 2 numbers --- total cost of your tree and the maximum degree in all computers of that tree.
Next, print
N
-1 lines, corresponding to
N
-1 edges of the tree, each edge on one line, forms
u v
.
Example
Input:
3 3 2
1 2 1
2 3 1
1 3 5
Output:
2 2
1 2
2 3 | 34,654 |
Lexicographic sort (SLEXSORT)
Given alphabet
A
and a list of words, sort the list according to the lexicographic order induced by
A
.
Input
The first line of input contains
t
, the number of tests.
Each test begins with a line with alphabet
A
,
which consists of lowercase letters arbitrary chosen from the Latin alphabet. The next line contains an integer
n
<100 000 - the number of words. The subsequent
n
contain one word each, which is not longer than 1 000 letters.
Additionally, you can assume that the total number of letters in all words of each test does not exceed 4*10
6
.
There is an empty line after each test.
Output
For each test output the sorted list of words in successive lines.
Score
The score is equal to the length of the source code of your program.
Example
Input:
2
re
3
ere
rer
re
balujemy
5
bel
luba
lej
bal
leje
Output:
re
rer
ere
bal
bel
luba
lej
leje
Warning
: large Input/Output data, be careful with certain languages | 34,655 |
Math II (MATH2)
Background
This is a mathematical(?) problem. See problem
MATH1
and
AMATH
.
Input
The first line of the input contains a single integer c(1<=c<=2).
The second line contains 3 integer numbers separated by single spaces, D(1<=D<=1 000 000 000),n(1<=n<=700),m(1<=m<=700).
n lines follow, each contains m space-separated integer numbers.The number which is in the i-th row and j-th column is defined as a(i,j).
Output
You should output n lines, each contains m integers,which is either 0 or 1.We define the number in the i-th row and j-th column of your output b(i,j).
Score
If your answer is valid, the score of your program equals to the sum of the scores of each test case multiply 10000.
The score for each test case is calculated in the following way:
a) c=1
The score S equals to
If S>1.5, your score will be multiplied by 10000.
b) c=2
The score S equals to
If S>2, your score will be multiplied by 10000.
Example
Input #1:
1
7 3 4
1 6 4 6
7 0 3 3
2 5 1 5
Output #1:
0 1 0 1
1 0 1 0
0 1 0 1
Input #2:
2
7 3 4
1 6 4 6
7 0 3 3
2 5 1 5
Output #2:
0 1 0 1
1 0 1 0
0 1 0 1
Score:
11428.5714
Warning: large input/output data, be careful with certain languages.
Some unofficial tests were added.
The score system has been changed to avoid Wrong Answer. | 34,656 |
Intercept (INTER)
Long long ago, so long ago, no body knows how long ago,
there was a huge galactic war. There was a very powerful
general, General Ramuk, who had every possible soldier and
scientist under him. One of his scientists reports that he
had intercepted a transmission that he believes is from the
aliens. A group of experienced cryptographers believe that
in the following hypotheses:
The aliens follow use binary system for representing
numbers
Their '0' should be interpreted as '1' and vice-versa
The message is encoded as follows:
[32bits of n1][16bits of n2][n2 bits of n3]
The retransmission they expect is:
[32bits of the remainder] when
n3
is divided by
n1
.
All the numbers are written, Most significant bit first.
Remainder must be communicated in the following format:
[remainder for 1st instance]
[remainder for 2nd instance]
in their own number system, without leading '1's ('0's).
The number of instances is about
200
.
The first transmission was completed. Ramuk is eagerly
waiting for the second transmission, which must be
replied. Being such a simple problem, he asks you to write a program to do the same.
He says:
"Nee evalovu chinnadha codea ezhudhariyo avalovu parisu
onnakku kaathhirriku ",
which translates to:
"The smaller the code you write, that much reward is awaiting you...".
You want to save the world from a probable Alien Invasion,
and get as much money as possible.
Constant bit length numbers will be prefixed by '1's ('0's in their notation).
Scoring
The scoring for this problem is the
length of the source code
.
Sample Input
NOTE: The colons (:) and newlines are for clarity
11111111111111111111110001001110:1111111111101111:0011100111000100
11111111111111111111110001001011:1111111111101100:0100100001000011111
The actual input will be like:
1111111111111111111111000100111011111111111011110011100111000100
1111111111111111111111000100101111111111111011000100100001000011111
(new line is again, for clarity)
Sample Output
0101101001
0010001111
Explanation
n1=945
n2=16
n3=50747
output=662
n1=948
n2=20
n3=376288
output=880
Warning: Large Input. | 34,657 |
Greatest Common Divisor (GCD)
Consider the decimal representation of a natural number N.
Find the greatest common divisor (GCD) of all numbers that can be obtained by permuting the digits in the given number.
Leading zeroes are allowed.
Input
Every line of input contains an integer, representing the original number N(0 < N < 10^250).
Output
For every test case, print the GCD of all numbers, which can be obtained from the given one by permuting the digits.
Score
Score is the length of your source.
Example
Input:
21
3
Output:
3
3 | 34,658 |
Brainf_ck (BRAINF_K)
brainf*ck is the ungodly creation of Urban Mller, whose goal was apparently to create a Turing-complete language for which he could write the smallest compiler ever.
http://en.wikipedia.org
defines it as
"a computer programming language designed to challenge and amuse programmers, and is not suitable for practical use. Its name has been variously euphemized, as in
brainf*ck."
A brainf*ck program has an implicit byte pointer, called "the pointer", which is free to move around within an array of 32768 bytes, initially all set to zero. The pointer itself is initialized to point to the beginning of this array.
The brainf*ck programming language consists of seven commands, each of which is represented as a single character. Note:
"Industry standard" brainf*ck actually has eight commands, but for the purposes of this problem one command was intentionally omitted.
COMMAND
OPERATION
>
Increment the pointer.
Incrementing a pointer value of 32767
results in a pointer value of 0.
<
Decrement the pointer.
Decrementing a pointer value of 0
results in a pointer value of 32767.
+
Increment the byte at the pointer.
Incrementing the byte value 255 results
in the byte value 0.
-
Decrement the byte at the pointer.
Decrementing the byte value 0 results
in the byte value 255.
.
Output the character whose ASCII
value is the byte at the pointer
[
Jump forward past the matching
]
if the
byte at the pointer is zero.
]
Jump backward to the matching
[
unless the byte at the pointer is zero.
For this problem, you will write a program that reads in, parses and executes a brainf*ck program.
Input
Input contains exactly one program. The program consists of one or more lines of brainf*ck commands. Your program should ignore any illegal characters (I.E. any character not in the set: <>+-.[]), If a percent sign (%) is encountered during parsing, the remainder of the line should be discarded. This constitutes a comment. The maximum number of commands in a brainf*ck program is 128000.
Output
Your program should output the output generated by the brainf*ck program. The only possible parsing error that can occur is if there is an unmatched [ or ] in the brainf*ck program. If your program encounters such an error, it should simply print "
COMPILE ERROR
" instead of executing the program. All brainf*ck programs will use no more than the specified 32768 bytes of memory.
Score
Score is the length of your source.
Example
Input:
++++++++[>+++++++++ % hello-world.
<-]>.<+++++[>++++++<-]>-.+++++++..
+++.<++++++++[>>++++<<-]>>.<<++++[>
------<-]>.<++++[>++++++<-]>.+++.
------.--------.>+.
Output:
Hello World!
Input:
[]]
Output:
COMPILE ERROR
A
super hard test case
was removed. | 34,659 |
Analyse Simple Arithmetical Expressions (EXPR2)
You are to write a program to analyse some simple arithmetical expressions. The BNF form of the defination of the expression is below.
<expression>::=<num><oper><num>
<num>::=0|1|2|...|99
<oper>::=+|-|*
Tip
: You may find this problem is like the problem
GALAXY
very much. To get round of the programming problems of using Brainf**k, Whitespace or Intercal, you must use C/C++/Pascal/Java to do the programming. Seems easy? Now there is an additional objective:
there must not be any semicolons ";" in your program!!!
Input
Multiple test cases, the number of them T is given in the very first line, T<=99. (In the judge data, T = 99.)
Each test case contains one line with a correct expression, without leading or trailing spaces.
Output
For each test case you should output one line contains the result of the expression without any leading zeros. You may assume this number is always a non-negative one.
Example
Input:
3
6*7
67-25
31+11
Output:
42
42
42
Score
Thanks to
Jin Bin
's suggestion, I've changed this problem from a classical one to a challenge one. Suppose the number of non-whitespace characters(ASCII 33 - 126) in your solution is
K
, the your score is
floor(K
3
/1000)+1
.
Note
The judge had something wrong and it has been fixed on Jul.1, 2008. Please accept my apology.
Note 2
Sorry to some users, but the C function "system()" is prohibited in this problem. Judge has been modified. Use problem
CE
to practice your programming skills without any(?) restrictions. | 34,660 |
Magic Program II (MAGIC2)
Task
Write a program with minimum length to print the
output
(119729 bytes).
Score
The score of your program is the length of your source code in bytes.
Notice: Sorry to the Python and PHP user, since these languages support compress functions, there are not allowed. Some submissions in these languages are judged as Wrong Answer now. | 34,661 |
JawBreaker Game (JAWB)
The goal of this popular game is to get maximum number of points, by removing aligned pieces of the same color. Pieces can only be removed if they touch each other by an entire side. The more pieces you remove in one turn, the more points you get. The number of points in one turn is described by the following formula: N*(N-1), where N is the number of pieces (for example 2*(2-1)=2, 10*(10-1)=90). If you remove pieces from the middle of the field, then all pieces located higher fall down and occupy the empty spaces. The game is finished when no pieces which can be removed from field remain.
In this problem you will be given a field and pieces on it. Your goal is to obtain the maximum number of points.
Note:
You can practice a little and plan your strategy with this on-line game [the on-line game is slightly different from the one described above]:
http://www.bigfrog.net/jawbreaker/
Input
t
– the number of tests, then
t
tests follow. [
t
<= 500]
Each test starts with 3 integers:
H
- the number of rows of the playing field,
W
- the number of columns of the playing field and
C
- the number of different colors of pieces. [4 <=
H, W
<= 50] and [3 <=
C
<= 20]. Then follow
H
rows with
W
numbers in each, separated by spaces. Each number is in the range from 0 to
C-1
and describes the color of a piece.
Output
For each test you must output the letter “Y” if you want to solve this test, or the letter “N” otherwise. If you output Y, you must output a set of lines with 2 integers
x, y
in each. These integers define rows and columns in the field. [0 <=
x
<
H
], [0 <=
y
<
W
]. Coordinates are counted from the upper left corner of field. After your last move output the line -1 -1. You’ll receive status Wrong Answer if your coordinates are outside the field, or point to an empty space, or to a single piece.
Score
The score received for this problem is calculated as follows:
score = 200*total_score/(200+time)
, where
total_score
- sum of points received for each playing field,
time
- process time for your solution in seconds. The
score
for a playing field is calculated as
(C*C*base_score)/(H*W)
, where
С
– number of different colors,
H
– field height,
W
– field width,
base_score
– number of points calculated as in the description of problem.
Example
Input:
1
4 4 3
0 0 1 1
1 1 2 2
0 1 2 0
0 1 1 2
Output:
Y
1 0
1 0
3 2
-1 -1
Explanation:
Initial field:
0 0 1 1
1 1 2 2
0 1 2 0
0 1 1 2
After the first turn (removed 5 "ones"):
. . . 1
0 . 1 2
0 . 2 0
0 0 2 2
After the second turn (removed 4 "zeros"):
. . . 1
. . 1 2
. . 2 0
. . 2 2
After the third turn (removed 3 "twos"):
. . . .
. . . 1
. . . 2
. . 1 0
Score:
In this case
base_score
= 5*(5-1) + 4*(4-1) + 3*(3-1) = 20 + 12 + 6 = 38,
total_score
= (3*3*38)/(4*4) = 21.375. Let’s suppose that it
takes 10 seconds to finish calculations, then
score
= 200*21.375/210 = 20.357143 | 34,662 |
Markov Algorithm (MAR)
Markov schemes are well known field of study in theory of algorithms. Let's define some slightly simplified schemes. We have some character set (alphabet), and a string composed of these symbols. Besides, we have rules of replacement, and each rule specifies the substring to be replaced and the replacement string. The replacement string can be empty. The order of rules is fixed. Everything functions as follows. Rules are looked through in input order. The first rule which can be applied, is applied exactly once (the given replacement which is described by the rule is carried out), and then the operation cycle repeats (the list is looked through anew). If there are many substrings in the line which satisfy a given rule then only the first (i.e., the leftmost) will be replaced. The process comes to an end if after the last rule application the line has not changed. During the process of replacements the length of the initial string can change, increasing or decreasing.
Example
:
Let’s consider the string
ababaab
and the set of rules
ab->c
cc->ab
As a result of the application of rules the initial string will be transformed into “cac”. The following intermediate results will appear:
ababaab, cabaab, ccaab, ccac, abac, cac
.
That’s all. And now some tasks.
Task 1
: The initial non-empty string was obtained from an ordinary arithmetic formula by the deletion of every symbol except brackets. You are to write the set of rules which transforms this string into the string "RIGHT" or "WRONG" depending on the correctness of brackets positions, following rules of bracket use in arithmetical expressions. For example, the string ()((())()) must be replaced by the string RIGHT, while the string (() must be replaced by the string WRONG with the same replacement rules.
Task 2
: The initial string represents an arbitrary string of the following type [integer1]+[integer2]=?, where [integer1] and [integer2] are decimal representation of some positive integers. You are to write a set of rules which translates the initial string into a string of the following type: [integer1]+[integer2]=[sum], where [sum] is the decimal representation of the sum of two numbers integer1 and integer2. For example, the string 2+2=? must be replaced by 2+2=4, and the string 25+76=? must be replaced by 25+76=101. The integers can be up to 100 digits in decimal notation.
Task 3
: You are given a string which consists of uppercase letters (A-Z), and ends with the "?" sign. You are to output this string in reverse order without the “?” sign. For example, the string ABBCD? must be transformed into DCBBA
Task 4
: You are given a binary integer which consists of 0s and 1s. You are to write it as a string of letters “z”, and the total number of such letters must be equal to the given binary number. For example, 110 must be translated by the algorithm into “zzzzzz”
Task 5
: You are given a string which consists of uppercase letters (A-Z), and ends with the "?" sign. You are to output this string in non-descending order without the “?” sign. After applying the rules to DFAAS?, the string should look like this: AADFS
Task 6
: You are given two decimal positive integers separated by the "_" symbol and followed by "=?", for example 30_42=?. You are to find and output the value of the greatest common divisor for this pair. For example for 30_42=? it’ll be 6.
Note
: The limit on the increase of the string during the work of the algorithm is 100000 symbols.
Input
There is no input data for this problem.
Output
You should output your solutions to every task one by one. If you don’t want to solve some particular task just output 0, otherwise output the length of your solution N. Then output exactly N lines
abc->def
, where
abc
is the substring for replacement, and
def
is the substring by which it will be replaced.
Score
For each correctly solved task you gain 1 point and additionally 1/N bonus points, where N is the length of the proposed solution.
Example
Output:
0
0
0
5
a->b
b->c
d->v
g->l
l->a
0
0
Score:
In this case (if the set of rules leads to a correct answer)
you’ll get 1 + 0.2 = 1.2 points for the 4-th task. | 34,663 |
Robo Eye (EYES)
A robot which helps to translate old papers into digital format is being prepared for mass production. But it requires special software to work efficiently. All scans which will be analyzed by the robot use one of the standard fonts: Arial, Courier, or Times New Roman. As the press is not ideal and pages can be rotated, some of the scans will be rotated by some degree. Imperfections of the robot's camera ("eye") can also cause some noise. Uniform noise can be up to 2% of the number of pixels. All analyzed documents are in uppercase English. The total number of letters in the robot's eye ranges from 3 to 6. The matrix in the robot's eye is monochrome and its size is 200x200 pixels.
Input
t
– the number of tests [
t
<= 500], then
t
tests follows.
Each test consists of 200 rows with 200 chars in each of them. Characters can be '.' and 'X', where '.' means the white color of the page, and 'X' is the black color of words.
The input data was generated using an on-line generator. The generator outputs data in 2 formats:
1)
as a picture
2)
as text
The datasets used for testing are such that all letters of the word are contained inside the picture.
Output
For each test output the recognized word in a separate line.
Score
The number of points you’ll receive for each image will be equal to the number of letters of the word, provided that it is correctly recognized.
Example
Input:
2
...........X...........X..............................................................X.................................................................................................................
.............................................X...........................X......................X.........................................X...............................................X.............
........................................................................................X...............................................................................................................
X............X....X...............................................................................................................X......X..................X......X.......................X..X.........
.........................................................X.........X.............................X.........................X.....XXX........X................................X..........................
................X.................................X...X....X......X.........................X...................................XXXXX.........................X.........................................
..............................X.X...........X.......................................................X......X....X.........X....XXXXXXX.........................................X........X...............
..............................................X...................................................................X..X.........XXXXXXXX.................................................................
......................................................................................................................X..........XXXXXXX................................................................
.....................................................................X............................................................XXXXXXX.......X......................X................................
...................................................X...........................X.....X...........X........X........................XXXXXXX...........................X..................................
.......................X...............................................................X............................................XXXXXXX.......................X...X.................................
.........X.................................................................................................X......X..................XXXXXXX.......................................................X....
.............X.........X.............................................X.....X...X.............X........................................XXXXXXXX...........................X...............X..............
...X....................................X.........................................................................................X....XXXXXXXX.........................................................
......................................X..........X...................................................................................X..XXXXXXXX.......................X................................
...........................................................................X.............................................................XXXXXXXX.......................................................
.....................................................X..X.........................................X.................XX...........X........XXXXXXXX......X.....................................X.........
......................X............................................................................................XXXXXXX.................XXXXXXXX....XX.................X.............................
....................X...........................................................................X..............X..XXXXXXXXXXXXX.............XXXXXXXX......X.....................X.......................
................................................................X................................................XXXXXXXXXXXXXXXXXXX.........XXXXXXXX...............X...................................
.............................................................................X......X..............X..............XXXXXXXXXXXXXXXXXXXXXXX.....XXXXXXXX..........X.......................X...............
......................X...........X.............X.............X....................................................XXXXXXXXXXXXXXXXXXXXXXXXXX..XXXXXXXX..............................................X..
....................................................................................................................XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX....................................X...........
.X...................X.............................................................X.................................XXXXXXX...XXXXXXXXXXXXXXXXXXXXXXXXXX..X.........................................X..
................................X..................................................................................X..XXXXXXX.......XXXXXXXXXXXXXXXXXXXXXX...........X..................................
..................................X..............................................................................X.....XXXXXXX...........XXXXXXXXXXXXXXXXX...........................................X..
.......................................X................................................................................XXXXXXX..............XXXXXXXXXXXX...............................................
.....XX...........................................................................X......................................XXXXXXX..................XXXXXX................................................
..............................................................................................................X...........XXXXXXX..................................................X....................
................X.....................................X.......................................X............................XXXXXXX.X.........X.............X......................X..............X......
......................................................................................................X.....................XXXXXXX.................................X.............................X...X.
....................X..X..................................................X...........................X......................XXXXXXX...............X.....X............................X.................
..................................................X....X.......................................................X..............XXXXXXX...................................................................
...........................X.............................................................X.X...................................XXXXXXX..................................................................
........X.X.......X..........................................................................X......................X...........XXXXXXXX..............................X.................................
.X............................................................................X...................XXX............................XXXXXXXX.........................................X.....................
........X..................................X.....................................................XXXXX............................XXXXXXXX........................................X.................X...
................................................................................................XXXXXXX........X...................XXXXXXXX.............................................................
.................................X.......................X.......................................XXXXXXX............................XXXXXXXX..X....X...............X....................................
................................................................X.................................XXXXXXX............................XXXXXXX..............X.................................X...........
...................................................................................................XXXXXXX....................X.......XXXXX.....................X.......................................
......X........................................X....................................................XXXXXXX............................XXX..............................................................
................X....................................................................................XXXXXXX............X...............X.....................................................X.........
......................................X...................................................XXX...X.....XXXXXXX....................XX....................................................................X
......................................................X..................................XXXXX.........XXXXXXX..................XXXX.....................X..X...........................................
...................................X........................X...........................XXXXXXX.........XXXXXXX.XX..............XXXXX...................................................................
.........................................................................................XXXXXXX.X.......XXXXXXX...............XXXXXX....................X.............X................................
.................................................................................X.....X..XXXXXXX.........XXXXXXX.....X.......XXXXXXX................................................................X..
.......................................X...................................................XXXXXXX.........XXXXXXX...........XXXXXXX........X.............X............................X................
.....................................................X...X..................................XXXXXXX.........XXXXXXX.........XXXXXXX............................................X........................
...........................................X.....................X.........................X.XXXXXXX.X.......XXXXXXXX.X....XXXXXXX...........................................X..........................
..........X...........................................................X............X..........XXXXXXX.........XXXXXXX.....XXXXXXX.....X.............X............................X...X..................
.X.................................................................X..............XXX..........XXXXXXX.........XXXXXXXX..XXXXXXX..X.................X...................................................
...................................X.............................................XXXXX..........XXXXXXX........XXXXXXXXXXXXXXXX............................................X............................
................................................................................XXXXXXX..........XXXXXXX.........XXXXXXXXXXXXX.......X......................................X...........................
...................................X.....X......X................................XXXXXXX..........XXXXXXX.........XXXXXXXXXXX..............................................................X............
.......................................X..........................................XXXXXXX..........XXXXXXX......X..XXXXXXXXX...................X...........................X.......X....................
.......................................................................XX..........XXXXXXX...X..X...XXXXXXX..X......XXXXXXX.....................X................X.....................X................
.........................X........................X.................................XXXXXXX..........XXXXXXX.........XXXXX...................X..............................................X...........
................................X..X..X..............................................XXXXXXX..........XXXXXXX.X.......XXX......X.......................................................X................
.......................................................X..............................XXXXXXX..........XXXXXXXX........X...........................X....................................................
.................................................................X.....................XXXXXXXX.........XXXXXXXX.................................................................X......................
.......................X................................................................XXXXXXXX.........XXXXXXXX.............................................X.........................................
...................................X.X.................X..............X..................XXXXXXXX.........XXXXXXXX....X..X...........................................................X..................
..........................X....................X........X.................................XXXXXXXX.........XXXXXXXX.................................X..X.......X........................................
.X........................................X..........................XX........X...........XXXXXXXX.........XXXXXXX........................X................................................X...........
....................................................................XXXXXXX....X............XXXXXXXX.........XXXXX.....X........................X.......................................................
.....................................X................X...........XXXXXXXXXXXXXX.............XXXXXXXX.......X.XXX.......................................................................................
X........................X........................................XXXXXXXXXXXXXXXXXXX.........XXXXXXXX.........X......................................X.................................................
.................X.................................................XXXXXXXXXXXXXXXXXXXXXXX.....XXXXXXXX.............X........................................................................X..........
......X....................X...................................X....XXXXXXXXXXXXXXXXXXXXXXXXXX..XXXXXXXX...............................X........................................................X.X.....
.............................X...X...................................XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX........................................X......................................................
.....................................X........................XX......XXXXXXX...XXXXXXXXXXXXXXXXXXXXXXXXXX..........................X...................................................................
.............................................................XXXX......XXXXXXX.......XXXXXXXXXXXXXXXXXXXXXX..........................................................................................X..
.....X..........................................X...........XXXXXX......XXXXXXX...........XXXXXXXXXXXXXXXXX...........XX...X............................................................................
................X...........................................XXXXXX.......XXXXXXX..............XXXXXXXXXXXX.....X........................................................................................
...........................................X.................XXXXXX.......XXXXXXX..................XXXXXX............................X.....................................X............................
.......X.................................X....................XXXXX........XXXXXXX...................................................X.............................X....................................
..............................................................XXXXXX........XXXXXXX..X..........X.........................X.....................................X...............X...............X.......
.............X............................................X....XXXXXX....X...XXXXXXX........X...........................................................X.........X...................X........X........
.....................................................X..........XXXXX.........XXXXXXX.................XX................................................................................................
..........X.....................................................XXXXXX.........XXXXXXX........................................................................X.........................................
...........................................X.....................XXXXXX.........XXXXXXX.................................................................................................................
.................................................................XXXXXX..........XXXXXXXX...................X..X........X...............................................................................
...............................X...........................X......XXXXXXX.......X.XXXXXXXX...........X................X..................X..................X...........................................
.........................X........................XX...............XXXXX...........XXXXXXXX................................X.................X.........X................................................
.................................................XXXXX.X...........XXXXXX...........XXXXXXXX...................................X........................................................................
X........................................XX..X..XXXXXXXX............XXXXXX...........XXXXXXXX.....................X.........................................................................X...........
...............................................XXXXXXXXXXX...........XXXXX.X..........XXXXXXX...................X..........X...............................................X............................
....X.........................................XXXXXXXXXXXXXX.........XXXXXX............XXXXX.....................................................X.....................X............X....X..............
......X.......................................XXXXXXXXXXXXXXX.........XXXXX.............XXX...........................X.................................................................................
........................X......................XXXXXXXXXXXXXXXX........XXXXX.............X...................................................................................................X.....X....
...............................................XXXXXX.XXXXXXXXXXX......XXXXXXX..................................................X.......................................................................
.........................X......................XXXXXX.XXXXXXXXXXXX.....XXXXX.....................X..............................X...........................X..........................................
................................X................XXXXX....XXXXXXXXXXX....XXXXX..........................X....................................X.......X...X.......................................X......
............X......................X.............XXXXXX.....XXXXXXXXXXX..XXXXX..................................................................................X....................................X..
........................X.........................XXXXXX......XXXXXXXXXXX.XXXXX...............X...........................................................................X.............................
..................X...........X...................XXXXXXX.......XXXXXXXXXXXXXXXX........................................................................................................................
..............................................X...XXXXXXX.........XXXXXXXXXXXXXX.........................................................X............................X.................................
...................................................XXXXXX...........XXXXXXXXXXXXX..................................X....................................................................................
...................................XXX..............XXXXXX............XXXXXXXXXXX.......................................................................................................................
..................................XXXXXX.............XXXXX..............XXXXXXXX........................................................................................................................
............X...X................XXXXXXXXX...........XXXXXX..............XXXXXXX.......................................X................................................................................
.....X...........................XXXXXXXXXX...........XXXXXX...............XXXX....................X...................X..............................................X..X..............................
...................................XXXXXXXXXX.......X.XXXXXX...........................................................X.........................................................X....................X.
.....................................XXXXXXXXXX........XXXXXXX....................................................................X...........................................X.........................
.......................................XXXXXXXXX.....X.XXXXXX.....................................................................................................................X.....................
..X.....................................XXXXXXXXXX......XXXXXX..........................................................................................................................................
...................................X....X.XXXXXXXXXX.....XXXXX................X.........................................................................................................................
...............................X......X.....XXXXXXXXX....XXXXXX.............XX..............................................................................................X...................X.......
..............................................XXXXXXXXX...XXXXXX.....................X..................................................................................................................
................................................XXXXXXXXX.XXXXXX...X............................X.................................X...........X..X......................................................
X......X.X........................X.X............XXXXXXXXX.XXXXXX.........................X................X.....X.....................................................X...................X............
...................................................XXXXXXXXXXXXXX....................................X.....................X............................................................................
.................................XX..................XXXXXXXXXXXXX...........................................X...X.X..........................................................................X.........
...........................X...........................XXXXXXXXXXX...X......................................X..................X........................................X...............................
...............................................X.........XXXXXXXXX.....................X................................................................................................................
..........................................................XXXXXXX..............................................................X.....................................X..................................
.............................X..........................X...XXXX...........X............................................................................................................................
....X..X..................................................X...X......................................X.....................X.....................................X......................................
....X....................................................X..............................X......X........................................................................................................
........................................................................................................................................................................................................
........................................X......X..X...............X...........................................................................X.......................X.............X...................
......................X......................................................X.....X...............X....................................................................................................
.........X.................................................................................................................X..........X..................................................X.............X
...........................X......................................................................................................................................X.....X...............................
......................................X...........................................................................X.......................................................X.........X.................X.
.............................................................................................................................................................................X....................X.....
....................................................................X................................X..................................................................................................
.................................................................................X.............................................X........................X......................X........................
........................X..................................................................................X...........................................................................X................
...........X.......................................X................X..............................X........................................................X.................................X.........
..........X.....................................................................................................X.......................................................................................
........................................................................................................................................................................................................
................................................................................................................X...............................................................X.......................
.............................X..............................................................X....................................................................X......................................
.....................X...............X....................X..................X....X.......X...............................................X......X......................................................
......................................................................................................................................................................X........................X........
..............................X.....X..................................................................................................................X..........X....................X..............X.
...........................X.X......................X.........X...............................X.......X..................................X................................X.............................
..X............................................................................X..........X......................................X....................................................X.................
.........................................................................................................................................................................X..........X..X................
.......................................................................................................................................X..........................X..........................X.........X
.....X.................................................X...........................X......X.................................................................................X...........................
............................X............................................................................X.X........................X...X.........................................................X.....
..X...........................................................X.......X...................................................X......................................................................X......
...........................X......................X....................X........................................................X.....X.................................................................
...................................X....................................................................................................................................................................
....................................................X.......................................................................................................X.......X.....................X.X...........
..........................XX.......................................................X...................X.......................................................................X........................
.................................X....................................................X.........................................................................X............................X.....X....
.................................................................X.......................................................X..............................................................................
............X...................X...................................................................................X..........................X........................................................
..............X.........................................................................................................................................................................................
........................................................................................X...............................................................................................................
..............................................................................X..................X.............................X........................................................................
.........................................................................X....X.............................X.....................X.....................................................................
..............................X............................................................X...................................X.................................................................X......
..........................................................................................................X.......X.....................................................................................
.............................................................................................X.....X....................................................................................................
..X............................................X...............................................................................X........................................................................
..................................................X...................X............................................X..X......................X...X..................X...................................
...........X.......................................X.X.......................................X................................................................................X................X........
................................................X..................................................................X...............................X.................................X..................
..X....................................................................X.................................................................................................................X..............
.....................................X..............................................................................................X...................................................................
......X........................................X..........................................................................................X.........................................................X...
..................................................X...................X..............................................................................................X........X.........................
.............X....................................................................X.......................X..................................................................X..........................
.............................X................................................................X....................................................X...............................X.......X............
.................................X..................................................................................X........................X.........X....................X...................X.......
.................................................................................................X.........................X............................................................................
...........X...X..............................................................................X.........................................................................................................
..................................................................................................................................X..................................................................X..
......X.........................................................................................................................X.......................................................................
.......................................................................................................................X................................X..............................................X
......................................................X..................................X...............................X..............................................................................
.............................X................................................................X.......................................................................XX.................X..............
.........................................X..........X.....................................................................................X.................X...X......................................X
......................................................X..........................................................................................................XX.....X...............................
.X..........................X...................X.....................................................X...................................................................X.............................
.............................................................X.................................................................................X..........................................X........X....
..........................................X............................................X................................................................................................................
......X..........X........................................................................................................X......X............................................................X.........
...................X...............X.............................................................................X........................................................X...X.........................
....................................X...........X..................................X....................................................................................................................
.............X........................................................X........X.......................................................X................................................................
..................X............................................X.........................................X............................................X................................................X
........................................................................................................X..X...........................................................................................X
.........................................X...................................................................................................................................................X..........
.......................X.......................................................................X....X...................................................................................................
...............................................................................................X.....................................X..................................................................
....X...........................................X...............................................................X.............X..............X..........................................................
....................................................X..............................................................................................X..X......................X....................X.....
............................................................................................X...............................X...............................X................X..........X...............
...X.............X...............X...........X.....................................................................................................................X....................................
.................................................................................................................................................X........................XX.X..........................
.X......X.............................X..............X.........................................................X................X.....X.................................................................
...X..............................................X.....................................................................................................................................................
..............X................................................................X....X...................................................................................................................
.........................X...............................................................X..X...........................................................................................................
.......................X................X..........X....................X.................................................X.....................X................X......................................
......................X...........................................................................................X.......................................X.........X...................................
...........X.........................................................................................................X...........X..........................X...........................................
................................X.............X...X.........................................X...............X........................................................X...............X..................
.................................................................X..............X.........X..............X..........................................X...................X............X..................
....................................................................................X................................................................X...................X..............................
..X...................................................................................................................................................................X.....X...........................
............................................................................X...........................X...............................................................................................
.........................................................................................................................X................................X.............................................
...................................................X.....................................................X......................X.......................................................................
...................................X...............................................X............X.......................................................................................................
....................................................X..........X..................................X......X....................................................X................................X........
............................X.......................................X..........................X.............................................X........................................X.........X.......
....................................................................................................................................................................................................X...
....................................X....................................................X.X...................X...X...............................................................X....................
...................X.......................................................................X............................................................................................................
..................................X............X.............................................................................X..........................................................................
............X..................X...........................................X...X..........X.............................X........X.......................X...........X.........X..............X.........
................................................................................................................X...............................X......X...X..............................X.............
......................................X...............................................................................................................X.X...................................X...........
X.............................................X..........X........................................................................................X................X....................................
.............................................................................X..........................................................................................................................
............................................................X..............................X......................................X.....................................................................
..........................................................................................................................X............................................X................................
...........................X..............................X...............................................................................X.............................................................
.............................................X....................................................................X.....................................................................................
......................................................................................................................................................X...X.............................................
...........................................................................................X.................................................................................................X.X........
..............................X.......................................................................X..X.............X..........X..............X......................................................
..........................................................X....................................X......................................................X.................................................
..............X....................................................................................................X.............X......................................................................
.............................................XX.....X.....................................X.............................................................................................................
........................X................................X.X.......................................................................................................................................X....
............X................X...............X............................................................................................X.............................................................
X.....X...............................................................................................X.................................................................................................
........................................X.............................................................X..............X.............................................X.................................X..
...................X...X..................................................X...................................X..............................................X...............................X..........
....................................X.............................X..................................................................X...........................................................X......
................................................X...............................X............X.................................................................................................X........
.......X..................................X.............................................................................................................................................................
.................X.............X....X............................................................................................................................X............X.........................
...........................................................X............................................................................................................................................
............................................................................................X...........X.......X.........................X..................................X.........................X
...X....................................................................................X..............X..X............................X................................................................
....................................................X...........................X............X...................................................................X.X....................................
....................................X..........X......X...........................................X..........X.........X.........X.................................................................X....
...............................................X...........X.X....................................................X...............X.....................................................................
...................................................................X....................................................................................................................................
...........................................................................................................................................................................X...X........................
...............................................X........................................X..............................................................................................X................
....................................X..............................X.........X.X........................................................................X...............................................
........................................................X....X........................................................................X....................................X.........................X..
....................X........................................................................X.............................................X..X...............X..X......................................
.........................X..................................X...............................X...X.............................................................X.........................................
...............X.......................X....................X......X....................................................................................X...........................................X...
............................................X...........X...............X..................X...........X....................................X...........................................................
...X.....................................................X..............................................................................................................................................
.....................................................X..................................X...................................................................................X...........................
........X.............................................................X................X.....................................X.......................................X..................................
X..................X......X...........................................................................................X...............X.................................................................
.........................................................................X.......................................................................................................X..............X.......
..............X..........................X...........................X..............................X...................................................................................................
..................................X.............X..................................................................................................X...................................................X
....................................X................................................................................................................................................X....X.............
.............X..........................................................................................................................................................................................
.................................X..................................................................................................................................................X.................X.
....................................................................................X...................................................................................................................
.............................................X........................................X.X..................................................................X...........................................X
.....................................X....................................................................................................................................X.X........X...............X..
................................X......X...............................X....................................................X..............................X............................................
.............X..........................................................................................................................................................................................
...........................................................X............X......................................................................................................................X........
...........................................................................................................................................................X............................................
......X........................................................................X.................X...................................................................................................X..
.....X..................................................................X...............................................................................................................................
.........................................................................................................................................................X..............................................
.............................X.....................................................X.........................................................X..........................................................
...........................X....................................................X.......X............................................X........X.......................................X.................
.........................................X.....................................................................X.......................X..................................................X.............
.X................................................................................................................................X.....................................................................
........................................................X...........................X.................X......................X..........................................................................
......X..........................................................X...............X....................X....................X...........X.X.....................X..X.....................................
XX..................................................................XXX.................................................................................................................................
....X.......X..................................X.....................XXX...........................X..............................................X.............................................X.......
...................X........X.................................X......XXXX...............................................................................................................................
....................................................................XXXXXXX....................................X....................................X....X...............X..............................
.....................................X.............................XXX..XXXX....X.........................X.............................................................................................
........X.........................................................XXX.....XXX.............................X.................................................X.....................X..X.............X....
.............X...............................X....................XX.......XX........................................................X..................................................................
.................................................................XXX........XX.........X.........................................................................................................X......
................X...............................................XXXX........XX..X........X...X................X.................X..............................X........................................
...............................................XX.............XXXX..........XX.................................................................................................X...........X............
.X..........................................X..................XXXX.........XX...XX..........................................X...................X......................................................
.X..........................X.................................XXXXXXX.......XX...XXXX.......................X............X....X.........................X...............................X........X......
.............................................................XXX..XXXX.....XXX....XXX.......................................................................................................X...........
............................................................XXX.....XXXXXXXXX....XXXX.................................................................X.................................................
.X...X...................................................XXXXX.....X.XXXXXXX....XXXXX...................X...............................................................................................
................................X........................XXXX..................XXXXX..........................X.......................X................................................X................
...........................................................XXX................XXX.XX.............................XX.....................................................................................
............................................................XXX...............XX..XX.....................X........X........X.....................X...........................X.......................X..
..................................................X..........XXX.............XXX..XX...........................................X..........................................................X..........X..
......................X.......................................XX............XXX...XX.........XX.........................................................................................................
.................................X.......................................X.XXX..XXX........XXXXX.....X...........................................................................X......................
..........X................................X....X.....X....................XX....XX.....XXXXXXXXX.......................................................................................................
.....................................................................X....XXX....XX...XXXXXXXX.XX......X..............X.................................................................................
...............................X.........................................XXX....XXX.XXXXX..XX.....XXX...........................................X.......................................................
....................X.................................................XXXXX......XXXXXX...XXX......XXXX.................................................................................................
.................................X..X.................................XXXX......XXXXX....XXX........XXX.............................................................X........................X..........
.............X.....X...........................................X.......XXX.......XX.....XXX..........XXXX..................................................X............................................
.........................XX...X................................X........XXX..X..........XX..........XXXXX..................................................X.........................................X..
..X..........XX.......................................................................XXXX.........XXX.XX................X..............................................................................
......................................................................................XXX........XXXX..XX...................................X...........................................................
.............................................XX......X.........X....X................XXX.......XXXX....XX...............................................................................................
..............................X.....................................................XXX.......XXXX.... | 34,664 |
Carl (CARL)
Professor Octastichs has invented a new programming language, Carl. An expression in Carl may be a positive or negative integer, or may be of the form
(p e1 e2)
where
p
is a real number between 0 and 1 (inclusive) and
e1
and
e2
are Carl expressions. An integer represents itself and
(p e1 e2)
represents
x + y
where
x
is the value of
e1
and
y
is the value of
e2
with probability
p
, otherwise it represents
x - y
.
Given a Carl expression, what is its expected value?
Input
Input consists of several Carl expressions, one per line, followed by a line containing ().
Output
For each expression, output its expected value to two decimal places.
Score
Score is the length of your source program.
Example
Input:
7
(.5 3 9)
()
Output:
7.00
3.00 | 34,665 |
Discover (DISCOVER)
Definite integral is an important part of Mathematical Analysis. During Mathematical Analysis lessons, students always find it quite hard to calculate the definite integral. And the software Mathematic is so complex that very few students can master its usage.
Next is the format for all functions in this challenge:
There are six types of basic elementary function:
constant function: C;
power function: x^C;
exponential function: e^x;
logarithmic function: ln(x);
trigonometric function: sin(x), cos(x), tan(x), cot(x), sec(x), cot(x);
inverse circular trigonometric function: asin(x), acos(x), atan(x).
C is a constant integer number between -100 and 100.
Elementary function is basic elementary function and their composite functions. There are ten types of composite functions. (A and B represent elementary functions)
A+B;
A-B;
-A;
A*B;
A/B;
A^B;
e^A;
ln(A);
sin(A), cos(A), tan(A), cot(A), sec(A), csc(A);
asin(A), acos(A), atan(A).
Arithmetic priority: () > ^ > *,/ > +,-
In this problem, the task can be proper integral, improper integral; it is also possible that its indefinite integral isn´t even an elementary function. But you can assume that, if the integrating range is [a,b], then (a,b) will be a subset of the function´s definitions. You can also assume that for any improper integral, the result of it will converge. Finally, it is guaranteed that the final result is between -10,000 and 10,000.
Input
The input consists of several test cases. There is a single number above all, the number of cases. There are no more than 50 cases. Each case contains two lines. The first line contains the function f(x) in the format above. There are no more than 40 letters each. There aren´t any whitespaces in the function.
The second line contains a and b, both of which can be string "INF" or "-INF"(quotes for clarify) - positive infinity and negative infinity respectively, or a floating point number between -100 and 100.
Output
For each case, print the value of
. The answer should be rounded to six digits to the right of the decimal point. Use the format in the sample.
Example
Input:
3
x
1 2
sin(x)^2/(sin(x)+cos(x))
0 1.5707963268
e^(-x)
0 INF
Output:
Case 1: 1.500000
Case 2: 0.623225
Case 3: 1.000000
The judge is "Score is source length". | 34,666 |
Attack A Single Test File! (SINGLEL)
Background
The purpose of this problem is to simulate attacking a problem with limited input/output data. Suppose a problem has only
N
bits (0/1) as input, 1 bit 0/1 as output. Obviously, it has 2
N
mutually distinct test files. Only with infomation given above, one can successfully get all the input/output data by submitting attacking programs and extracting judge's responses!
Interactive Protocol
You should communicate with Judge using standard input and output.
Attention: the program should clear the output buffer after printing each line. It can be done using fflush(stdout) command or by setting the proper type of buffering at the beginning of the execution - setlinebuf(stdout).
Each input contains exactly 2
6
= 64 games. The very first line of the input contains number
N
. After reading this data your program should play 64 games with judge.
At the beginning of each game, the judge will generate a permutation
P
of 0..2
N
-1 and a 0/1 string
S
of length 2
N
. These two parameters won't change during the whole game.
Each time you should send to the judge a line with a 0/1 string
S'
of length 2
N
.
If
S'
is purely coincident with judges string
S
, judge will send to you number "-1" as response. Your program should terminate the processing of this game immediately after getting this response.
Otherwise, judge's response will be a number
T
(0 <=
T
<= 2
N
-1), which means that, for each 0 <=
i
<
T
,
S'[P[i]] == S[P[i]]
, while
S'[P[T]] != S[P[T]]
. All the indices are 0-based.
For each game you should not make more than 6666 queries, otherwise you will get
Wrong Answer
verdict.
Scoring
For each game, if you use
w
queries before you get "-1" response, your score will be
w
2
. The score for each test file will be the sum of scores of the 64 games. The final score will be the average score of all test files. Smaller score is better.
Constraints
1 <=
N
<= 8.
Time limit for each test file is 33 seconds.
Example
The example of communication. J=Judge, P=Player.
J: 1
P: 00
J: 1
P: 01
J: 0
P: 10
J: -1
P: 00
J: 0
P: 10
J: 1
P: 01
J: 0
P: 11
J: -1
[and 62 games more]
Explanation
In the first example, judge's permutation is (1,0), while in the second example, judge's permutation is (0,1). The score of these two games will be 2
2
+ 3
2
= 17. | 34,667 |
Glenbow Museum (SPOJTEST)
NOTE: This problem can only be solved using ICK language.
The famous Glenbow Museum in Calgary is Western Canada's largest museum, with exhibits ranging from art to cultural history to mineralogy. A brand new section is being planned, devoted to brilliant computer programmers just like you. Unfortunately, due to lack of space, the museum is going to have to build a brand new building and relocate into it.
The size and capacity of the new building differ from those of the original building. But the floor plans of both buildings are orthogonal polygons. An orthogonal polygon is a polygon whose internal angles are either 90
o
or 270
o
. If 90
o
angles are denoted as R (Right) and 270
o
angles are denoted as O (Obtuse) then a string containing only R and O can roughly describe an orthogonal polygon. For example, a rectangle (Figure 1) is the simplest orthogonal polygon and it can be described as RRRR (the angles are listed in counter-clockwise order, starting from any corner). Similarly, a cross-shaped orthogonal polygon (Figure 2) can be described by the sequence RRORRORRORRO, RORRORRORROR, or ORRORRORRORR. These sequences are called
angle strings
.
Of course, an angle string does not completely specify the shape of a polygon -- it says nothing about the length of the sides. And some angle strings cannot possibly describe a valid orthogonal polygon (RRROR, for example).
To complicate things further, not all orthogonal polygons are acceptable floor plans for the museum. A museum contains many valuable objects, and these objects must be guarded. Due to cost considerations, no floor can have more than one guard. So a floor plan is acceptable only if there is a place within the floor from which one guard can see the entire floor. Similarly, an angle string is acceptable only if it describes at least one acceptable polygon. Note that the cross-shaped polygon in Figure 2 can be guarded by someone standing in the center, so it is acceptable. Thus the angle string RRORRORRORRO is acceptable, even though it also describes other polygons that cannot be properly guarded by a single guard.
Help the designers of the new building determine how many acceptable angle strings there are of a given length.
Input
The input file contains exactly 42 test cases. Each test case consists of a line containing a positive integer L(1<= L <=500), which is the desired length of an angle string. There won't be any extra whitespace in the input.
Output
For each test case, print a line with the number of acceptable angle strings of the given length.
Example
Input:
4
6
[and 40 test cases more]
Output:
1
6
[and 40 test cases more]
Note: Anyone who solves this problem will get 3 points because the only language available is
Intercal
. Any rejected submissions will be shown as "Wrong Answer" instead of different verdicts like WA, RE and TLE to make this problem a little more difficult.
The input has been corrected on Sep 27. 2010. Now it contains no extra '\r' at the end of each line. | 34,668 |
Super Quine (SELF)
Write A program to print itself n(-10 <= n <= 10) times.
Negative count means the reversed program.
Input
A line contains an integer n.
Output
The required string described above.
Score
Score is the length of your code.
Example
Input:
-2
Source:
abcdefg
Output:
gfedcbagfedcba
Score:
7
Hint:
You can contact me if you have any question about the Special Judge or your code. | 34,669 |
Nop (NOP)
Mirko purchased a new microprocessor. Unfortunately, he soon learned that many of his programs that
he wrote for his old processor didn't work on the new processor.
Deep inside the technical documentation for both processors, he found an explanation. In order to
work faster, the new processor imposes certain constraints on the machine code of programs,
constraints that never existed on the previous model.
The machine code of a processor consists of instructions that are executed sequentially. Each
instruction uses a byte of memory. Also, instructions can have zero or more parameters, each of which
uses an additional byte of memory. In machine code, parameters immediately follow an instruction.
When formatted as text, machine code instructions are uppercase letters, while parameters are
lowercase letters. For example:
A b c b B c c C D e f g h
This program consists of four instructions; the first takes three parameters, the second two, the third
none and the fourth takes four parameters. The program uses 13 bytes of memory.
The new processor model fetches memory in four-byte chunks so each instruction must start at a
memory address that is divisible by four (the first byte in memory is address 0). To achieve that, we
can insert NOP (no operation) instructions into the old program, instructions that do nothing and are
not limited to memory locations divisible by four. The above program, adapted to run on the new
processor, can look like this:
A b c b B c c NOP C NOP NOP NOP D e f g h
The instructions A, B, C and D are now at memory locations 0, 4, 8 and 12, which satisfies the
processor's constraints.
Write a program that determines the smallest number of NOP instructions that need to be inserted
for the given program to work on the new processor model.
Input
The input contains the machine code of the program written for the old processor model. The program
will consist of at most 200 English letters.
The program will always start in an instruction i.e. the first letter in the machine code will be uppercase.
If an instruction appears more than once in the machine code, it will always take the same number of
parameters.
Output
Output the smallest number of NOP instructions needed to adapt the program for the new processor.
Example
Input
Abcd
Output
0
Input
EaEbFabG
Output
5
Input
AbcbBccCDefgh
Output
4
Score is your source code length. Have fun! | 34,670 |
Brainf F##k Writing (BFWRITE)
Task is about checking your Brainf**k Skill!!
So you have to write "SPOJ is indeed awesome" just using brainf**k. Try to use as few letters as possible.
Input
Nothing
Output
Just: "SPOJ is indeed awesome"
Example
Input:
Output:
SPOJ is indeed awesome | 34,671 |
Relative Board (RELBOARD)
English
Vietnamese
Given a matrix A with dimension N*N (2 ≤ N ≤ 1000) which contains only 6 types of value: {-1, -2, 0, 1, 2, 3}
A is called the relative board of a sequence T = (T
1
, T
2
, ..., T
n
), or T relates to A if:
A
ij
= 0 : T
i
= T
j
A
ij
= 1 : T
i
< T
j
A
ij
= -1 : T
i
> T
j
A
ij
= 2 : T
i
≤ T
j
A
ij
= -2 : T
i
≥ T
j
A
ij
= 3 : T
i
is not equal to T
j
For all i, j: 1 <= i, j <= N
Given the relative board A, find the sequence of positive integers T = (T
1
, T
2
, ..., T
n
) that relates to A such that Max(T) is as small as possible. Suppose that the sequence T always exists.
Define Max(T) = Max(T
1
, T
2
, ..., T
n
).
Input
The first line contains an integer N. N lines follow, each line contains N integers that describe the relative board A.
Output
The first line contains Max(T). The second line contains N separated positive integers T
1
, T
2
, .., T
n
.
Score
Your score = Max(T).
Example
Input:
6
0 1 1 1 2 2
-2 0 1 0 2 2
-2 -1 0 3 0 1
-2 -2 3 0 1 1
-1 -2 0 -1 0 1
-1 -2 -1 -1 -1 0
Output:
4
1 2 3 2 3 4
-> Score = 4 | 34,672 |
Place the Numbers II (PLCNUM2)
Some days ago, Little Chucha bought a computer game. She is given a NxN board which she has to fill with the numbers 1 to N^2, no repetitions allowed. The computer calculates the sum of distances for each pair of consecutive numbers, that is, 1 -> 2, 2 -> 3, ..., N^2 -> 1. The goal is to make that sum as short as possible.
After many hours spent playing, Chucha has mastered the game. So she bought a new version and now the goal is to make the sum of distances as big as possible. Can you help her?
Input
Input consists of a single integer number 1<=N<=100, the size of the board.
Output
Output one possible placing of the numbers. You are to write N lines, N space separated integers each.
Example
Input:
3
Output:
1 2 3
4 5 6
7 8 9
Score:
Score for the example is:
Distance 1 -> 2 : 1
Distance 2 -> 3 : 1
Distance 3 -> 4 : 3
Distance 4 -> 5 : 1
Distance 5 -> 6 : 1
Distance 6 -> 7 : 3
Distance 7 -> 8 : 1
Distance 8 -> 9 : 1
Distance 9 -> 1 : 4
Sum of distances (SOD): 16, Min SOD: 10, Score: 1+16-10=7 points. | 34,673 |
Primes in Brainf##k (HS09BF)
Your task is to print all primes up to
100
separated by a single comma. Please do not print anything else after the last prime.
Attention:
You can use any programming language you want, as long as it is Brainf**k.
Input
Nothing.
Output
In a single line, all the primes up to
100
.
Example
Input:
Output:
2,3,5,7,...,97 | 34,674 |
Polybius square (POLYBIUS)
Wersja polska
English version
For given text, encipher it with
Polybius square
and print.
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 a string
n
(could contain spaces, which you dont have to encipher; apart from spaces it will be only made of big letters - 'A' to 'Z').
Output
For each test, print ciphered string
n
.
Score
Score is source length.
Example
Input:
4
SHORTENING IS FUNNY
NO IT ISNT
TRY IT AND ASCERTAIN
JI JI
Output:
43 23 34 42 44 15 33 24 33 22 24 43 21 45 33 33 54
33 34 24 44 24 43 33 44
44 42 54 24 44 11 33 14 11 43 13 15 42 44 11 24 33
24 24 24 24 | 34,675 |
Dos Date (DDATE)
In DOS, current date is stored in encoded form to reduce the space. Date is encoded in a single integer number. The binary form of the number can be divided to decode the date parameters.
Date is a sequence of 23 bits. First 14-bits for year, next 4-bits for month and finally 5 bits for date.
e.g., 12 February 1990 can be encoded as -
1990 02 12 ---> (11111000110 0010 01100) Binary Form
---> (1018956) Decimal Form
Your task is simple. You only will have to decode date from the given decimal encoded form. Score is source length.
Input
The input consists of N cases (equal to about 1000). The first line of the input contains only positive integer N. Then follow the cases. Each case consists of exactly one line with one positive integer X. This integer X is the encoded form which is to be decoded.
1<=N<=1000
X will fit in Integer(C Int) range.
Output
Output consist of exactly N lines of decoded form.
Example
Input:
5
1024275
1029012
1017036
903863
802507
Output:
19 August 2000
20 December 2009
12 June 1986
23 May 1765
11 June 1567 | 34,676 |
Burned Pancakes Tower (DBP)
The cook at the Frobbozz Magic Pancake House sometimes falls asleep on the job while cooking pancakes. As a result, one side of a stack of pancakes is often burned. Clearly, it is bad business to serve visibly burned pancakes to the patrons. Before serving, the waitress will arrange the stacks of pancakes so that the burned sides are facing down. You must write a program to aid the waitress in stacking the pancakes correctly.
We start with a stack of N pancakes of distinct sizes, each of which is burned on one side. The problem is to convert the stack to one in which the pancakes are in size order with the smallest on the top and the largest on the bottom and burned side down for each pancake. To do this, we are allowed to flip the top k pancakes over as a unit (so the k-th pancake is now on top and the pancake previously on top is now in the k-th position and the burned side goes from top to bottom and vice versa).
For example (+ indicates burned bottom, - a burned top):
+1 -3 -2 [flip 2] ⇒ +3 -1 -2 [flip 1] ⇒ -3 -1 -2 [flip 3] ⇒
+2 +1 +3 [flip 1] ⇒ -2 +1 +3 [flip 2] ⇒ -1 +2 +3 [flip 1] ⇒ +1 +2 +3
You must write a program which finds a sequence of flips, which converts a given stack of pancakes to a sorted stack with burned sides down.
Input
The first line of the input contains a single integer N < 55, the number of problem instances to follow. Each of the following N lines gives a separate dataset as a sequence of numbers separated by spaces. The first number on each line gives the number M of pancakes in the data set. The remainder of the data set is the numbers 1 through M in some order, each with a plus or minus sign, giving the initial pancake stack. The numbers indicate the relative sizes of the pancakes and the signs indicate whether the burned side is up (-) or down (+). M will be, at most, 1000.
Output
For each dataset, you should generate one line of output with the following values: The number of flips (K, where 0 <= K <= 3000) required to sort the pancakes and a sequence of K numbers, each of which gives the number of pancakes to flip on the corresponding sorting step. There may be several correct solutions for some datasets and your task is to find the shortest one.
Score
For each test case is (3M-1)/(K+1)
Example
Input:
5
12 -2 -1 -10 +7 -4 -8 +12 -3 +5 +11 +6 -9
11 +2 +6 -10 +4 -1 -5 +7 -8 -3 +9 -11
11 +1 +8 +11 +10 +4 +3 -5 +2 -6 -7 -9
13 -2 -12 +8 +9 +10 -6 -5 +3 -7 -4 +11 -1 +13
12 +11 -3 +7 -5 -8 -12 -9 -1 +4 -2 -10 +6
Output:
25 7 12 3 1 11 4 10 2 1 9 3 1 8 6 7 2 1 6 4 5 1 1 4 1 3
25 11 1 11 3 1 10 1 1 9 7 1 8 2 1 6 1 5 3 4 2 1 3 1 2 1
25 3 11 8 1 10 3 9 7 1 8 7 1 7 6 1 6 4 1 5 3 4 1 1 3 1
24 2 1 12 2 1 11 4 10 3 7 2 1 6 4 5 2 1 4 1 3 1 1 2 1
29 6 1 12 7 11 6 10 1 1 9 5 1 8 6 7 5 6 2 5 2 1 4 1 1 3 1 1 2 1
Score:
6.4943590 | 34,677 |
Area Difference (SQDIFF)
A gardener bought two sprinklers for his new garden. Each sprinkler moistens the soil around a circle with known radius. One will be working in the morning and the other in the evening. To plan how many plants of different species is better to plant, the gardener wants to know what area of the garden will be watered only in the morning, only in the evening or both in the morning and in the evening. After some searching on the Internet, he found a formula for calculating the area of intersection of circles, but for some reason the formula that would help to calculate the remaining two areas was not found.
Input
The first line contains T (1 <= T <= 1000) - the number of tests. The next T lines contain six integers x1, y1, r1, x2, y2 and r2 (0 <= xi, yi, ri <= 10000) - coordinates and radii of the first and second sprinkler, respectively.
Output
For each test case print the absolute value of the difference between the the area that is going to be watered only in the moring and the area that is going to be watered only in the evening rounded to two decimals after the point. Your score is the source length.
Example
Input:
1
2 2 4 5 2 3
Output:
21.99 | 34,678 |
Monster (MONS)
Your Task is simple. Write the code that will print the content of the following file:
monster
.
Input
No Input
Output
The content of the above file.
Score
Minimum is the size, better is the score. | 34,679 |
Fully Parenthesized Expression (BRACKETS)
Clyde has written a program that can evaluate arithmetic expressions. There is just one problem - the expressions must be fully parenthesized!
Help Clyde by making sure all of his expressions are fully parenthesized - he's willing to reward you.
Input
The first line of input contains a single integer
n
(1 ≤
n
≤ 1000) that indicates the amount of test cases.
On the next
n
lines will be a string
s
representing the expression.
S
will always contain a valid expression and will be strictly less than 256 characters in length.
The operators used in
s
are
*/%
of high precedence and
+-
of low precedence. All operators are binary. All input strings will consist of only characters in the set "
0123456789+-*/%()
" (no whitespace).
Output
Your program should output
n
lines, each containing the fully parenthesized expression
s
.
A fully parenthesized expression is one where each operator is one where all operands are surrounded by either one parenthesis and one operator, or two parentheses. There should not be any extra parentheses.
The outputted expression does not need to be a solvable expression.
Fully Parenthesized
Not Fully Parenthesized
(42)
42
(1+(2*3))
1+(2*3)
(1+((61%(3+6))*7))
1+61%(3+6)*7
Example
Input
6
42
1+2*3
1%6*2
2/0
(1+((61%(3+6))*7))
(((((1)))))
Output
(42)
(1+(2*3))
((1%6)*2)
(2/0)
(1+((61%(3+6))*7))
(1)
Score
Your score is the length of your source code. | 34,680 |
Terminating or Non-Terminating (DEC_BIN)
Binary representation of some decimals are terminating and some gives repeating decimal,for example the binary representation 7(111) is terminating but 7.2(111.0011001100110011...) is non terminating.
Given a number you have to determine whether it's binary representation is terminating or not.
Score is the length of the source.
Input
Each line of input presents a single test case: a string of decimal digits, each of them is no longer than
500
characters long.There will be no extraneous spaces in the input.
The input ends on EOF.
Output
Output “1" or “0” for terminating and non-terminating respectively.
Example
Input:
457788832157.625
Output:
1 | 34,681 |
Cycles, More Cycles (CYCLE)
A m-cycle in a directed graph is defined to be a sequence of vertices v
0
-v
1
-v
2
-v
3
-...-v
m
where an edge (v
i
, v
i+1
) exists for each 0 <= i < n, v
i
!= v
j
for all 0 <= i < j < m and v
m
= v
0
. For a given graph of n vertices we can count the number of cycles in it. Now you task is a little harder: find the maximum value among all graphs with certain constraints, that is, your graph should contain an edge from either vertex x to y or y to x, but not both.
Assume there are R m-cycles in your output, your solution will be awarded by w * R points, where w is related to n and m. Your score will be the sum of scores of all test cases.
Note your source must not be larger than 10000 bytes.
Input
One line containing two blank-separated integers, n and m, where 3 <= m <= n <= 17.
Output
Adjacent matrix A of the graph you found. Numbers must be separated by spaces. Edge (i, j) exists when and only when A
ij
= 1. A
ij
+ A
ji
<= 1 and A
ii
= 0 for any 0 <= i, j < n, or your solution will be judged as wrong answer.
Example
Input:
3 3
Output:
0 0 1
1 0 0
0 1 0
Assume w = 0.2, this solution will get 0.2 * 1 = 0.2 points for this case. | 34,682 |
Reverse the Input (REVINPUT)
A simple task is a rare thing in SPOJ these days. If you are looking for one, then this is just the task for you! All you need to do is to reverse the input
N
times.
Score is the length of your solution.
Input
The first lines of the input is an integer
N
(1 <= N <= 100). Next follows the input consisting of
ASCII characters
. The input is terminated by
EOF
. You may assume that length of each word is less then 1024 and maximum number of words can be never more than 1024.
Output
The input reversed
N
times with at least a space/newline between any two words of your output.
Example
Input:
2
fox jumps over the lazy dog.
Output:
.god .god yzal yzal eht eht revo revo spmuj spmuj xof xof
Input:
1
It matters not how strait the gate,
How charged with punishments the scroll.
I am the master of my fate:
I am the captain of my soul.
Output:
.luos ym fo niatpac eht ma I
:etaf ym fo retsam eht ma I
.llorcs eht stnemhsinup htiw degrahc woH
,etag eht tiarts woh ton srettam tI | 34,683 |
Word To Number (WORDNUM)
In this task you just need to convert a number from its word form to digit form. For example, you should output 1 for 'one', 37000 for 'thirty seven thousand' or 99 for 'ninety nine'. You can assume that output will be >= 0 and < 50000. Also all numbers will be valid i.e output will not have numbers like 023.
Input
First line of input has a single positive integer t = number of test cases. In the next t lines, given a number in word form.
Output
Output the number as specified.
Example
Input:
3
one hundred twenty three
thirty four thousand one hundred eight
eleven
Output:
123
34108
11
Score :
Source code length | 34,684 |
Nth Prime (NPRIME)
Given an integer
1 <= N <= 100000
, you have to print the Nth prime number.
Score is the length of your source.
Input
The input file consists of series of numbers one in each line.The input is terminated by EOF.
Output
The Nth prime number.
Example
Input:
3
5
7
11
Output:
5
11
17
31
PS: Timit limit and test cases are modified on
05.10.2010
to encourage more short solution. | 34,685 |
Prisoner of Benda (Challenge) (BENDA)
Daniel enjoys watching TV series. One of his favourite is Futurama. One episode has the following plot.
Professor Farnsworth switches bodies with Amy using a new invention so that he can relive his youth. Likewise, Amy is reminiscent of her younger days of constantly eating and wishes to use the Professor's skinny body to gorge herself with food once again. Later, they find they cannot switch their bodies back with each other, because the device will not operate on the same pairing of bodies. The Professor thoughtlessly suggests they might be able to switch back to their original bodies with a third person. Bender switches bodies with the Professor (Amy's body) so he can perform a robbery without being identified. After realizing his mistake, the Professor, now in Bender's body, tires of trying to solve the problem. He decides to live a life of daring stunts and joins a robot circus.
Bender, now in Amy's body, is caught aboard the yacht of Robo-Hungarian emperor Nikolai. When Bender states that he is really a robot who has switched bodies with a human, Nikolai reveals that he feels trapped by his wealth and wishes to live the life of a normal, "peasant" robot. Bender tricks him into switching bodies with a robot wash bucket and inhabits Nikolai's body, planning to live like an emperor. However, he discovers that Nikolai's fiancée and first officer are plotting to kill him. Bender is saved with the assistance of the Professor and the circus' loyal Robo-Hungarian citizens. Meanwhile, Leela switches bodies with Amy, thus inhabiting the Professor's body, when she comes to believe that Fry only loves her for her beauty. In order to beat Leela at her own game, Fry switches bodies with Dr. Zoidberg in an attempt to repulse Leela. This leads them to one-up each other using various disgusting acts while on a date, which climaxes when the two have sex with each other in their equally grotesque bodies, and reconcile. During this time, Amy has overeaten in Leela's body, making it overweight. She switches bodies with Hermes, so she can continue eating while Hermes slims Leela's body back down. While eating, she witnesses Fry and Leela making out in the Professor and Dr. Zoidberg's bodies and loses her appetite for food. Concurrently, Zoidberg and Nikolai, in the respective bodies of Fry and the robot wash bucket, become friends and attempt to assume the lives of Fry and Bender, blowing up their apartment in the process. The bucket, now in Amy's body, professes its love to Scruffy the Janitor, but he turns it away. Finally, two Globetrotters, Ethan "Bubblegum" Tate and "Sweet" Clyde Dixon, mathematically prove that everyone's minds can be restored using two additional bodies and then successfully do so, with themselves as the extras.
We need to replicate how they have accomplished this. We will consider that a certain amount of body switches already took place. We need to determine the sequence of switches after which everyone is in self body, using no more than two extra bodies. Don't forget that two specific bodies can be mind switched only once.
Input
The first line of input contains t - the number of test cases. The description of tests follows. The first line of each test is numbers n - the numbre of characters and m - the number of body swtiches already taken place. Next m lines contain the description of switches. Let us mark all bodies with numbers from 1 to n. Then each switch is defined by two numbers a, b - the numbers of bodies used in the switch. The switches are listed chronologically.
Constraints
1 <= t <= 50
2 <= n <= 200
1 <= m <= n(n-1)/2
1 <= a, b <= n
Output
Print the number of switches needed to return everyone to their own bodies in the first line of the output. Then you should print the switches themselves in the order they should be performed. The format should be the same as in the input data. You can output any valid solution. However you shouldn't use more than two extra bodies. The extra bodies should be marked as n+1 and n+2. After all the switches the extra characters should be in their own bodies as well. Also you can't use more than 3n swtiches.
Scoring
For each test case you score will be the amount of switches. Moreover if you use only one extra body your score will be 0.9 multiplied by the amount of swtiches. If no extra bodies used - 0.8*<amount of switches>. The score for the problem will be the sum of the scores of individual test cases.
Example
Input:
1
2 1
1 2
Output:
5
1 3
2 4
2 3
1 4
3 4
The score of such solution will be 5. | 34,686 |
The Electronic Dice (DIE_PIP)
A
die
is a small throwable object with multiple resting attitudes, generally used as gambling devices, especially for craps or sic bo, or for use in non-gambling tabletop games.A traditional die is a cube (often with corners slightly rounded), marked on each of its six faces with a different number of circular patches or pits called
pips
. All of these pips have the same appearance within a set of dice, and are sized for ease of recognizing the pattern formed by the pips on a face.
These pips are typically arranged in patterns denoting the numbers one through six. The sum of opposing faces traditionally adds up to seven.
In this problem we will be developing a module for electronic die,your task is to convert from the decimal die roll to the visible configuration of pips (dots) on the electronic die's face,as this die is electronic we will use 0 and 1 instead of the standard one.
The challenges thrown to you are that you can use any one of your favourite programming language(s) as long it's name starts with 'C' and to keep your solution less than 128 bytes.
Score is the length of your source.
Input
An integer N
(0<N<7),
one in each line. Input is terminated by EOF.
Output
The face of the die giving the appropiate value.
Example
Input:
1
2
3
4
5
6
Output:
0 0 0
0 1 0
0 0 0
0 0 1
0 0 0
1 0 0
1 0 0
0 1 0
0 0 1
1 0 1
0 0 0
1 0 1
1 0 1
0 1 0
1 0 1
1 0 1
1 0 1
1 0 1 | 34,687 |
Christmas Tree (XMAS)
English
Vietnamese
Write a program to print to the screen the following Christmas tree. Your score is the length of your code, the smaller the better.
_____________*_______________
____________***______________
___________*o_o*_____________
__________*o___o*____________
_________*o_____o*___________
________*o___o___o*__________
_______*o___o_o___o*_________
______*o_o_o___o_o_o*________
_____*___*o_____o*___*_______
________*o_______o*__________
_______*o____o____o*_________
______*o____o_o____o*________
_____*o____o___o____o*_______
____*o__o_o_____o_o__o*______
________*o_______o*__________
_______*o_________o*_________
______*o___________o*________
_____*o_____________o*_______
____*o_______________o*______
___*o_________________o*_____
__*o___________________o*____
_*o_o_o_o_o_o_o_o_o_o_o_o*___
____________o_o______________
____________o_o______________
____________o_o______________
____________o_o______________
____________o_o______________
____________ooo______________
Merry Christmas and happy new year to you! | 34,688 |
Number to Word (NUMWORD)
In this task you just need to convert a number from its digit form to word form.
For example, you should output 'one' for 1, 'thirty seven thousand' for 37000.
You can assume that input will be >= 0 and <= 50000.
Also all numbers will be valid i.e. input will not have numbers like 023.
Input
Input contains one line which is n, 0 <= n <= 50,000.
Output
Output the number in words as specified.
Example
Input:
123
34108
Output:
one hundred twenty three
thirty four thousand one hundred eight
Score
: source code length.
Problem was modified on 23/2/2011. Many other languages added as users want, and problem statement changed which lead to no accepted solutions and that is because increasing in test cases number. | 34,689 |
Printf Parser (PRINTF)
In this task you have to parse a C language printf statement and print the output that will be produced on executing that statement in C. The statement will be of type printf("A",A1,A2,A3.....); where A consists of small latin alphabets, whitespaces and following format specifiers ( whitespaces will be present only in A ):
%d - signed decimal integer
%c - character
%f - decimal floating point( 6 digits after decimal point )
%s - character string
A1, A2, A3 ... are the arguments passed to printf statement and they will be equal to number of format specifiers mentioned. Their argument type will be same as that of format specifier i.e if specfier is '%c' the corresponding argument will be a character only. Input will always have at least one format specifier.
Input
First line of input contains a positive integer T denoting number of test cases. Following T lines have a valid printf statment containing less than 500 characters.
Output
Print the corresponding output given by the printf statement.
Example
Input:
2
printf("%c %d%f",'L',123,4.5);
printf("hello %f world %d nice %f computer %c is easy %s",2.34123245231,100,1.41414141,'S',"problem");
Output:
L 1234.500000
hello 2.341232 world 100 nice 1.414141 computer S is easy problem
Score :
Source Code Length | 34,690 |
PATHS (WAYS)
Consider a square matrix of order m (m+1 rows and m+1 columns). At each step you can move one step to the right or one step to the top. How many possibilities are to reach (m, m) from (0, 0)?
Input
The first line consists of an integer t, the number of test cases. Each test case consists of a single integer m, the order of square matrix.
Output
For each case print the number of possibilities of reaching the point (m, m) from (0, 0)
Constraints
1 ≤ t ≤ 10
1 ≤ m ≤ 14
Example
Sample Input:
3
1
2
3
Sample Output:
2
6
20
Explanation of Test Cases 1 and 2
See Also :
WAYS (No source limit) | 34,691 |
BF_MODULUS (MODULUS2)
See also
http://www.spoj.com/problems/PROBLEM1/
Problem
Given an integer n print all the possibilities of a%n.
Input
The first line consists of an integer t, the number of test cases followed by t lines containing an integer n.
Output
For each test case print all the possibilities of a%n in descending order separated by a single space. After each test case print a new line character. If there are no possibilities print "NOT POSSIBLE".
Input specifications:
0<t<=100
0<=N<=100
Time limit
: 1 second
Example
Sample Input
2
1
2
Sample Output
0
1 0 | 34,692 |
Sum of Fibonacci numbers (FIBSUM)
Given the
i
th (1<=i<=35) Fibonacci number F
i
calculate the sum of the
i
th till
i+9
th number F
i
+F
i+1
+...+F
i+9
and the last digit of the
i+246
th one F
i+246
.
Be careful: Your solution mustn't exceed 111 bytes. But rather half of it should be more than enough.
Score is source length.
Input
In the first line the number of testcases N<=100, then N lines with one positive integer i.
Output
One line with "F
i
+F
i+1
+...+F
i+9
+last digit of F
i+246
" for each i.
Example
Input:
2
1
35
Output:
146
1821381552 | 34,693 |
Distributing the balls (BALLS)
In this task you have compute the number of ways we can distribute
A
balls into
B
cells with with every cell having at-least one ball.
Input
The inputs A and B are given in a single line separated by a blank,the inputs are terminated by EOF.
Output
Output the answer modulus 247383691.
Score
Score is the length of your code.
Example
Input:
12 4
6 3
Output:
14676024
540
Constraints
Every A and B can be distinguishable.
[math]0 \le A \le 1000000 [\math]
[math]0 \le B \le 100 [\math] | 34,694 |
Equation Check (EQCHECK)
Given an equation of a straight line of form Ax+By=C. A,B,C are integers. You have to check if it passes through any lattice point or not.
Input
First line => T = No of test cases < 100
Next T lines contains the equation of form Ax+By=C. 1 < A,B,C < 10^6
Output
Print 'yes' if line passes through any lattice point, else print 'no' for each test case.
Example
Input:
2
2x+3y=4
6x+8y=25
Output:
yes
no
Score
: Source Code Length | 34,695 |
Digits of Phi (Golden Ratio) (PHIVAL)
Calculate as many digits of the
Golden Ratio φ
((1+5^0.5)/2) as possible but at least 1000 after the decimal point. More then 1000000 digits won't enhance the score. In addition try to shorten your code.
Input
None
Output
1.61803398874989484...
Score
Speed and code length should be rated similarly. Though it must be difficult that's an attempt:
Score
= min(1000000, (number of correct digits)) + 15000000 / (source length) | 34,696 |
Summing up Last digits (PLDGTS)
Let F(x) is a function which returns the last digit of the first prime number with 'x' digit. The first few values of F(x) is:
F(1) = 2
F(2) = 1
F(3) = 1
F(4) = 9
F(5) = 7
The value of F(x) for 1 <= x <= 25 is {2,1,1,9,7,3,3,9,7,7,9,3,9,7,1,7,1,3,3,1,9,7,9,7,7}.
In this task you have to compute the sum up F(x)'s between two given a and b (including)
Constraints:
1 <= T <= 1000
1 <= a <= b <= 1000
Input
The first line of the input is an integer T(say),then T test cases follows.
Output
Output the answer one in each line.
Example
Input:
3
647 997
736 823
632 928
Output:
1741
410
1487
Constraints:
1 <= T <= 1000
1 <= a <= b <= 1000
Score
Score is the length of your code. | 34,697 |
Grid points (GRIDPNT)
There's a Cartesian lattice with 0<=x,y<=n. Given one point (x1, y1>0) in this lattice rotating clockwise as little as possible around the origin find the next point (x2, y2). The given and searched points mustn't have another point between the origin (0, 0) and this point itself.
x1, y1, x2, y2 are non-negative integers.
Score is source length.
Input
In the first line the number T (T<100) of test cases.
Then T lines with the space-separated n (1<=n<=50), x1 and y1.
Output
For each test case the space-separated x2 and y2.
Example
Input:
3
1 1 1
5 3 2
50 48 49
Output:
1 0
5 3
49 50 | 34,698 |
Connecting three towns (THREETWN)
Given three towns find the point for which the summary distance to all towns is as small as possible.
The shorter all streets together, the shorter your source code and the faster your code the better will be your score. For the street length you can get at most 10000000 points, for each of the other parts 5000. Thus the best score is 10010000.
Input
In the first line the number T (T<100) of test cases. Then T lines with the space separated coordinates (integer 0<=x,y<=100) of the three towns.
Output
For each test case the coordinates of the above specified point.
Example
Input:
2
2 2 1 1 2 1
1 0 0 0 2 1
Output:
1.78867513459 1.21132486541
1 0 | 34,699 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.