task stringlengths 0 154k | __index_level_0__ int64 0 39.2k |
|---|---|
Positive, negative or zero (PRF0101)
Write a program that allows user to enter any integer named a and then checks that the number entered is positive, negative, or zero.
Example 1:
Please enter any integer: 2
2 is a positive number
Example 2:
Please enter any integer: -9
-9 is a negative number
Example 3:
Please enter any integer: 0
The number entered is zero
Â
Input
Allow user input a number t.
Constraints
-100 < t †100
Output
check t is positive, negative or zero, show the result
Example
Input:
1
Output:
Please enter any integer: 1 is a positive number | 35,200 |
sqrt (PRF0102)
Write a program that allows user to enter any number named n and then calculates square root of the number entered. Before calculating the square root, the program needs to check whether the input number is negative or not.
Hint: use the function double sqrt (double n) of the math.h library to calculate the square root of the parameter n.
Example 1:
Please enter any number: -2
Accept positive number only!
Example 2:
Please enter any number: 15
Square root of 15.000000 is 3.872983
Example 3:
Please enter any number: 0
Square root of 0.000000 is 0.000000
Input
Allow user entry a number
Output
Calculates square root of the number entered and show result
Example
Input:
6
Output:
Square root of 6.000000 is 2.449490 | 35,201 |
Division (PRF0103)
Write a program that allows user to enter two integers called m and n then calculates the value of
m divided by n
.
Before dividing, the program must check whether the denominator is zero.
Example 1:
Please enter numerator: 7
Please enter denominator: 0
The denominator canât be zero!
Example 2:
Please enter numerator: -8
Please enter denominator: -5
Result: -8 / -5 = 1.600000
Example 3:
Please enter numerator: 10
Please enter denominator: -2
Result: 10 / -2 = -5.000000 | 35,202 |
IF (PRF01IF01)
Write a program that allows user enter an even number. The program must check and show result.
Example format: ouput
input
Â
Example 1:
Please enter an even number:
2
Thank you.
Example 2:
Please enter an even number:
1
Â
1 isn't an even number.
Example 3:
Success #stdin #stdout 0s 4504KB
Please enter an even number:Thank you.
Success #stdin #stdout 0s 4500KB
Please enter an even number:1 isn't an even number.
Success #stdin #stdout 0s 4176KB
Please enter an even number:0 is zero.
Please enter an even number:
0
0 is zero. | 35,203 |
IF (PRF01IF02)
Write a program that allows user enter an odd number. The program must check and show result.
Example format: ouputÂ
input
Â
Example 1:
Please enter anÂ
oddÂ
number:
1
Thank you.
Example 2:
Please enter anÂ
oddÂ
number:
2
Â
2 isn't an odd number.
Example 3:
Please enter an odd number:
0
0 is zero. | 35,204 |
IF (PRF01IF03)
Write a program that allows user enter a number divisible by 5 but not divisible by 3. The program must check and show result.
Example format: ouputÂ
input
Â
Example 1:
Please enter a number divisible by 5 but not divisible by 3:15
15 isn't a number divisible by 5 but not divisible by 3.
Please enter a number divisible by 5 but not divisible by 3:5
Thank you.
Please enter a number divisible by 5 but not divisible by 3:1
1 isn't a number divisible by 5 but not divisible by 3.
Please enter a number divisible by 5 but not divisible by 3:0
0 isn't a number divisible by 5 but not divisible by 3.
Please enter a number divisible by 5 but not divisible by 3:
15
15 isn't a number divisible by 5 but not divisible by 3.
Example 2:
Please enter a number divisible by 5 but not divisible by 3:
5
Thank you.
Example 3:
Please enter a number divisible by 5 but not divisible by 3:
1
1 isn't a number divisible by 5 but not divisible by 3.
Example 4:
Please enter a number divisible by 5 but not divisible by 3:
0
0 isn't a number divisible by 5 but not divisible by 3. | 35,205 |
IF (PRF01IF04)
Write a program that allows user enter a number divisible by 5 and divisible by 2. The program must check and show result.
Example format: ouputÂ
input
Â
Example 1:
Please enter a number divisible by 5 but not divisible by 3:15
0 isn't a number divisible by 5 but not divisible by 3.
Please enter a number divisible by 5 and divisible by 2:
15
15 isn't a number divisible by 5 and divisible by 2.
Example 2:
Please enter a number divisible by 5 and divisible by 2:
10
Thank you.
Example 3:
Please enter a number divisible by 5 and divisible by 2:
1
1 isn't a number divisible by 5 and divisible by 2.
Example 4:
Please enter a number divisible by 5 and divisible by 2:
0
0 isn't a number divisible by 5 and divisible by 2. | 35,206 |
LOOP (PRF02LOOP01)
Write a program that prints the alphabet using uppercase characters.
Example
Output:
Alphabet
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z | 35,207 |
LOOP (PRF02LOOP02)
Write a program that prints the alphabet using lowercase characters.
Example
Output:
alphabet
a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z | 35,208 |
LOOP (PRF02LOOP03)
Write a program that displays the number-triangle with N lines and is formatted as below.
Example 1:
Please enter the positive integer N:
0
N must be greater than 0!
Example 2:
Please enter the positive integer N:
5
The number-triangle that has 5 lines is:
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
Note by Editorial Board
This program outputs prompts as though it is running in an interactive environment. SPOJ isn't interactive, and you'll get a better idea of what the real output should look like if you run your program in a similar non-interactive environment, such as
ideone
. I've done this and added the output below to give an alternative view of how the output should be formatted. Note the lack of newlines after the prompts. It looks like the problem setter has chosen the exact judge, so your output must match exactly.
Example
Input:
0
Output:
Please enter the positive integer N:N must be greater than 0!
Input:
5
Output:
Please enter the positive integer N:The number-triangle that has 5 lines is:
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5 | 35,209 |
LOOP (PRF02LOOP04)
Write a program that displays the number-triangle with N lines and is formatted as below.
Example 1:
Please enter the positive integer N:
0
N must be greater than 0!
Example 2:
Please enter the positive integer N:
4
The number-triangle that has 4 lines is:
1
1 2
1 2 3
1 2 3 4
Note by Editorial Board
This program outputs prompts as though it is running in an interactive environment. SPOJ isn't interactive, and you'll get a better idea of what the real output should look like if you run your program in a similar non-interactive environment, such as
ideone
. I've done this and added the output below to give an alternative view of how the output should be formatted. Note the lack of newlines after the prompts. It looks like the problem setter has chosen the exact judge, so your output must match exactly.
Example
Input:
0
Output:
Please enter the positive integer N:N must be greater than 0!
Input:
4
Output:
Please enter the positive integer N:The number-triangle that has 4 lines is:
1
1 2
1 2 3
1 2 3 4 | 35,210 |
ARRAY (INPUT,OUTPUT) (PRF03ARRAY0101)
Write a program that allows users to enter a numeric array with N elements. The program will display them.
Example 1
How many element of numeric array:
5
The value of a[1] is:
2
The value of a[2] is:
-1
The value of a[3] is:
8
The value of a[4] is:
3
The value of a[5] is:
0
Â
5 element of numeric array:
The value of a[1] is:2
The value of a[2] is:-1
The value of a[3] is:8
The value of a[4] is:3
The value of a[5] is:0
Example 2
How many element of numeric array:
3
The value of a[1] is:
2
The value of a[2] is:
1
The value of a[3] is:
3
Â
3 element of numeric array:
The value of a[1] is:2
The value of a[2] is:1
The value of a[3] is:3
Note by Editorial Board
This program outputs prompts as though it is running in an interactive environment. SPOJ isn't interactive, and you'll get a better idea of what the real output should look like if you run your program in a similar non-interactive environment, such as
ideone
. I've done this and added the output below to give an alternative view of how the output should be formatted. Note the lack of newlines after the prompts. It looks like the problem setter has chosen the exact judge, so your output must match exactly.
Example
Input:
5
2
-1
8
3
0
Output:
How many element of numeric array:The value of a[1] is:The value of a[2] is:The value of a[3] is:The value of a[4] is:The value of a[5] is:
5 element of numeric array:
The value of a[1] is:2
The value of a[2] is:-1
The value of a[3] is:8
The value of a[4] is:3
The value of a[5] is:0
Input:
3
2
1
3
Output:
How many element of numeric array:The value of a[1] is:The value of a[2] is:The value of a[3] is:
3 element of numeric array:
The value of a[1] is:2
The value of a[2] is:1
The value of a[3] is:3 | 35,211 |
ARRAY (SORT) (PRF03ARRAY0102)
Write a program that allows users to enter a numeric array with N elements. The program will sort and display them.
Example 1
How many element of numeric array:
5
The value of a[1] is:
2
The value of a[2] is:
-1
The value of a[3] is:
8
The value of a[4] is:
3
The value of a[5] is:
0
Â
ASC:
5 element of numeric array:
The value of a[1] is:-1
The value of a[2] is:0
The value of a[3] is:2
The value of a[4] is:3
The value of a[5] is:8
Example 2
How many element of numeric array:
3
The value of a[1] is:
2
The value of a[2] is:
1
The value of a[3] is:
3
Â
ASC:
3 element of numeric array:
The value of a[1] is:1
The value of a[2] is:2
The value of a[3] is:3
Note by Editorial Board
This program outputs prompts as though it is running in an interactive environment. SPOJ isn't interactive, and you'll get a better idea of what the real output should look like if you run your program in a similar non-interactive environment, such as
ideone
. I've done this and added the output below to give an alternative view of how the output should be formatted. Note the lack of newlines after the prompts. It looks like the problem setter has chosen the exact judge, so your output must match exactly.
Example
Input:
5
2
-1
8
3
0
Output:
How many element of numeric array:The value of a[1] is:The value of a[2] is:The value of a[3] is:The value of a[4] is:The value of a[5] is:
ASC:
5 element of numeric array:
The value of a[1] is:-1
The value of a[2] is:0
The value of a[3] is:2
The value of a[4] is:3
The value of a[5] is:8
Input:
3
2
1
3
Output:
How many element of numeric array:The value of a[1] is:The value of a[2] is:The value of a[3] is:
ASC:
3 element of numeric array:
The value of a[1] is:1
The value of a[2] is:2
The value of a[3] is:3 | 35,212 |
ARRAY (SORT) (PRF03ARRAY0103)
Write a program that allows users to enter a numeric array with N elements. The program will sort and display them.
Example 1
How many element of numeric array:
5
The value of a[1] is:
2
The value of a[2] is:
-1
The value of a[3] is:
8
The value of a[4] is:
3
The value of a[5] is:
0
Â
DESC:
5 element of numeric array:
The value of a[1] is:8
The value of a[2] is:3
The value of a[3] is:2
The value of a[4] is:0
The value of a[5] is:-1
Example 2
How many element of numeric array:
3
The value of a[1] is:
2
The value of a[2] is:
1
The value of a[3] is:
3
Â
DESC:
3 element of numeric array:
The value of a[1] is:3
The value of a[2] is:2
The value of a[3] is:1
Note by Editorial Board
This program outputs prompts as though it is running in an interactive environment. SPOJ isn't interactive, and you'll get a better idea of what the real output should look like if you run your program in a similar non-interactive environment, such as
ideone
. I've done this and added the output below to give an alternative view of how the output should be formatted. Note the lack of newlines after the prompts. It looks like the problem setter has chosen the exact judge, so your output must match exactly.
Example
Input:
5
2
-1
8
3
0
Output:
How many element of numeric array:The value of a[1] is:The value of a[2] is:The value of a[3] is:The value of a[4] is:The value of a[5] is:
DESC:
5 element of numeric array:
The value of a[1] is:8
The value of a[2] is:3
The value of a[3] is:2
The value of a[4] is:0
The value of a[5] is:-1
Input:
3
2
1
3
Output:
How many element of numeric array:The value of a[1] is:The value of a[2] is:The value of a[3] is:
DESC:
3 element of numeric array:
The value of a[1] is:3
The value of a[2] is:2
The value of a[3] is:1 | 35,213 |
ARRAY (MIN) (PRF03ARRAY0104)
Write a program that allows users to enter a numeric array with N elements. The program will display minimum of the entered array values.
Example 1
How many element of numeric array:
5
The value of a[1] is:
2
The value of a[2] is:
-1
The value of a[3] is:
8
The value of a[4] is:
3
The value of a[5] is:
0
Â
Min:-1
Example 2
How many element of numeric array:
3
The value of a[1] is:
2
The value of a[2] is:
1
The value of a[3] is:
3
Â
Min:1
Note by Editorial Board
This program outputs prompts as though it is running in an interactive environment. SPOJ isn't interactive, and you'll get a better idea of what the real output should look like if you run your program in a similar non-interactive environment, such as
ideone
. I've done this and added the output below to give an alternative view of how the output should be formatted. Note the lack of newlines after the prompts. It looks like the problem setter has chosen the exact judge, so your output must match exactly.
Example
Input:
5
2
-1
8
3
0
Output:
How many element of numeric array:The value of a[1] is:The value of a[2] is:The value of a[3] is:The value of a[4] is:The value of a[5] is:
Min:-1
Input:
3
2
1
3
Output:
How many element of numeric array:The value of a[1] is:The value of a[2] is:The value of a[3] is:
Min:1 | 35,214 |
String - Input/Output (PRF04STRING01)
Create a program that allows user to enter a text and print it out.
Input
text
Output
text
Example1
Input:
Lap trinh can ban C.
Output:
Lap trinh can ban C.
Example2
Input:
Cong nghe thong tin.
Output:
Cong nghe thong tin.
Example3
Input:
Infomation Technology.
Output:
Infomation Technology. | 35,215 |
String - lTrim (PRF04STRING02)
Create a program that allows user to enter a text, then removes whitespace from the left side of a string and print it out.
Input
       text
Output
text
Example1
Input:
Lap trinh can ban C
Output:
Lap trinh can ban C
Example2
Input:
Information Technology
Output:
Information Technology
Example1
Input:
Cong nghe thong tin
Output:
Cong nghe thong tin | 35,216 |
String - rTrim (PRF04STRING03)
Create a program that allows user to enter a text, then removes whitespace from the right side of a string and print it out.
Input
text         Â
Output
text
Example 1
Input:
Lap trinh can ban C
Output:
Lap trinh can ban C
Example 2
Input:
Information Technology
Output:
Information Technology
Example 3
Input:
Cong nghe thong tin
Output:
Cong nghe thong tin | 35,217 |
String - trim (PRF04STRING04)
Create a program that allows user to enter a text, then removes whitespace from the left side and right size of a string, removes all 2 whitespaces from inside that string and print it out.
Input
       text      text      Â
Output
text text
Example 1
Input:
Lap trinh can ban C
Output:
Lap trinh can ban C
Example 2
Input:
Information Technology
Output:
Information Technology
Example 3
Input:
Cong nghe thong tin
Output:
Cong nghe thong tin | 35,218 |
String - Limit (PRF04STRING05)
Allows the user to enter a string of up to 10 characters, and output the result.
Input
text.
Output
The first 10 characters of the input.
Example
Input:
123456789011
Output:
1234567890 | 35,219 |
InputOutut Array 2D (AR1NHAPINMANG)
Allow user enter size n x m of array, then entry each element in array
Input
n m
pt00 pt01 ....
pt10 pt11 ....
Output
pt00
pt01
.... (use tab)
pt10
pt11
....
Example
Input:
2 3
1 2 3
4 5 6
Output:
1
2
3
4
5
6 | 35,220 |
Input Array 2D and cal AVG (AR2AVG)
Allow user enter size n x m of array, then entry each element in array, show agv value
Input
n m
pt00 pt01 ....
pt10 pt11 ....
Output
avg
Example
Input:
2 3
1 2 3
4 5 6
Output:
3.500000 | 35,221 |
Nhap Mang Va Tim Max (AR2MAX)
Allow the user to enter the size of the array n à m, then enter the value of each element in the array. Find and print the maximum value.
Input
n m
pt00 pt01 ....
pt10 pt11 ....
Output
The maximum value from the array
Example
Input:
2 3
1 2 3
4 5 6
Output:
6 | 35,222 |
Nhap Mang Va Tim Min (AR2MIN)
Allow the user to enter the size of the array n à m, then enter the value of each element in the array. Find and print the minimum value.
Input
n m
pt00 pt01 ....
pt10 pt11 ....
Output
The minimum value from the array.
Example
Input:
2 3
1 2 3
4 5 6
Output:
1 | 35,223 |
Nhap Mang Va Tinh Tong (AR2SUM)
Allow the user to enter the size of the array n à m, then enter the value of each element. Calculate and print the sum of the values.
Input
n m
pt00 pt01 ....
pt10 pt11 ....
Output
print the sum of the array elements.
Example
Input:
2 3
1 2 3
4 5 6
Output:
21 | 35,224 |
Book (Struct) (AR2BOOK)
Build a struct that stores the book information in a structure:
title: string
author: string
subject: string
book_id: integer
Allow users to enter and display information 1 book.
Input
title
author
subject
book_id
Output
title : author : subject : book_id
Example
Input:
nghin le mot dem
khong tac gia
co tich
1
Output:
nghin le mot dem : khong tac gia : co tich : 1 | 35,225 |
Books (Struct) (ARBOOK2)
Build a struct that stores book information in a structure:
title: string
author: string
subject: string
book_id: integer
Allow the user to specify the number of books to save, enter information about the books, then display a list.
Input
n
title1
author1
subject1
book_id1
title2
author2
subject2
.....
Output
title1 : author1 : subject1 : book_id1
title2 : author2 : subject2 : book_id2
.....
Example
Input:
2
thang quy nho
nguyen nhat anh
thanh xuan vuon truong
2
bo cau khong dua thu
nguyen nhat anh
thanh xuan vuon truong
1
Output:
thang quy nho : nguyen nhat anh : thanh xuan vuon truong : 2
bo cau khong dua thu : nguyen nhat anh : thanh xuan vuon truong : 1 | 35,226 |
Employee (Struct) (AREMPLOYEE)
Build a struct that stores employee information in a structure:
id: string
name: string
gender: string
salary: integer
Allow user to enter information for one employee, then display it.
Input
ID
name
gender
salary
Output
ID : name : gender : salary
Example
Input:
NV02
Tran Thanh Hung
M
1500
Output:
NV02 : Tran Thanh Hung : M : 1500 | 35,227 |
Employees (Struct) (AR2EMPLOYEES)
Build a struct that stores employee information in a structure:
id: string
name: string
gender: string
salary: integer
Allow user to enter the number of employees and information for each one, then display a list.
Input
n
ID1
name1
gender1
salary1
ID2
name2
gender2
salary2
.....
Output
ID1 : name1 : gender1 : salary1
ID2 : name2 : gender2 : salary2
.....
Example
Input:
3
NV01
Tran Thanh Hung
F
1500
NV02
Nguyen Ngoc Bich
M
2000
NV03
Tran Trung Hau
F
1700
Output:
NV01 : Tran Thanh Hung : F : 1500
NV02 : Nguyen Ngoc Bich : M : 2000
NV03 : Tran Trung Hau : F : 1700 | 35,228 |
Suma de Numeros (SIS110G401)
Cuando comenzamos a sumar utilizamos las manos contamos un numero con la mano izquierda y otroa con la mano derecha, Vamos a sumar
Entrada
Un numero entero que representa la mano izquierda y otra que representa la mando derecha
Salida
Sume los dedos de ambas manos
Ejemplo
Entrada:
4 4
Salida:
8 | 35,229 |
ICPC (THR18A)
The Iranian ChamPions Cup (ICPC), the most prestigious football league in Iran, is reaching its end, and people are eagerly waiting for the finals, which happened to be between the two most popular Iranian teams, Persepolis and Esteghlal.
The ICPC finals consist of two matches, with each team competing as the home team in one match. The winning team is determined by aggregate score, the sum of the scores of the two matches. For example, if the scores of the two matches are Persepolis 6â0 Esteghlal in the first match, and Esteghlal 3â1 Persepolis in the second match, then the aggregate score will be Persepolis 7â3 Esteghlal, meaning that Persepolis is the winner. If aggregates are equal, the away goals rule is used to determine the winner, in which case the winner is the team that scored the most goals in the match it played away from home. If the result is still equal, a penalty shootout is required.
Hana, an avid football fan, is trying to figure out various scenarios in which her favorite team wins the finals. To this end, she aims to write a program that gets as input the number of goals in the two matches, and decides which team is the winner if it can be derived from the aggregate scores and the away goals rule, otherwise declares that the match goes to penalty kicks. You are going to help Hana write such a program.
Input
The first line of the input contains two space-separated integers p
1
and s
1
, where p
1
and s
1
are the number of goals scored by Persepolis and Esteghlal, respectively, in the first match in which Persepolis is the home team. The second line contains two space-separated integers s
2
and p
2
, where s
2
and p
2
are the number of goals scored by Esteghlal and Persepolis, respectively, in the second match in which Esteghlal is the home team. All input integers are between 0 and 20, inclusively.
Output
In the output, print the name of the winning team, either Persepolis or Esteghlal, if the winner can be determined by the aggregate scores and the away goals rule. Otherwise, print Penalty.
Example
Input 1:
3 0
2 1
Output 1:
Persepolis
Input 2:
3 1
2 0
Output 2:
Esteghlal
Input 3:
2 0
2 0
Output 3:
Penalty | 35,230 |
Chaarshanbegaan at Cafebazaar (THR18B)
Chaarshanbegaan is a gathering event at Cafebazaar similar to TGIF events at Google. Some entertainment programs like pantomime, foosball, Xbox/PS4, and several board games are part of the event. You are going to set up a dart game in Chaarshanbegaan. As a techie organizing a game for techies, you would rather use a smart screen and write a program to calculate the scores instead of hanging a traditional dartboard and scoring the shots manually. Your program must get the coordinates of dart shots for a player and calculate his/her total score. The score for each dart shot (at point (x, y)) is calculated based on its distance from the center of the dartboard (point (0, 0)). If the distance is d millimeters, the score is calculated based on the following table:
Input
The first line of the input contains a single integer N as the number of dart shots for a player (1 †N †100). Each of the next N lines contains two space-separated integers as the coordinates (x, y) of a dart shot. The coordinates are in millimeters and their absolute values will not be greater than 300.
Output
Print a single line containing the total score of the player.
Example
Input 1:
2
4 7
-31 -5
Output 1:
18
Input 2:
3
12 -16
-180 100
152 10
Output 2:
11 | 35,231 |
Denver and Emma (DNEQ)
Denver really likes Emma and he wants to impress her but Emma only like those boys who are good in problem solving. So Emma gave a problem to Denver and told him that she will only be impressed by him if he is able to solve the problem. As Denver is very bad in problem solving so he wants your help him. The problem statement is...
There are
N men
and their weight is increased by
A kg
each, when one of the men whose weight is
B kg
is replaced by a new man so you need to find the weight of new men.
Input
The first line of the input consist of a single integer number
t
which determines the number of test cases.
In each of next
t
lines there are three integer number
N
,
A
and
B
denoting the number of men which is
N
, the weight increased by
A
amount and the weight of the men which is replaced i.e. B kg.
Constraints
1 †t †10
1 †N †10
2
1 †A †99
1 †B †99
Example
Input:
2
8 1.5 65
6 3 80
Output:
77
98
Explanation:
In test case 1
st
there are 8 men and their weight is increased by 1.5kg so total weight increased = (8 Ã 1.5)kg = 12kg
The weight of the new men = (12 + 65) = 77kg. | 35,232 |
Count Set Bits (CSETB)
You are given a number
n
and you need to find the total number of set bits in the binary representation of all integers from
1
to
n
inclusive.
Input
The first line of input contains
t
denoting the number of test cases.
Next
t
lines contain a single integer
n
.
Constraints
1 †t †20
1 †n †10
4
Output
Output a single integer which is the total number of set bits in the binary representation of all integers from 1 to n inclusive.
Example
Input:
5
7
4
10
9
6
Output:
12
5
17
15
9 | 35,233 |
simple palindromes (FIZBBZIF)
A palindrome is a word or phrase which is the same backwards and forwards. Capitalisation and punctuation don't count.
Input
A list of words or phrases one at a time
Output
Each word, followed by " is a palindrome" or " is not a palindrome"
Example
Input:
dad
Hannah
A man, a plan, a canal, Panama!
Output:
dad is a palindrome
Hannah is a palindrome
A man, a plan, a canal, Panama! is a palindrome | 35,234 |
Eratosthenes Prime numbers (SIOENES)
Given an integer 'N', print count all the prime numbers which are less than or equal to 'N'.
Input description
First line of input is an integer T (number of testcases) and integer T will be followed by T lines, where each line will contain an integer N.
Output description
Output will consists of T lines. Each line will have count of prime numbers not greater than 'N'.
Constraint
1<=T<=10000
1<=N<=1000000
Example
Input:
2
9
11
output
4
5 | 35,235 |
Kevin likes array (KVAR)
Kevin likes array. This time he has a array
A[1], A[2] ... A[N]
. He calls a array beautiful, if the number of inversions is equal to the number of its local inversions. The number of inversion is equal to the number of pairs
(i;j)
such that
1 †i †j †N
and
A[i] > A[j]
and number of its local inversions is the number of integers i such that
1 †i < N
and
A[i] > A[i+1]
. So help him to find whether the array is beautiful or not. Print
YES
for a corresponding test case if it is beautiful and
NO
otherwise.
Constraints
1 †T †10
1 †N †100
1 †A[i] †100
Example
Input:
4
1
1
2
2 1
3
3 2 1
4
1 3 2 4
Output:
YES
YES
NO
YES
Explanation
Case 1.Here N = 1, so we have no pairs (i; j) with 1 †i < j †N. So the number of inversions is equal to zero. The number of local inversion is also equal to zero. Hence this array is beautiful.
Case 2. Here N = 2, and we have one pair (i; j) with 1 †i < j †N, the pair (1; 2). Since A[1] = 2 and A[2] = 1 then A[1] > A[2] and the number of inversions is equal to 1. The number of local inversion is also equal to 1 since we have one value of i for which 1 †i < N (the value i = 1) and A[i] > A[i+1] for this value of i since A[1] > A[2]. Hence this permutation is also good.
Case 3. Here N = 3, and we have three pairs (i; j) with 1 †i < j †N. We have A[1] = 3, A[2] = 2, A[3] = 1. Hence A[1] > A[2], A[1] > A[3] and A[2] > A[3]. So the number of inversions is equal to 3. To count the number of local inversion we should examine inequalities A[1] > A[2] and A[2] > A[3]. They both are satisfied in our case, so we have 2 local inversions. Since 2 â 3 this array is not beautiful.
Case 4. Here we have only one inversion and it comes from the pair (2; 3) since A[2] = 3 > 2 = A[3]. This pair gives also the only local inversion in this permutation. Hence the number of inversions equals to the number of local inversions and equals to one. So this array is beautiful | 35,236 |
Star Justify (STARJUST)
Pad strings with asterisks on either side to fill a given size of space. The string should appear in the centre, but if equal padding is not possible then the shorter padding should appear on the right of the string.
Input
The first line of the input contains the number of test cases. Each consecutive pair of lines provides an integer representing the size of space to fill and a string that needs to be padded.
Output
One string per line, which should be the asterisk-padded strings
Example
Input:
3
10
hello
10
milk
30
to be, or not to be
Output:
***hello**
***milk***
******to be, or not to be***** | 35,237 |
Clock hands on a different planet (ALIENCLK)
On planet Aberus, the day is broken into 16 hours. Each hour contains 80 minutes. An Aberitian child is using the clock face to learn about angles in her maths class. The teacher asks her to work out what angle is held between the two hands of the clock at different times of day, and report the answer in degrees. She'd rather use a program to calculate this, can you help her?
Input
The first input line contains a positive integer representing the number of test instances. Each subsequent line contains a clock time in the format HH:MM.
Output
For each of the clock times given, report the angle (between 0 and 359 degrees) that is held between the two hands of the clock, rounded to one decimal place. Note: If the angle is more than 180, subtract the angle from 360.
Example
Input:
3
12:00
06:00
13:15
Output:
90.0
135.0
130.8 | 35,238 |
Patio paving slabs (PATIOSLB)
You are building a patio, which is made up of stone paving slabs and grout (the material between the slabs which holds the patio together).
You need to lay a row of paving slabs to start the construction of a patio. You have bought a set of slabs of various different lengths. Which slabs should you choose from the set in order to fill the row perfectly? Remember that you'll need to leave a 1 cm gap for grout between each slab, and also a 1 cm gap for grout at either end of the row.
Input
The first line of input gives you the number of test cases. For each subsequent test case, there are three lines of input. In the first line you are given a positive integer representing the total length in cm of the row that you need to fill. The next line gives you a positive integer stating the number of patio slabs available. The third line gives the lengths in cm of the patio slabs that you have available, separated by spaces.
Output
Output the set of slab lengths that you have chosen, sorted in descending order, and separated by spaces. If there is no solution, output -1. If there are multiple solutions, output the solution that makes use of the largest of the slabs.
Example
Input:
2
100
9
20 40 30 24 31 18 55 40 23
50
4
20 20 30 40
Output:
55 23 18
-1 | 35,239 |
Factorising odd numbers (FCTORISE)
Any odd integer, m, greater than 1, can be factorised by expressing it as the difference of two squares, since if m = x^2 - y^2 then m = (x+y)*(x-y), so m has factors x+y and x-y.
For example, 15 = 4^2 - 1^2 = (4+1)*(4-1) = 5*3.
Rearranging the first equation above gives m + y^2 = x^2, so we can find x and y by evaluating m + y^2 for y = 0, 1, 2 ... until the perfect square x^2 is found.
Write a program to factorise an odd integer greater than 1 by expressing it as the difference of two squares.
Input
The first line of the input is the number of cases (a positive integer, n, on one line).
This is followed by n odd integers greater than 1, each on a line of its own.
Output
The output should consist of:
m = x^2 - y^2 = (x+y)*(x-y)
(with the actual values for m, x, and y).
Example
Input:
2
15
9929
Output:
15 = 4^2 - 1^2 = 5*3
9929 = 4965^2 - 4964^2 = 9929*1 | 35,240 |
Timing Morse (TIMORSE)
The International Morse Code specifies that the duration of a dash is three times that of a dot; the duration of the interval between the dots and dashes in a single character is the same as the duration of a dot; the duration of the interval between characters in a word is three times the duration of a dot; and the duration of the interval between words is seven times the duration of a dot.
The Morse Code length of a message is the duration of the message as transmitted in Morse code, expressed as a multiple of the duration of a dot.
For example, the Morse Code length of the message "hi" (···· ··) is 7 + 3 + 3 = 13.Â
The Morse Code length of the message "joe" (·âââ âââ ·) is 13 + 3 + 11 + 3 + 1 = 31, and the Morse Code length of the message "hi joe" is 13 + 7 + 31 = 51.
Write a program to calculate the Morse Code length of messages.
For ease of reference, the Morse code you will need (the alphabet) is:
a
·â
j
·âââ
s
···
b
â···
k
â·â
t
â
c
â·â·
l
·â··
u
··â
d
â··
m
ââ
v
···â
e
·
n
â·
w
·ââ
f
··â·
o
âââ
x
â··â
g
ââ·
p
·ââ·
y
â·ââ
h
····
q
ââ·â
z
ââ··
i
··
r
·â·
Input
The input to the program should consist of a positive integer, n, on one line, followed by n messages, each on a line of its own. Each message can consist of the letters "a" to "z" plus the space character (any other characters can be ignored).
Output
The output should consist of the n messages each followed by ": length = L", where L is the Morse Code length of the message.
Example
Input:
2
hi joe
sos
Output:
hi joe: length = 51
sos: length = 27 | 35,241 |
Ascii Art Darkness Calculator (AARTDARK)
In simple ASCII images a dark pixel is represented as an asterisk * and a bright pixel as a full stop .
The darkness of an ASCII art image is defined as (number of * characters) / (number of characters in total).
Input
The first line of input contains the number of images. Subsequent lines of input contain either an integer defining the size of an "image", or image data.
All images are square, and the size of the image is the length of a side.
Output
For each input image, output the darkness of that image, one per line.
Example
Input:
2
2
..
.*
8
........
........
..*..*..
........
.*....*.
..****..
........
........
Output:
0.25
0.125 | 35,242 |
Cinema seating, covid 19 version (CINECOVI)
This challenge involves writing a simple cinema seat booking system. Cinemas are opening up post lockdown, but they have to seat customers differently. No longer is it OK to try and fill all seats, or allow customers to choose their own. Â
Each group who book through the booking office need to sit together, and there needs to be an empty seat between groups on all sides (left, right, infront and behind). The seats in the cinema are filled from the bottom left, in order of booking. If a row fills up, we start filling on the left hand side of the next row back.
(For the purposes of illustration, imagine that the screen is at the base of the grid and that we fill the front row first).
So, if we have a cinema with just three rows, with 10 seats per row, and the following group sizes in our booking
5 4 3 2 1
we will be able to seat the first group of 5 at bottom left, then the group of 4 next to them after a gap of one seat. We'll leave a row behind, then the back row will fit the 3, 2 and 1. The seats would look like this:
Seats:
1110110100
0000000000
1111101111
If there were more bookings and instead we had the group sizes
5 4 3 2 1 1 2 3 4 5
we would have to turn away some groups. In this case, the seats would look like this:
Seats:
1110110101
0000000000
1111101111
Failed to seat:
2
3
4
5
Input
The first line of your input contains two integers, which specify the size of the cinema in terms of number of rows and number of seats per row.
Output
Your output should be the word "Seats:" on a line of its own, followed by an array of 1s and 0s represented the seats in the cinema (1=full, 0=empty). If you find that there are groups who cannot be seated in the cinema because it is too full, output the phrase "Failed to seat:" on the next line, followed by the sizes of the unseated groups in order, one per line.
Example
Input:
5 20
7 9 8 7 6 5 4 3 2 1 9 2 11 4 8
Output:
Seats:
11111101111101111000
00000000000000000000
11111111011111110000
00000000000000000000
11111110111111111000
Failed to seat:
3
2
1
9
2
11
4
8 | 35,243 |
Tiebreaker (TIEBRKR)
Are you the winner? Let's find out in this tiebreaker.
Given a list of ticket numbers and the status of WIN or NOWIN, identify the winning tickets and output them in order from lowest to highest.
Input
An integer t, 1 <= t <= 100, denoting the number of tickets to check.
For each ticket, there are two lines with information. The first line is an integer n, which is the ticket number. The second line is s, the status of the ticket number. The ticket status is either WIN or NOWIN.
Output
One line that lists the number of winning tickets.
One line that lists the ticket numbers, sorted from highest to lowest. Each number is separated by a space.
Example
Input:
5
5011
WIN
4000
NOWIN
101
WIN
500
NOWIN
501
WIN
Output:
3
101 501 5011 | 35,244 |
Fun With Fibonacci (DCP)
TheÂ
Fibonacci sequence
 is a set of numbers that starts with aÂ
zero
, followed by a one, and proceeds based on the rule that, each number (
called a Fibonacci number
) is equal to the sum of the previous two numbers. If the Fibonacci sequence is denotedÂ
F(n)
, whereÂ
n
 is the term in the sequence,
Now your task is to find the total number of odd Fibonacci numbers and total number of even Fibonacci numbers between a range (
consider 0 as an even number
).
Input
First Line of the input containsÂ
T,
 representing the number of test caseÂ
(1 <= T <= 50)
. For each test case contains two integers
N
and
M
where
(1 <= N <= 10
18
)
and
(1 <= M <= 10
18
)
.
Output
You have to calculate total number of
odd
 Fibonacci numbers and total number of
even
 Fibonacci numbers between
N
th
 Fibonacci number and
M
th
 Fibonacci number.
For each test case print case number with the desire answer as show sample output.
Example
Input:
2
2 6
1 5
Output:
Case 1:
Odd = 4
Even = 1
Case 2:
Odd = 3
Even = 2 | 35,245 |
Pavement Blood (PAVEMENT)
You live in a dangerous neighbourhood. Each night you walk home, the path home consists of a N by 3 tiled path (N rows).
Recently there have been many murders, and the tiles have been stained with blood.
Your feet are large, each step you take on the path home will cover a 2 by 2 grid of tiles, gathering some of the blood that has been left on the tiles onto your boots.
To make things simpler, you have marked each tile with a number representing the amount of blood on the tile, the i-th row and j-th column having value a[i][j]. Each step will add an amount of blood onto your boots (equal to the sum of the 2Ã2 grid of the tiles you step on). Moreover, some tiles may have soap on them and such, which previous murderers have dropped whilst trying to clean up after themselves, these will have negative numbers representing how much they clean your boots. Once you step on a tile, to get home as quick as possible, you cannot step on the same tile again.
You are smart, you know that the more blood you gather onto your boots, the less likely people are to attack you. You wish to gather as much blood as possible onto your boots by the end of your journey across the pavement. Your legs are long and you can skip over as many tiles as you wish on your way home.
Given the values of all the tiles, determine the maximum amount of blood you can get on your boots.
NOTE: Should you take a step, it must cover a 2Ã2 grid of tiles, you can't have half a foot out of the path or otherwise.
Input
The first line contains a single integer n, the length of the path home.
The next N lines contain 3 integers each, representing the values of tiles that lead home.
1 <= N <= 100,000
-1,000,000,000 <= a[i][j] <= 1,000,000,000
Output
A single integer representing the maximum amount of you can pick up on your boots.
Example
Input:
7
7 1 11
6 3 9
-4 -2 8
-8 -10 17
5 4 -3
-1 2 0
3 9 -3
Output:
50 | 35,246 |
Pan-da (PANANDDA)
You are given a string, which only consists of the letters P, A, N and D. In one operation, you can insert a letter somewhere into the string.
Determine the minimum number of insertions/operations so that if you cut the string into pieces, there is a possible cut so that all the pieces are either "DA" or "PAN".
Input
Your first and only line will contain the string (of length N, 1 <= N <= 1e5).
Output
Output a single integer representing the minimum number of insertions needed to be able to cut the string into substrings of only PAN and DA.
Example
Input 1:
PANDA
Output 1:
0
Input 2:
DPANA
Output 2:
2 | 35,247 |
Score : 1100 points Problem Statement Let f(A, B) , where A and B are positive integers, be the string satisfying the following conditions: f(A, B) has length A + B ; f(A, B) contains exactly A letters A and exactly B letters B ; The length of the longest substring of f(A, B) consisting of equal letters (ex., AAAAA or BBBB ) is as small as possible under the conditions above; f(A, B) is the lexicographically smallest string satisfying the conditions above. For example, f(2, 3) = BABAB , and f(6, 4) = AABAABAABB . Answer Q queries: find the substring of f(A_i, B_i) from position C_i to position D_i (1-based). Constraints 1 \leq Q \leq 10^3 1 \leq A_i, B_i \leq 5 \times 10^8 1 \leq C_i \leq D_i \leq A_i + B_i D_i - C_i + 1 \leq 100 All input values are integers. Partial Score 500 points will be awarded for passing the testset satisfying 1 \leq A_i, B_i \leq 10^3 . Input Input is given from Standard Input in the following format: Q A_1 B_1 C_1 D_1 A_2 B_2 C_2 D_2 : A_Q B_Q C_Q D_Q Output For each query i in order of input, print a line containing the substring of f(A_i, B_i) from position C_i to position D_i (1-based). Sample Input 1 5 2 3 1 5 6 4 1 10 2 3 4 4 6 4 3 7 8 10 5 8 Sample Output 1 BABAB AABAABAABB A BAABA ABAB | 35,248 |
Score : 200 points Problem Statement The development of algae in a pond is as follows. Let the total weight of the algae at the beginning of the year i be x_i gram. For iâ¥2000 , the following formula holds: x_{i+1} = rx_i - D You are given r , D and x_{2000} . Calculate x_{2001} , ... , x_{2010} and print them in order. Constraints 2 †r †5 1 †D †100 D < x_{2000} †200 All values in input are integers. Input Input is given from Standard Input in the following format: r D x_{2000} Output Print 10 lines. The i -th line ( 1 †i †10 ) should contain x_{2000+i} as an integer. Sample Input 1 2 10 20 Sample Output 1 30 50 90 170 330 650 1290 2570 5130 10250 For example, x_{2001} = rx_{2000} - D = 2 \times 20 - 10 = 30 and x_{2002} = rx_{2001} - D = 2 \times 30 - 10 = 50 . Sample Input 2 4 40 60 Sample Output 2 200 760 3000 11960 47800 191160 764600 3058360 12233400 48933560 | 35,249 |
Quick Sort Let's arrange a deck of cards. Your task is to sort totally n cards. A card consists of a part of a suit (S, H, C or D) and an number. Write a program which sorts such cards based on the following pseudocode: Partition(A, p, r) 1 x = A[r] 2 i = p-1 3 for j = p to r-1 4 do if A[j] <= x 5 then i = i+1 6 exchange A[i] and A[j] 7 exchange A[i+1] and A[r] 8 return i+1 Quicksort(A, p, r) 1 if p < r 2 then q = Partition(A, p, r) 3 run Quicksort(A, p, q-1) 4 run Quicksort(A, q+1, r) Here, A is an array which represents a deck of cards and comparison operations are performed based on the numbers. Your program should also report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance). Input The first line contains an integer n , the number of cards. n cards are given in the following lines. Each card is given in a line and represented by a pair of a character and an integer separated by a single space. Output In the first line, print the stability (" Stable " or " Not stable ") of this output. In the following lines, print the arranged cards in the same manner of that of the input. Constraints 1 †n †100,000 1 †the number of a card †10 9 There are no identical card in the input Sample Input 1 6 D 3 H 2 D 1 S 3 D 2 C 1 Sample Output 1 Not stable D 1 C 1 D 2 H 2 D 3 S 3 Sample Input 2 2 S 1 H 1 Sample Output 2 Stable S 1 H 1 | 35,250 |
Max Score: $1400$ Points Problem Statement E869120 defined a sequence $a$ like this: $a_1=a_2=1$, $a_{k+2}=a_{k+1}+a_k \ (k \ge 1)$ He also defined sequences $d_1, d_2, d_3, \dots , d_n$, as the following recurrence relation : $d_{1, j} = a_j$ $d_{i, j} = \sum_{k = 1}^j d_{i - 1, k} \ (i \ge 2)$ You are given integers $n$ and $m$. Please calculate the value of $d_{n, m}$. Since the answer can be large number, print the answer modulo $998,244,353$. Can you solve this problem??? Input The input is given from standard input in the following format. $n \quad m$ Output Print $d_{n, m}$ modulo $998,244,353$. Constraints $1 \le n \le 200,000$ $1 \le m \le 10^{18}$ Subtasks Subtask 1 [ $100$ points ] The testcase in this subtask satisfies $1 \le n, m \le 3,000$. Subtask 2 [ $170$ points ] The testcase in this subtask satisfies $1 \le m \le 200,000$. Subtask 3 [ $230$ points ] The testcase in this subtask satisfies $1 \le n \le 3$. Subtask 4 [ $420$ points ] The testcase in this subtask satisfies $1 \le n \le 1000$. Subtask 5 [ $480$ points ] There are no additional constraints. Sample Input 1 4 7 Sample Output 1 176 The sequence is following: $d_{i, 1}$ $d_{i, 2}$ $d_{i, 3}$ $d_{i, 4}$ $d_{i, 5}$ $d_{i, 6}$ $d_{i, 7}$ $d_1$ 1 1 2 3 5 8 13 $d_2$ 1 2 4 7 12 20 33 $d_3$ 1 3 7 14 26 46 79 $d_4$ 1 4 11 25 51 97 176 As a result, the answer is $d_{4, 7} = 176$. Sample Input 2 12 20 Sample Output 2 174174144 Interesting number. It only contains $1$, $4$ and $7$. Sample Input 3 16 30 Sample Output 3 102292850 You can calculate that $d_{16, 30} = 1,193,004,294,685$. Please don't forget printing the answer mod $998,244,353$. WriterïŒsquare1001 | 35,251 |
D: ãã¹ã¯ãŒã åé¡ AOR ã€ã«ã¡ããã¯è±å°æåã®ã¿ãããªã匷åãªãã¹ã¯ãŒããäœããããšæã£ãŠããŸãã åéãã $N$ åã®å±éºãªãã¹ã¯ãŒãã®äŸãæããŠããã£ã AOR ã€ã«ã¡ããã¯ã 以äžã®æ¡ä»¶ãå
šãŠæºãããããªãã¹ã¯ãŒããäœãããšã«ããŸããã é·ãã¯1æå以äžã§ããã ã©ã®å±éºãªãã¹ã¯ãŒãã®ãã©ã®é£ç¶ããéšåæååãšãç°ãªãã 1, 2 ã®æ¡ä»¶ãæºãããäžã§ãæãçãæååã§ããã 1,2,3ã®æ¡ä»¶ãæºãããäžã§ãèŸæžé ã«äžŠã¹ããšãå
é ã«æ¥ãæååã§ããã AOR ã€ã«ã¡ããã«ä»£ãã£ãŠåŒ·åãªãã¹ã¯ãŒããçæããããã°ã©ã ãæžããŠãã ããã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã $N$ $S_1$ $\vdots$ $S_N$ 1 è¡ç®ã«ã¯ãæååã®æ°ãè¡šãæŽæ° $N$ ãäžããããã 2 è¡ç®ããã® $N$ è¡ã«ã¯ãæåå $S_i$ ãäžããããã $|S_i|$ ãšã¯æååã®é·ãã§ããã1 æå以äžã§ããã $1 \le N \le 100,000$ ãæºããã $1 \le \sum_{1\le i \le N} |S_i| \le 400,000$ ãæºããã æååã¯è±å°æåã®ã¿ãå«ãã åºå çãã 1 è¡ã§åºåããããŸããæ«å°Ÿã«æ¹è¡ãåºåããã ãµã³ãã« ãµã³ãã«å
¥å 1 5 password login admin root master ãµã³ãã«åºå 1 b ãµã³ãã«å
¥å 2 3 abcdefghijklmnopqrstuvwxy qwertyuiopasdfghjklxcvbnm qawsxedcrfvtgbyhnujmikolp ãµã³ãã«åºå 2 z ãµã³ãã«å
¥å 3 1 abcdefghijklmnopqrstuvwxyz ãµã³ãã«åºå 3 aa | 35,252 |
Score : 100 points Problem Statement An uppercase or lowercase English letter \alpha will be given as input. If \alpha is uppercase, print A ; if it is lowercase, print a . Constraints \alpha is an uppercase ( A - Z ) or lowercase ( a - z ) English letter. Input Input is given from Standard Input in the following format: α Output If \alpha is uppercase, print A ; if it is lowercase, print a . Sample Input 1 B Sample Output 1 A B is uppercase, so we should print A . Sample Input 2 a Sample Output 2 a a is lowercase, so we should print a . | 35,253 |
Balls and Boxes 2 Balls Boxes Any way At most one ball At least one ball Distinguishable Distinguishable 1 2 3 Indistinguishable Distinguishable 4 5 6 Distinguishable Indistinguishable 7 8 9 Indistinguishable Indistinguishable 10 11 12 Problem You have $n$ balls and $k$ boxes. You want to put these balls into the boxes. Find the number of ways to put the balls under the following conditions: Each ball is distinguished from the other. Each box is distinguished from the other. Each ball can go into only one box and no one remains outside of the boxes. Each box can contain at most one ball. Note that you must print this count modulo $10^9+7$. Input $n$ $k$ The first line will contain two integers $n$ and $k$. Output Print the number of ways modulo $10^9+7$ in a line. Constraints $1 \le n \le 1000$ $1 \le k \le 1000$ Sample Input 1 2 3 Sample Output 1 6 Sample Input 2 3 2 Sample Output 2 0 Sample Input 3 100 100 Sample Output 3 437918130 | 35,254 |
Is-Convex For a given polygon g , print "1" if g is a convex polygon, "0" otherwise. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees. g is represented by a sequence of points p 1 , p 2 ,..., p n where line segments connecting p i and p i+1 (1 †i †n-1 ) are sides of the polygon. The line segment connecting p n and p 1 is also a side of the polygon. Input g is given by coordinates of the points p 1 ,..., p n in the following format: n x 1 y 1 x 2 y 2 : x n y n The first integer n is the number of points. The coordinate of a point p i is given by two integers x i and y i . The coordinates of points are given in the order of counter-clockwise visit of them. Output Print "1" or "0" in a line. Constraints 3 †n †100 -10000 †x i , y i †10000 No point of the polygon will occur more than once. Two sides of the polygon can intersect only at a common endpoint. Sample Input 1 4 0 0 3 1 2 3 0 3 Sample Output 1 1 Sample Input 2 5 0 0 2 0 1 1 2 2 0 2 Sample Output 2 0 | 35,255 |
Score : 500 points Problem Statement A cheetah and a cheater are going to play the game of Nim. In this game they use N piles of stones. Initially the i -th pile contains a_i stones. The players take turns alternately, and the cheetah plays first. In each turn, the player chooses one of the piles, and takes one or more stones from the pile. The player who can't make a move loses. However, before the game starts, the cheater wants to cheat a bit to make sure that he can win regardless of the moves by the cheetah. From each pile, the cheater takes zero or one stone and eats it before the game. In case there are multiple ways to guarantee his winning, he wants to minimize the number of stones he eats. Compute the number of stones the cheater will eat. In case there is no way for the cheater to win the game even with the cheating, print -1 instead. Constraints 1 †N †10^5 2 †a_i †10^9 Input The input is given from Standard Input in the following format: N a_1 : a_N Output Print the answer. Sample Input 1 3 2 3 4 Sample Output 1 3 The only way for the cheater to win the game is to take stones from all piles and eat them. Sample Input 2 3 100 100 100 Sample Output 2 -1 | 35,256 |
Score : 400 points Problem Statement An SNS has N users - User 1 , User 2 , \cdots , User N . Between these N users, there are some relationships - M friendships and K blockships . For each i = 1, 2, \cdots, M , there is a bidirectional friendship between User A_i and User B_i . For each i = 1, 2, \cdots, K , there is a bidirectional blockship between User C_i and User D_i . We define User a to be a friend candidate for User b when all of the following four conditions are satisfied: a \neq b . There is not a friendship between User a and User b . There is not a blockship between User a and User b . There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a , c_L = b , and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1 . For each user i = 1, 2, ... N , how many friend candidates does it have? Constraints All values in input are integers. 2 †N †10^5 0 \leq M \leq 10^5 0 \leq K \leq 10^5 1 \leq A_i, B_i \leq N A_i \neq B_i 1 \leq C_i, D_i \leq N C_i \neq D_i (A_i, B_i) \neq (A_j, B_j) (i \neq j) (A_i, B_i) \neq (B_j, A_j) (C_i, D_i) \neq (C_j, D_j) (i \neq j) (C_i, D_i) \neq (D_j, C_j) (A_i, B_i) \neq (C_j, D_j) (A_i, B_i) \neq (D_j, C_j) Input Input is given from Standard Input in the following format: N M K A_1 B_1 \vdots A_M B_M C_1 D_1 \vdots C_K D_K Output Print the answers in order, with space in between. Sample Input 1 4 4 1 2 1 1 3 3 2 3 4 4 1 Sample Output 1 0 1 0 1 There is a friendship between User 2 and 3 , and between 3 and 4 . Also, there is no friendship or blockship between User 2 and 4 . Thus, User 4 is a friend candidate for User 2 . However, neither User 1 or 3 is a friend candidate for User 2 , so User 2 has one friend candidate. Sample Input 2 5 10 0 1 2 1 3 1 4 1 5 3 2 2 4 2 5 4 3 5 3 4 5 Sample Output 2 0 0 0 0 0 Everyone is a friend of everyone else and has no friend candidate. Sample Input 3 10 9 3 10 1 6 7 8 2 2 5 8 4 7 3 10 9 6 4 5 8 2 6 7 5 3 1 Sample Output 3 1 3 5 4 3 3 3 3 1 0 | 35,257 |
Score : 300 points Problem Statement You are given a string S . Takahashi can insert the character A at any position in this string any number of times. Can he change S into AKIHABARA ? Constraints 1 \leq |S| \leq 50 S consists of uppercase English letters. Input Input is given from Standard Input in the following format: S Output If it is possible to change S into AKIHABARA , print YES ; otherwise, print NO . Sample Input 1 KIHBR Sample Output 1 YES Insert one A at each of the four positions: the beginning, immediately after H , immediately after B and the end. Sample Input 2 AKIBAHARA Sample Output 2 NO The correct spell is AKIHABARA . Sample Input 3 AAKIAHBAARA Sample Output 3 NO | 35,258 |
Score : 300 points Problem Statement You are given a sequence of positive integers of length N , a = (a_1, a_2, ..., a_N) . Your objective is to remove some of the elements in a so that a will be a good sequence . Here, an sequence b is a good sequence when the following condition holds true: For each element x in b , the value x occurs exactly x times in b . For example, (3, 3, 3) , (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not. Find the minimum number of elements that needs to be removed so that a will be a good sequence. Constraints 1 \leq N \leq 10^5 a_i is an integer. 1 \leq a_i \leq 10^9 Input Input is given from Standard Input in the following format: N a_1 a_2 ... a_N Output Print the minimum number of elements that needs to be removed so that a will be a good sequence. Sample Input 1 4 3 3 3 3 Sample Output 1 1 We can, for example, remove one occurrence of 3 . Then, (3, 3, 3) is a good sequence. Sample Input 2 5 2 4 1 4 2 Sample Output 2 2 We can, for example, remove two occurrences of 4 . Then, (2, 1, 2) is a good sequence. Sample Input 3 6 1 2 2 3 3 3 Sample Output 3 0 Sample Input 4 1 1000000000 Sample Output 4 1 Remove one occurrence of 10^9 . Then, () is a good sequence. Sample Input 5 8 2 7 1 8 2 8 1 8 Sample Output 5 5 | 35,259 |
Score : 100 points Problem Statement There are N slimes lining up in a row. Initially, the i -th slime from the left has a size of a_i . Taro is trying to combine all the slimes into a larger slime. He will perform the following operation repeatedly until there is only one slime: Choose two adjacent slimes, and combine them into a new slime. The new slime has a size of x + y , where x and y are the sizes of the slimes before combining them. Here, a cost of x + y is incurred. The positional relationship of the slimes does not change while combining slimes. Find the minimum possible total cost incurred. Constraints All values in input are integers. 2 \leq N \leq 400 1 \leq a_i \leq 10^9 Input Input is given from Standard Input in the following format: N a_1 a_2 \ldots a_N Output Print the minimum possible total cost incurred. Sample Input 1 4 10 20 30 40 Sample Output 1 190 Taro should do as follows (slimes being combined are shown in bold): ( 10 , 20 , 30, 40) â ( 30 , 30, 40) ( 30 , 30 , 40) â ( 60 , 40) ( 60 , 40 ) â ( 100 ) Sample Input 2 5 10 10 10 10 10 Sample Output 2 120 Taro should do, for example, as follows: ( 10 , 10 , 10, 10, 10) â ( 20 , 10, 10, 10) (20, 10 , 10 , 10) â (20, 20 , 10) (20, 20 , 10 ) â (20, 30 ) ( 20 , 30 ) â ( 50 ) Sample Input 3 3 1000000000 1000000000 1000000000 Sample Output 3 5000000000 The answer may not fit into a 32-bit integer type. Sample Input 4 6 7 6 8 6 1 1 Sample Output 4 68 Taro should do, for example, as follows: (7, 6, 8, 6, 1 , 1 ) â (7, 6, 8, 6, 2 ) (7, 6, 8, 6 , 2 ) â (7, 6, 8, 8 ) ( 7 , 6 , 8, 8) â ( 13 , 8, 8) (13, 8 , 8 ) â (13, 16 ) ( 13 , 16 ) â ( 29 ) | 35,260 |
ãã³ãžã§ã³ åé¡ ããªãã¯ãããã³ãžã§ã³ã®å°äž N éã«ãã財å®ãæã«å
¥ããããšæã£ãŠãã.æå,ããªãã¯å°äž 1 éã«ãã,ããªãã®äœå㯠H(H ã¯æ£æŽæ°) ã§ãã.äžã®éã«éãããšãã«,äœåãæ¶è²»ããã.ãããããåéã«ãããäžã®éã«éãããšãã«æ¶è²»ãããäœåãåãã£ãŠãã.äžæ¹,åéã«ã¯ 1 ã€ã®ååŸ©ã®æ³ããã,æ³ã 1 å䜿ãããšã«å埩ã§ããäœåãããããå®ãŸã£ãŠãã.äœåã 0 以äžã«ãªããšããªãã¯æ»ãã§ããŸã.ãŸã,äœåã H ãããé«ããªãããšã¯ãªã.ååŸ©ã®æ³ã¯äœåã§ã䜿ãããšãã§ããã,å埩ã«ã¯æéããããã®ã§,ããªãã¯æ³ã®äœ¿çšåæ°ãã§ããã ãå°ãªãããããšèããŠãã. N ,H ,åéã®äžã®éã«éãããšãã«æ¶è²»ãããäœå,ãããŠåéã§ååŸ©ã®æ³ã 1 å䜿çšãããšãã«å埩ããäœåãäžãããããšã,äœåã 0 以äžã«ããããšãªãå°äž N éãŸã§å°éããããã«å¿
èŠãªæ³ã®äœ¿çšåæ°ã®æå°å€ãæ±ããããã°ã©ã ãäœæãã. ãŸã,äžåºŠäžã®éã«éãããš,財å®ãæã«å
¥ãããŸã§äžã®éã«æ»ãããšã¯ã§ããªã. å
¥å å
¥å㯠N è¡ãããªã. å
¥åã® 1 è¡ç®ã«ã¯ 2 ã€ã®æŽæ° N, H(2 †N †100000 = 10 5 , 1 †H †10000000 = 10 7 ) ã空çœãåºåããšããŠæžãããŠãã.N ã¯å°äž N éã«è²¡å®ããããšããããšã衚ã,H ã¯åæäœå ( ãã³ãžã§ã³ã®å°äž 1 éã«å°çããæ®µéã®äœå ) ã§ãã,ãã€äœåã®æå€§å€ã§ãã ( å埩ã«ãã£ãŠäœåã H ãã倧ãããªãããšã¯ãªã ) . ç¶ã N â 1 è¡ã«ã¯,2 ã€ã®æŽæ°ã空çœãåºåããšããŠæžãããŠãã.1 + i è¡ç®(1 †i †N â 1) ã®æŽæ° di , hi ã«ã€ããŠ, di ã¯å°äž i éããå°äž i + 1 éã«éããéã«æ¶è²»ãããäœåã,hi ã¯å°äž i éã§æ³ã 1 å䜿çšãããšãã«å埩ããäœåã衚ã(0 †di < H, 1 †hi < H). ã©ã®æ¡ç¹çšããŒã¿ã«ãããŠã,å°äž N éã«ãã©ãçãæ¹æ³ãååšãã.æ¡ç¹çšããŒã¿ã®ãã¡,é
ç¹ã® 10%åã«ã€ããŠã¯,N †1000 ã〠H †1000 ãæºãã.é
ç¹ã®30%åã«ã€ããŠã¯,N â€1000 ãæºãã.é
ç¹ã® 50%åã«ã€ããŠã¯,æ³ã®äœ¿çšåæ°ã®æå°å€ã 10 6 ãè¶
ããªã. åºå åºåã¯,äœåã 0 以äžã«ããããšãªãå°äž N éã«å°éããããã«å¿
èŠãª,æ³ã®äœ¿çšåæ°ã®æå°å€ãå«ã 1 è¡ãããªã. 泚æ ãã®åé¡ã§ã¯,æ±ãæŽæ°ã®ç¯å²ã 32bit ã«åãŸããªãå¯èœæ§ãããããšã«æ³šæãã. å
¥åºåäŸ å
¥åäŸ 1 10 10 4 2 2 5 6 1 7 3 6 4 9 6 0 8 4 1 9 4 åºåäŸ 1 10 äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 35,261 |
Dropping Ink As shown in the following figure, there is a paper consisting of a grid structure where each cell is indicated by ( x , y ) coordinate system. We are going to put drops of ink on the paper. A drop comes in three different sizes: Large, Medium, and Small. From the point of fall, the ink sinks into surrounding cells as shown in the figure depending on its size. In the figure, a star denotes the point of fall and a circle denotes the surrounding cells. Originally, the paper is white that means for each cell the value of density is 0. The value of density is increased by 1 when the ink sinks into the corresponding cells. For example, if we put a drop of Small ink at (1, 2) and a drop of Medium ink at (3, 2), the ink will sink as shown in the following figure (left side): In the figure, density values of empty cells are 0. The ink sinking into out of the paper should be ignored as shown in the figure (top side). We can put several drops of ink at the same point. Your task is to write a program which reads a sequence of points of fall ( x , y ) with its size (Small = 1, Medium = 2, Large = 3), and prints the number of cells whose density value is 0. The program must also print the maximum value of density. You may assume that the paper always consists of 10 à 10, and 0 †x < 10, 0 †y < 10. Input x 1 , y 1 , s 1 x 2 , y 2 , s 2 : : ( x i , y i ) represents the position of the i -th drop and s i denotes its size. The number of drops is less than or equal to 50. Output Print the number of cells whose density value is 0 in first line. Print the maximum value of density in the second line. Sample Input 2,5,3 3,6,1 3,4,2 4,5,2 3,6,3 2,4,1 Output for the Sample Input 77 5 | 35,262 |
Problem A: Luck Manipulator Nathan O. Davis ããã¯ïŒããã²ãŒã ãæ»ç¥äžã§ããïŒéåžžã«ã¬ã¢ãªã¢ã€ãã ãæã«å
¥ããããšåèŠå
«èŠããŠããïŒãã®ã¬ã¢ãªã¢ã€ãã ã¯ïŒã«ãžãã®ã¹ããããã·ãŒã³ã§ç¹æ®ãªçµµæãäžåã«æãããšãã«æã«å
¥ããããšãã§ããïŒã¹ããããã·ãŒã³ã«ã¯ N åã®ãªãŒã«ãããïŒãã¿ã³ãäžåæŒããšçŸåšå転ããŠããæãå·ŠåŽã®ãªãŒã«ã忢ããïŒãã®ããïŒãã®ã¬ã¢ã¢ã€ãã ãæã«å
¥ããããã«ã¯ N åãã¿ã³ãæŒãå¿
èŠãããïŒãŸãïŒç¹æ®ãªçµµæã§åæ¢ãããããã«ã¯ããã¿ã€ãã³ã°ã§ãã¿ã³ãæŒãå¿
èŠãããïŒãšãããïŒãã®ãã¿ã³ãæŒãã¿ã€ãã³ã°ã¯éåžžã«ã·ãã¢ã§ããããïŒãªããªãäžæããããã«å°ã£ãŠããïŒããã§ïŒNathan ããã¯ã¡ã¢ãªãã¥ãŒã¢ãå©çšããŠïŒã²ãŒã äžã«ãããã¡ã¢ãªã®å€ã確èªããªããã²ãŒã ãè§£æããããšã«ããïŒ Nathan ããã®è§£æã®çµæïŒãã®ç¹æ®ãªçµµæã§ãªãŒã«ã忢ãããããã«ã¯ïŒãã¿ã³ãæŒãããæã«ïŒã¡ã¢ãªã® 007E0D1F çªå°ã«æžã蟌ãŸãããä¹±æ°ããç¹å®ã®å€ã«ãªã£ãŠããå¿
èŠãããããšãçªãæ¢ããïŒä¹±æ°ã®å€ã¯ 1 ãã¬ãŒã æ¯ã«ç·åœ¢ååæ³ã«ãã£ãŠå€åããŠããïŒãŸããã¿ã³ãæŒããããã©ããã®å€å®ã¯ 1 ãã¬ãŒã æ¯ã« 1 åè¡ãããŠããããšãåãã£ãïŒããã§ïŒç·åœ¢ååæ³ãšã¯æ¬äŒŒä¹±æ°ãçæããããã®æ¹æ³ã®äžã€ã§ããïŒä»¥äžã®åŒã«ãã£ãŠå€ã決å®ããïŒ x' = ( A à x + B ) mod C ããã§ïŒ x ã¯çŸåšã®ä¹±æ°ã®å€ïŒ x' ã¯æ¬¡ã®ä¹±æ°ã®å€ïŒ A , B , C ã¯äœããã®å®æ°ã§ããïŒãŸãïŒ y mod z 㯠y ã z ã§å²ã£ããšãã®äœãã衚ãïŒ äŸãã°ïŒ2 åã®ãªãŒã«ãæã€ã¹ããããã·ãŒã³ã§ A = 5ïŒ B = 7ïŒ C = 11 ã§ïŒæåã®ãä¹±æ°ãã®å€ã 10 ã§ãã£ããšããïŒãããŠïŒç¹æ®ãªçµµæã§ãªãŒã«ãæ¢ããããã®æ¡ä»¶ã¯ïŒå·ŠåŽã®ãªãŒã«ã 2ïŒå³åŽã®ãªãŒã«ã 4 ã§ãã£ããšããïŒãã®ãšãïŒ1 ãã¬ãŒã ç®ã«ãããä¹±æ°ã®å€ã¯ (5 à 10 + 7) mod 11 = 2 ã§ããããïŒ1 ãã¬ãŒã ç®ã«ãã¿ã³ãæŒãã°å·ŠåŽã®ãªãŒã«ã¯ç¹æ®ãªçµµæã§åæ¢ããïŒç¶ã 2 ãã¬ãŒã ç®ã§ã®ä¹±æ°ã®å€ã¯ (5 à 2 + 7) mod 11 = 6 ã§ããããïŒ2 ãã¬ãŒã ç®ã«ãã¿ã³ãæŒããŠãå³åŽã®ãªãŒã«ã¯ç¹æ®ãªçµµæã§ã¯åæ¢ããªãïŒç¶ã 3 ãã¬ãŒã ç®ã§ã¯ä¹±æ°ã®å€ã (5 à 6 + 7 ) mod 11 = 4 ã«ãªãã®ã§ïŒ3 ãã¬ãŒã ç®ã«ãã¿ã³ãæŒãã°å³åŽã®ãªãŒã«ã¯ç¹æ®ãªçµµæã§åæ¢ããïŒãã£ãŠïŒæç 3 ãã¬ãŒã ã§å
šãŠã®ãªãŒã«ãç¹æ®ãªçµµæã§åæ¢ãããããšãã§ãïŒã¬ã¢ãªã¢ã€ãã ãæã«å
¥ããããšãã§ããïŒ ããªãã®ä»äºã¯ïŒæçã§äœãã¬ãŒã ç®ã«å
šãŠã®ãªãŒã«ãç¹æ®ãªçµµæã§åæ¢ãããããšãã§ããããæ±ããããã°ã©ã ãæžããŠïŒNathan ãããã¬ã¢ãªã¢ã€ãã ãæã«å
¥ããããããå©ããŠãããããšã§ããïŒ Input å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯æ¬¡ã®åœ¢åŒã§äžããããïŒ N A B C X Y 1 Y 2 ... Y N æåã®è¡ã«ã¯ 5 ã€ã®æŽæ° N (1 †N †100) ïŒ A , B (0 †A , B †10,000)ïŒ C (1 †C †10,000) ïŒ X (0 †X < C ) ããããã 1 ã€ã®ç©ºçœæåã§åºåãããŠäžããããïŒããã§ïŒ X ã¯æåã®ä¹±æ°ã®å€ã衚ãïŒç¶ãè¡ã§ã¯ïŒ N åã®æŽæ° Y 1 , Y 2 , ... , Y N (0 †Y i †10,000) ã 1 ã€ã®ç©ºçœæåã§åºåãããŠäžããããïŒãããã¯ïŒãªãŒã«ãç¹å®ã®çµµæã§æ¢ããããã®æ¡ä»¶ã衚ããŠããïŒãã®ç¬¬ i çªç®ã®æ° Y i ã¯ïŒå·Šãã i çªç®ã®ãªãŒã«ãç¹æ®ãªçµµæã§åæ¢ããããã«ã¯ïŒä¹±æ°ã®å€ã Y i ã§ããå¿
èŠãããïŒããæå³ã§ããïŒ å
¥åã®çµããã¯ïŒç©ºçœã§åºåããã 5 ã€ã® 0 ãå«ã 1 è¡ã§ç€ºãããïŒ Output åããŒã¿ã»ããã«ã€ããŠïŒç¹æ®ãªçµµæã§åæ¢ãããããã«å¿
èŠãšãªãæçã®ãã¬ãŒã æ°ã 1 è¡ã«åºåããïŒãªãïŒ10,000 ãã¬ãŒã 以å
ã«åæ¢ãããããšãã§ããªãå Žåã¯ïŒãã¬ãŒã æ°ã®ä»£ããã« -1 ãåºåããïŒåºåã«äœèšãªç©ºçœãæ¹è¡ãå«ããŠã¯ãªããªãïŒ Sample Input 1 5 7 11 10 10 2 5 7 11 10 2 4 2 1 1 256 0 128 255 2 0 0 1 0 1234 5678 2 1 1 100 0 99 98 2 1 1 100 0 99 99 2 1 1 10000 0 1 0 2 1 1 10000 0 2 1 0 0 0 0 0 Output for the Sample Input 0 3 255 -1 198 199 10000 -1 | 35,263 |
Problem D: Change ICPC World Finals 2æ¥ç® ãã£ãŒæ°ãã¯ç©ºæž¯ã®ã¿ãŒããã«ã«ã€ããã ããããé£è¡æ©ãä¹ãç¶ãæµå°Råœã«ä¹ã蟌ãã®ã§ããã æã
ã¯Dåœãçµç±ãããããææã¡ã®ãéã2çš®é¡ã®é貚ã«äž¡æ¿ããã°ãªããªãã ã±ãŒæ°ããã£ãŒããã¯ã©ã®ããã«äž¡æ¿ããŸããïŒã ãã£ãŒæ°ãããããããããããããããããã ã±ãŒæ°ããªãã»ã©ãç§ã20,000åãDåœçšã«5,000åãRåœçšã«15,000åå²ãæ¯ãããšæããŸãã ãã£ãŒæ°ãããããããããããããããããã ã±ãŒæ°ãããïŒå€ã§ãããäž¡æ¿çµæãç§ãšéããŸããâŠãã åé¡ ããæ
è¡è
ã¯ãæ¥æ¬ãæ
ç«ã¡ãDåœïŒé貚åäœDïŒãRåœïŒé貚åäœRïŒã芳å
ããæ¥æ¬ã«åž°ã£ãŠããããšãèããŠããã ä»ã\( M \)åæã£ãŠããã \( c_{D} \)[D]ã\( c_{R} \)[R]ãååœã§æ¶è²»ããããšãåãã£ãŠããã®ã§ã ãéãäžè¶³ããªãããã«äž¡æ¿ãããã \( x \)åãDåœã®ãéã«äž¡æ¿ãããš\( \lfloor \frac{r_{D}x}{100} \rfloor \)[D]ã«ã \( x \)åãRåœã®ãéã«äž¡æ¿ãããš\( \lfloor \frac{r_{R}x}{100} \rfloor \)[R]ã«ãªãã äŸãã°ã \( r_{D}=11, c_{D}=10 \)ã®æã« 150åãDåœã®ãéã«äž¡æ¿ãããš\( \lfloor \frac{11 \times 150}{100} \rfloor = \)16[D]ã«ãªããããéã¯äžè¶³ããªãã ãããã50åããäž¡æ¿ããªããš5[D]ã«ãªã10[D]ã«æºããªããããéãäžè¶³ããã ãŸããåž°åœæã«ã¯ææã¡ã®ãéãå
šãŠæ¥æ¬åã«äž¡æ¿ããã \( x \)[D]ãæ¥æ¬åã«äž¡æ¿ãããš\( \lfloor \frac{100x}{r_{D}} \rfloor \)åã«ã \( x \)[R]ãæ¥æ¬åã«äž¡æ¿ãããš\( \lfloor \frac{100x}{r_{R}} \rfloor \)åã«ãªãã å
ã®1ã€ç®ã®äŸã§ã¯ã åŸããã16[D]ã®ãã¡10[D]ãæ¶è²»ãããã6[D]äœãã ãããæ¥æ¬åã«äž¡æ¿ãããš\( \lfloor \frac{100 \times 6}{11} \rfloor = 54\)åã«ãªãã åºåœæã«æ¥æ¬åã®æé©ãªäž¡æ¿ãè¡ã£ãæãåž°åœæã«æçµçã«æå
ã«æ»ã£ãŠããæ¥æ¬åã®æå€§é¡ãæ±ããã ãããªãäž¡æ¿ãè¡ãªã£ãŠããDåœãŸãã¯Råœã®ããããã§ãéãäžè¶³ããå Žåã«ã¯"-1"ãšåºåããã â»\( \lfloor x \rfloor \)ã¯ã\(x\)ãè¶
ããªãæå€§ã®æŽæ°ã衚ãã å
¥å M r D r R c D c R 1è¡ç®ã« çŸåšææã¡ã®æ¥æ¬åã®é¡\(M\)ã æ¥æ¬åãšDåœã®é貚åäœãšã®äž¡æ¿ã¬ãŒã\( r_{D} \)ã æ¥æ¬åãšRåœã®é貚åäœãšã®äž¡æ¿ã¬ãŒã\( r_{R} \)ã Dåœã§ã®ãéã®æ¶è²»é¡\( c_{D} \)ã Råœã§ã®ãéã®æ¶è²»é¡\( c_{R} \)ã空çœåºåãã§äžããããã åºå æå
ã«æ»ã£ãŠããæ¥æ¬åã®æå€§é¡ã1è¡ã«åºåããã ãããªãäž¡æ¿ãè¡ãªã£ãŠããDåœãŸãã¯Råœã®ããããã§ãéãäžè¶³ããå Žåã¯"-1"ãåºåããã å¶çŽ \( 0 \leq M \leq 10^{12}(= 1000000000000) \) \( 1 \leq r_{D}, r_{R} \leq 100 \) \( 0 \leq c_{D}, c_{R} \leq 10^{12}(= 1000000000000) \) å
¥åºåäŸ å
¥å1 20000 3 1 20 100 åºå1 9333 667åãDåœã®ãéã«ã10,000åãRåœã®ãéã«å€æããã°ããããã20[D]ã100[R]ãåŸãããã å
¥å2 1000000000000 3 1 20 100 åºå2 999999989333 ãã®æ
è¡è
ã¯å€§éæã¡ã§ããã å
¥å3 0 3 1 20 100 åºå3 -1 ãã®æ
è¡è
ã¯äžæç¡ãã§ãããã©ãã«ãè¡ããªãã | 35,264 |
Score : 400 points Problem Statement There are N people standing in a queue from west to east. Given is a string S of length N representing the directions of the people. The i -th person from the west is facing west if the i -th character of S is L , and east if that character of S is R . A person is happy if the person in front of him/her is facing the same direction. If no person is standing in front of a person, however, he/she is not happy. You can perform the following operation any number of times between 0 and K (inclusive): Operation: Choose integers l and r such that 1 \leq l \leq r \leq N , and rotate by 180 degrees the part of the queue: the l -th, (l+1) -th, ... , r -th persons. That is, for each i = 0, 1, ..., r-l , the (l + i) -th person from the west will stand the (r - i) -th from the west after the operation, facing east if he/she is facing west now, and vice versa. What is the maximum possible number of happy people you can have? Constraints N is an integer satisfying 1 \leq N \leq 10^5 . K is an integer satisfying 1 \leq K \leq 10^5 . |S| = N Each character of S is L or R . Input Input is given from Standard Input in the following format: N K S Output Print the maximum possible number of happy people after at most K operations. Sample Input 1 6 1 LRLRRL Sample Output 1 3 If we choose (l, r) = (2, 5) , we have LLLRLL , where the 2 -nd, 3 -rd, and 6 -th persons from the west are happy. Sample Input 2 13 3 LRRLRLRRLRLLR Sample Output 2 9 Sample Input 3 10 1 LLLLLRRRRR Sample Output 3 9 Sample Input 4 9 2 RRRLRLRLL Sample Output 4 7 | 35,265 |
Problem B: Miscalculation Bob is an elementary schoolboy, not so good at mathematics. He found Father's calculator and tried cheating on his homework using it. His homework was calculating given expressions containing multiplications and additions. Multiplications should be done prior to additions, of course, but the calculator evaluates the expression from left to right, neglecting the operator precedence. So his answers may be the result of either of the following two calculation rules. Doing multiplication before addition Doing calculation from left to right neglecting the operator precedence Write a program that tells which of the rules is applied from an expression and his answer. An expression consists of integers and operators. All the integers have only one digit, from 0 to 9. There are two kinds of operators + and * , which represent addition and multiplication, respectively. The following is an example expression. 1+2*3+4 Calculating this expression with the multiplication-first rule, the answer is 11, as in Sample Input 1. With the left-to-right rule, however, the answer will be 13 as shown in Sample Input 2. There may be cases in which both rules lead to the same result and you cannot tell which of the rules is applied. Moreover, Bob sometimes commits miscalculations. When neither rules would result in Bobâs answer, it is clear that he actually did. Input The input consists of a single test case specified with two lines. The first line contains the expression to be calculated. The number of characters of the expression is always odd and less than or equal to 17. Each of the odd-numbered characters in the expression is a digit from ' 0 ' to ' 9 '. Each of the even-numbered characters is an operator ' + ' or ' * '. The second line contains an integer which ranges from 0 to 999999999, inclusive. This integer represents Bob's answer for the expression given in the first line. Output Output one of the following four characters: M When only the multiplication-first rule results Bob's answer. L When only the left-to-right rule results Bob's answer. U When both of the rules result Bob's answer. I When neither of the rules results Bob's answer. Sample Input 1 1+2*3+4 11 Sample Output 1 M Sample Input 2 1+2*3+4 13 Sample Output 2 L Sample Input 3 3 3 Sample Output 3 U Sample Input 4 1+2*3+4 9 Sample Output 4 I | 35,266 |
Problem B: å®ãããã§ãã«ãŒ ããªãã¯ç¡äºé²åŠæ¯ãåããçµããé§å Žè¿èŸºããæ¬é·è¿èŸºãžåŒã£è¶ãæºåã®æäžã§ãã£ãã å®¶ã®äžãæŽçããŠãããšããå»å¹Žè³Œå
¥ããå®ããã倧éã«èŠã€ãã£ãã 亀ææéã確èªãããšããææ¥ãŸã§ã«æéããªããã°ãªããªãã®ã ããåŒã£è¶ãã®æºåããŸã å
šãçµãã£ãŠããªãããå°é¡ã®åœéžéã®ããã«å®ãã売ãå ŽãŸã§è¡ãã®ã¯é¢åã§ããã ããã§ããªãã¯ãããåœéžéãåŸããããã調ã¹ãããšã«ããã å®ããã¯8æ¡ã®æ°åãããªããåœéžçªå·ã¯åãã8æ¡ã§æ°åãš'*'ããæ§æãããæã£ãŠããå®ãããšæ°åéšåãäžèŽããå Žåãåœéžçªå·ã«å¿ããåœéžéãæ¯æãããã äŸãã°ææããŠããå®ããã®çªå·ã "12345678" ã®å Žåãåœéžçªå·ã "*******8" ã "****5678" ã®å Žåã¯åœéžãšãªãããåœéžçªå·ã "****4678" ã®ãšãã¯åœéžãšã¯ãªããªããåœéžçªå·ã¯è€æ°ããåŸãŠãããããç¬ç«ã«åœéžéãæ¯æãããããã ããåœéžçªå·ã¯1æã®å®ããã2ã€ä»¥äžã®åœéžçªå·ã«åœãããªãããã«éžã°ãããããšãã°åœéžçªå·ã "*******8", "****5678" ã®2ã€ã§ãã£ãå Žåã "12345678" ã¯äž¡æ¹ã«åœéžããŠããŸãããããã®ãããªåœéžçªå·ã®éžã°ãæ¹ããããããšã¯ãªãã ããªãã®ä»äºã¯ãå
¥åãšããŠäžããããææããŠããå®ããã®çªå·ãšå®ããã®åœéžçªå·ã«å¯ŸããŠããããã®åœéžéãåŸãããããåºåããããã°ã©ã ãæžãããšã§ããã Input å
¥åã¯ä»¥äžã®ãããªåœ¢åŒã§äžããããã n m N 1 M 1 ... N n M n B 1 ... B m 1è¡ç®ã§ã¯åœéžçªå·ã®æ° n (1 †n †100)ãšææããŠããå®ããã®ææ° m (1 †m †1000)ãããããæŽæ°ã§äžããããã ç¶ã n è¡ã§ã¯ãåè¡ã«åœéžçªå· N i ãšåœéžé M i (1 †M i †1000000)ãäžãããããåœéžéã¯æŽæ°ã§ãããåœéžçªå·ã®åœ¢åŒã¯å顿äžã§è¿°ã¹ããšããã§ããã ç¶ã m è¡ã§ã¯ææããŠããå®ããã®çªå·ãäžããããã Output åœéžéã®åèšé¡ãåºåããã Notes on Test Cases äžèšå
¥å圢åŒã§è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã«å¯ŸããŠäžèšåºå圢åŒã§åºåãè¡ãããã°ã©ã ãäœæããŠäžããã n ã 0 ã®ãšãå
¥åã®çµããã瀺ããŸãã Sample Input 3 3 *******1 100 ******22 1000 11111112 1000000 01203291 02382022 11111111 10 10 ****3228 149416 ****3992 198635 ****4286 77783 ****4843 225244 ***49835 231046 ***59393 379996 *5763748 437345 *6726222 58054 *8117882 16375 *9244339 537727 77885716 96726222 26971031 66652868 89599648 37772338 64679621 65479161 92959393 57855682 0 0 Output for Sample Input 1200 438050 | 35,267 |
A: A-Z Cat / A-Z ãã£ãã ç©èª ãããã«ããã¯è¥ã¶æŸé«æ ¡ã®ããã°ã©ãã³ã°ã³ã³ãã¹ãéšïŒéç§°ã·ãããéšã«æå±ãã2幎çã§ããïŒãšãŠã€ããªãããããïŒãããã«ããã¯åéã®ãžã§ã€ã«é ŒãŸããŠç«ãé ããããšã«ãªã£ãïŒA-Z ãã£ãããšåŒã°ããççš®ã®ç«ã§ããïŒãããã«ããã¯é ãã£ã A-Z ãã£ãããããããã«ãã 2 å·ããš (åæã«) åä»ãïŒå€§å±€å¯æãã£ãïŒ A-Z ãã£ããã¯ç¹å®ã®æ¡ä»¶ãæºããæååã奜ããšãããïŒããã§ãããã«ããã詊ãã«æååãäžããŠã¿ããšïŒãããã«ãã 2 å·ã¯æååã®äžéšãçªã§åãåã£ãåŸïŒæºè¶³ããªè¡šæ
ãæµ®ãã¹ãïŒã©ãããïŒå¥œã¿ã®æååã«æžãæããããšããŠããããã ïŒ å€©äœ¿ã®ããšããããããããã«ããã«ãã£ããã§ãã D ã®ã²ãšã¯ïŒãããã«ããã®ããã« A-Z ãã£ããã奜ãæååã®æ¡ä»¶ãèŠã€ãåºããïŒãã㯠'A' ãš 'Z' ã亀äºã«ç¹°ãè¿ãããæååã§ããïŒã〠'A' ããå§ãŸã 'Z' ã§çµããæååã§ããïŒA-Z ãã£ããã¯ãšãŠãè³¢ãã®ã§ïŒæå°éã®æåæ¶å»ã§å¥œã¿ã®æååã«å€æããããšããïŒãããã«ããã«ããæ Œå¥œãããã D ã®ã²ãšã¯ïŒäžãããã 'A' ãš 'Z' ã®ã¿ãããªãæååã A-Z ãã£ãããã©ã®ãããªæååã«å€æãããæ±ããããã°ã©ã ãæžãããšã«ããïŒ åé¡ è±å€§æåã®ã¿ãããªãæåå S ãäžããããïŒ S ã®ä»»æã®æåã奜ããªã ãåé€ããããšã§ïŒ'A' ãš 'Z' ã亀äºã«åºçŸãïŒã〠'A' ããå§ãŸã 'Z' ã§çµããæååãäœãïŒåé€åæ°ãæå°åãããšãåŸãããæååãæ±ããïŒ å
¥ååœ¢åŒ å
¥åãšããŠæåå S ã1è¡ã«äžããããïŒ S ã¯è±å€§æåã®ã¿ãããªãïŒ 1 †|S| †20 ãæºããïŒ åºååœ¢åŒ S ã«å¯Ÿãæå°åæ°ã®æååé€ãè¡ã£ãŠåŸãããïŒ'A' ãš'Z' ã亀äºã«åºçŸãïŒã〠'A' ããå§ãŸã 'Z' ã§çµããæååã 1 è¡ã«åºåããïŒã©ã®ãããªæååé€ãè¡ã£ãŠãæ¡ä»¶ãæºããæååãåŸãããªãå Žå㯠-1 ã 1 è¡ã«åºåããïŒ å
¥åäŸ1 AIZUNYANPEROPERO åºåäŸ1 AZ å
¥åäŸ2 AZAZ åºåäŸ2 AZAZ å
¥åäŸ3 ZDDYAZAWABDDZAZPIDDA åºåäŸ3 AZAZAZ å
¥åäŸ4 ZZZZAAAAAA åºåäŸ4 -1 | 35,268 |
Problem G: The Morning after Halloween You are working for an amusement park as an operator of an obakeyashiki , or a haunted house, in which guests walk through narrow and dark corridors. The house is proud of their lively ghosts, which are actually robots remotely controlled by the operator, hiding here and there in the corridors. One morning, you found that the ghosts are not in the positions where they are supposed to be. Ah, yesterday was Halloween. Believe or not, paranormal spirits have moved them around the corridors in the night. You have to move them into their right positions before guests come. Your manager is eager to know how long it takes to restore the ghosts. In this problem, you are asked to write a program that, given a floor map of a house, finds the smallest number of steps to move all ghosts to the positions where they are supposed to be. A floor consists of a matrix of square cells. A cell is either a wall cell where ghosts cannot move into or a corridor cell where they can. At each step, you can move any number of ghosts simultaneously. Every ghost can either stay in the current cell, or move to one of the corridor cells in its 4-neighborhood (i.e. immediately left, right, up or down), if the ghosts satisfy the following conditions: No more than one ghost occupies one position at the end of the step. No pair of ghosts exchange their positions one another in the step. For example, suppose ghosts are located as shown in the following (partial) map, where a sharp sign (' # ) represents a wall cell and 'a', 'b', and 'c' ghosts. #### ab# #c## #### The following four maps show the only possible positions of the ghosts after one step. #### #### #### #### ab# a b# acb# ab # #c## #c## # ## #c## #### #### #### #### Input The input consists of at most 10 datasets, each of which represents a floor map of a house. The format of a dataset is as follows. w h n c 11 c 12 ... c 1 w c 21 c 22 ... c 2 w . . .. . .. . . .. . c h 1 c h 2 ... c h w w , h and n in the first line are integers, separated by a space. w and h are the floor width and height of the house, respectively. n is the number of ghosts. They satisfy the following constraints. 4 †w †16 4 †h †16 1 †n †3 Subsequent h lines of w characters are the floor map. Each of c ij is either: a ' # ' representing a wall cell, a lowercase letter representing a corridor cell which is the initial position of a ghost, an uppercase letter representing a corridor cell which is the position where the ghost corresponding to its lowercase letter is supposed to be, or a space representing a corridor cell that is none of the above. In each map, each of the first n letters from a and the first n letters from A appears once and only once. Outermost cells of a map are walls; i.e. all characters of the first and last lines are sharps; and the first and last characters on each line are also sharps. All corridor cells in a map are connected; i.e. given a corridor cell, you can reach any other corridor cell by following corridor cells in the 4-neighborhoods. Similarly, all wall cells are connected. Any 2 à 2 area on any map has at least one sharp. You can assume that every map has a sequence of moves of ghosts that restores all ghosts to the positions where they are supposed to be. The last dataset is followed by a line containing three zeros separated by a space. Output For each dataset in the input, one line containing the smallest number of steps to restore ghosts into the positions where they are supposed to be should be output. An output line should not contain extra characters such as spaces. Sample Input 5 5 2 ##### #A#B# # # #b#a# ##### 16 4 3 ################ ## ########## ## # ABCcba # ################ 16 16 3 ################ ### ## # ## ## # ## # c# # ## ########b# # ## # # # # # # ## # # ## ## a# # # # # ### ## #### ## # ## # # # # # ##### # ## ## #### #B# # # ## C# # ### # # # ####### # # ###### A## # # # ## ################ 0 0 0 Output for the Sample Input 7 36 77 | 35,269 |
Problem F: Marked Ancestor You are given a tree T that consists of N nodes. Each node is numbered from 1 to N , and node 1 is always the root node of T . Consider the following two operations on T : M v : (Mark) Mark node v . Q v : (Query) Print the index of the nearest marked ancestor of node v which is nearest to it. Initially, only the root node is marked. Note that a node is an ancestor of itself. Your job is to write a program that performs a sequence of these operations on a given tree and calculates the value that each Q operation will print. To avoid too large output file, your program is requested to print the sum of the outputs of all query operations. Note that the judges confirmed that it is possible to calculate every output of query operations in a given sequence. Input The input consists of multiple datasets. Each dataset has the following format: The first line of the input contains two integers N and Q , which denotes the number of nodes in the tree T and the number of operations, respectively. These numbers meet the following conditions: 1 †N †100000 and 1 †Q †100000. The following N - 1 lines describe the configuration of the tree T . Each line contains a single integer p i ( i = 2, ... , N ), which represents the index of the parent of i -th node. The next Q lines contain operations in order. Each operation is formatted as " M v " or " Q v ", where v is the index of a node. The last dataset is followed by a line containing two zeros. This line is not a part of any dataset and should not be processed. Output For each dataset, print the sum of the outputs of all query operations in one line. Sample Input 6 3 1 1 2 3 3 Q 5 M 3 Q 5 0 0 Output for the Sample Input 4 | 35,270 |
æ°è±¡äºå ±å£« (Weather Forecaster) åé¡ JOI åžã¯ååæ¹åã« H ããã¡ãŒãã«ïŒæ±è¥¿æ¹åã« W ããã¡ãŒãã«ã®é·æ¹åœ¢ã®åœ¢ãããŠããïŒH à W åã® 1 ããã¡ãŒãã«åæ¹ã®å°åºç»ã«åºåãããŠããïŒåãã i çªç®ïŒè¥¿ãã j çªç®ã®å°åºç»ã (i, j) ãšè¡šãïŒ åå°åºç»ã¯äžç©ºã«é²ããããé²ããªããã®ã©ã¡ããã§ããïŒãã¹ãŠã®é²ã¯ïŒ1 åçµã€ããšã« 1 ããã¡ãŒãã«æ±ã«ç§»åããïŒä»æ¥ã¯å®ã«å€©æ°ãè¯ãããïŒJOI åžã®å€ãã JOI åžå
ã«é²ãç§»åããŠããããšã¯ãªãïŒ ä»ïŒåå°åºç»ã®äžç©ºã«é²ãããããªãããããã£ãŠããïŒæ°è±¡äºå ±å£«ã§ããããªãã¯ïŒåå°åºç»ã«ã€ããŠïŒä»ããäœååŸã«åããŠãã®å°åºç»ã®äžç©ºã«é²ãæ¥ãããäºæž¬ããããšã«ãªã£ãïŒ åå°åºç»ã«ã€ããŠïŒä»ããäœååŸã«åããŠãã®å°åºç»ã®äžç©ºã«é²ãæ¥ããæ±ããïŒ å
¥å å
¥å㯠1 + H è¡ãããªãïŒ 1 è¡ç®ã«ã¯ïŒæŽæ° H, W (1 †H †100, 1 †W †100) ã空çœãåºåããšããŠæžãããŠããïŒããã¯ïŒJOI åžã H à W åã® 1 ããã¡ãŒãã«åæ¹ã®å°åºç»ã«åºåãããŠããããšã衚ãïŒ ç¶ã H è¡ã®ãã¡ã® i è¡ç® (1 †i †H) ã«ã¯ W æåãããªãæååãæžãããŠããïŒW æåã®ãã¡ã® j æåç® (1 †j †W) ã¯ïŒå°åºç» (i, j) ã®äžç©ºã«ïŒä»ïŒé²ããããã©ããã衚ãïŒé²ãããå Žåã¯æå 'c' (è±å°æå) ãïŒé²ããªãå Žåã¯æå '.' (ããªãªã) ãæžãããŠããïŒ åºå åºå㯠H è¡ãããªãïŒããããã®è¡ã¯ç©ºçœãåºåããšãã W åã®æŽæ°ãããªãïŒåºåã® i è¡ç®ã® j çªç®ã®æŽæ° (1 †i †H, 1 †j †W) ã¯ïŒä»ããäœååŸã«åããŠå°åºç» (i, j) ã®äžç©ºã«é²ãæ¥ããã衚ããªããã°ãªããªãïŒãã ãïŒä»ãã§ã«å°åºç» (i, j) ã®äžç©ºã«é²ãããå Žå㯠0 ãïŒäœåçµã£ãŠãå°åºç» (i, j) ã®äžç©ºã«é²ãæ¥ãªãå Žå㯠-1 ãåºåããïŒ åºåã®åè¡ã®è¡é ãšè¡æ«ã«ã¯äœèšãªç©ºçœãå
¥ããªãããšïŒ å
¥åºåäŸ å
¥åäŸ 1 3 4 c..c ..c. .... åºåäŸ 1 0 1 2 0 -1 -1 0 1 -1 -1 -1 -1 å
¥åäŸ 2 6 8 .c...... ........ .ccc..c. ....c... ..c.cc.. ....c... åºåäŸ 2 -1 0 1 2 3 4 5 6 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 0 1 2 0 1 -1 -1 -1 -1 0 1 2 3 -1 -1 0 1 0 0 1 2 -1 -1 -1 -1 0 1 2 3 å
¥åºåäŸ 1 ã§ã¯ïŒJOI åžã¯ 3 à 4 åã®å°åºç»ã«åºåãããŠããïŒä»ã® JOI åžã®é²ã®ç¶æ³ã¯ä»¥äžã®éãã§ããïŒå³ã®äžãåã衚ãïŒ ãã®åŸïŒ1 åããšã«é²ã¯ä»¥äžã®ããã«ç§»åããïŒ å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 35,271 |
ææéè·¯éè¡æ 20XX幎ã«å倿¹åžç±å¡©å çŽçºããåäŒæŽ¥çºãŸã§ã®6åºéãç·è·é¢58kmã®äŒæŽ¥äžå€®éè·¯ã宿ãééããäºå®ã§ãã ééåŸãå幎éã¯å©çšä¿é²ã®ãã17æ30åã19æ30åãŸã§ã«åºçºICãå°çICãééãããªããã€èµ°è¡è·é¢ã40km以äžã®è»ã«å¯Ÿããéè¡æéã¯åé¡ã«ãªããŸãããã ãæéã¯50ååäœãšãã端æ°ã¯åãäžããŸããäžèšã®è¡šã¯æéãšè·é¢ã®äžèŠ§è¡šã§ãã äŸãã°å倿¹ïŒïŒïŒããäŒæŽ¥è¥æŸïŒïŒïŒãŸã§ã¯æéã450åãè·é¢ã12kmãšãªããŸããå顿é垯ã§ããã°250åã«ãªããŸãã åºçºICãåºçºICééæå»ãå°çICãå°çICééæå»ãå
¥åãšããæéãèšç®ããŠåºåããããã°ã©ã ãäœæããŠãã ããããã ããå
¥åãããæå»ã¯24 æé衚èšã®å€ãšããŸãããªãã17æ30åããã³19æ30åã¡ããã©ã«ééããå Žåãå顿é垯ã«å«ããŸãã Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã d h d m d a h a m a ïŒè¡ç®ã«åºçºICã®çªå· d (1 †d †7)ãïŒè¡ç®ã«åºçºICã®ééæå»ã®æé h d (0 †h d †23) ãšå m d (0 †m d †59) ãäžããããŸãã 3è¡ç®ã«å°çICã®çªå· a (1 †a †7)ãïŒè¡ç®ã«å°çICã®ééæå»ã®æé h a (0 †h a †23) ãšå m a (0 †m a †59) ãäžããããŸãã Output ããŒã¿ã»ããããšã«éè¡æéïŒæŽæ°ïŒãïŒè¡ã«åºåããŸãã Sample Input 2 17 25 4 17 45 4 17 25 7 19 35 0 Output for the Sample Input 250 1300 | 35,272 |
å®¿é¡ (Homework) åé¡ å¬äŒã¿ã®å®¿é¡ã«æ¯åèŠãããããŠãã JOI åãïŒä»åã¯å®¿é¡ãèšç»çã«å®è¡ããããšã«ããïŒå®¿é¡ã¯åœèªãšç®æ°ã®ããªã«ã§ããïŒåœèªã®ããªã«ã¯ A ããŒãžïŒç®æ°ã®ããªã«ã¯ B ããŒãžããïŒ JOI åã¯ïŒ1 æ¥ã«åœèªã®ããªã«ãæå€§ C ããŒãžãšïŒç®æ°ã®ããªã«ãæå€§ D ããŒãžé²ããããšãã§ãããïŒå®¿é¡ããããšãã®æ¥ã¯éã¶ããšãã§ããªãïŒ å¬äŒã¿ã¯ L æ¥ããïŒJOI åã¯å¬äŒã¿äžã«å®¿é¡ãçµããããªããã°ãªããªãïŒJOI åãå¬äŒã¿äžã«æå€§ã§äœæ¥éã¹ãããæ±ããããã°ã©ã ãäœæããïŒ å
¥å å
¥å㯠5 è¡ãããªãïŒ1 è¡ã« 1 ã€ãã€æ£ã®æŽæ°ãæžãããŠããïŒ 1 è¡ç®ã«ã¯æŽæ° L (2 ⊠L ⊠40) ãæžãããŠããïŒå¬äŒã¿ã®æ¥æ°ã衚ãïŒ 2 è¡ç®ã«ã¯æŽæ° A (1 ⊠A ⊠1000) ãæžãããŠããïŒåœèªã®ããªã«ã®ããŒãžæ°ã衚ãïŒ 3 è¡ç®ã«ã¯æŽæ° B (1 ⊠B ⊠1000) ãæžãããŠããïŒç®æ°ã®ããªã«ã®ããŒãžæ°ã衚ãïŒ 4 è¡ç®ã«ã¯æŽæ° C (1 ⊠C ⊠100) ãæžãããŠããïŒJOI åã 1 æ¥ã«é²ããããšãã§ããåœèªã®ããªã«ã®æå€§ããŒãžæ°ã衚ãïŒ 5 è¡ç®ã«ã¯æŽæ° D (1 ⊠D ⊠100) ãæžãããŠããïŒJOI åã 1 æ¥ã«é²ããããšãã§ããç®æ°ã®ããªã«ã®æå€§ããŒãžæ°ã衚ãïŒ ãã ãïŒäžããããå
¥åããŒã¿ã«ãããŠã¯ïŒJOI åãå¬äŒã¿äžã«å®¿é¡ãå¿
ãçµããããããšãã§ãïŒ å°ãªããšã 1 æ¥ã¯éã¹ãããšãä¿èšŒãããŠããïŒ åºå JOI åãå¬äŒã¿äžã«éã¹ãæ¥æ°ã®æå€§å€ã 1 è¡ã§åºåããïŒ å
¥åºåäŸ å
¥åäŸ 1 20 25 30 6 8 åºåäŸ 1 15 å
¥åºåäŸ 1 ã§ã¯ïŒå¬äŒã¿ã¯ 20 æ¥éããïŒåœèªã®ããªã«ã 25 ããŒãžïŒç®æ°ã®ããªã«ã 30 ããŒãžããïŒJOI å㯠1 æ¥ã«åœèªã®ããªã«ãæå€§ 6 ããŒãžïŒç®æ°ã®ããªã«ãæå€§ 8 ããŒãžé²ããããšãã§ããïŒäŸãã° JOI åãå¬äŒã¿åæ¥ããåœèªã®ããªã«ã 6 ããŒãžïŒç®æ°ã®ããªã«ã 8 ããŒãžãã€é²ãããšãããšïŒåœèªã®ããªã«ã 5 æ¥ç®ã«ïŒç®æ°ã®ããªã«ã 4 æ¥ç®ã«çµããããããšãã§ãïŒ15 æ¥ééã¶ããšãã§ããïŒããã JOI åãå¬äŒã¿äžã«éã¹ãæ¥æ°ã®æå€§å€ãªã®ã§ïŒ15 ãåºåããïŒ å
¥åäŸ 2 15 32 48 4 6 åºåäŸ 2 7 å
¥åºåäŸ 2 ã§ã¯ïŒ äŸãã° JOI åã忥ããåœèªã®ããªã«ã 4 ããŒãžïŒç®æ°ã®ããªã«ã 6 ããŒãžãã€é²ãããšãããšïŒ8 æ¥ç®ã«äž¡æ¹ã®ããªã«ãçµããããããšãã§ãïŒ7 æ¥ééã¶ããšãã§ããïŒããã JOI åãå¬äŒã¿äžã«éã¹ãæ¥æ°ã®æå€§å€ãªã®ã§ïŒ7 ãåºåããïŒ å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 35,273 |
Score : 100 points Problem Statement AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a , the color of the one he bought yesterday is b , and the color of the one he bought today is c . Here, the color of each paint can is represented by an integer between 1 and 100 , inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him. Constraints 1âŠa,b,câŠ100 Input The input is given from Standard Input in the following format: a b c Output Print the number of different kinds of colors of the paint cans. Sample Input 1 3 1 4 Sample Output 1 3 Three different colors: 1 , 3 , and 4 . Sample Input 2 3 3 33 Sample Output 2 2 Two different colors: 3 and 33 . | 35,274 |
Score : 700 points Problem Statement Tonight, in your favourite cinema they are giving the movie Joker and all seats are occupied. In the cinema there are N rows with N seats each, forming an N\times N square. We denote with 1, 2,\dots, N the viewers in the first row (from left to right); with N+1, \dots, 2N the viewers in the second row (from left to right); and so on until the last row, whose viewers are denoted by N^2-N+1,\dots, N^2 . At the end of the movie, the viewers go out of the cinema in a certain order: the i -th viewer leaving her seat is the one denoted by the number P_i . The viewer P_{i+1} waits until viewer P_i has left the cinema before leaving her seat. To exit from the cinema, a viewer must move from seat to seat until she exits the square of seats (any side of the square is a valid exit). A viewer can move from a seat to one of its 4 adjacent seats (same row or same column). While leaving the cinema, it might be that a certain viewer x goes through a seat currently occupied by viewer y ; in that case viewer y will hate viewer x forever. Each viewer chooses the way that minimizes the number of viewers that will hate her forever. Compute the number of pairs of viewers (x, y) such that y will hate x forever. Constraints 2 \le N \le 500 The sequence P_1, P_2, \dots, P_{N^2} is a permutation of \{1, 2, \dots, N^2\} . Input The input is given from Standard Input in the format N P_1 P_2 \cdots P_{N^2} Output If ans is the number of pairs of viewers described in the statement, you should print on Standard Output ans Sample Input 1 3 1 3 7 9 5 4 8 6 2 Sample Output 1 1 Before the end of the movie, the viewers are arranged in the cinema as follows: 1 2 3 4 5 6 7 8 9 The first four viewers leaving the cinema ( 1 , 3 , 7 , 9 ) can leave the cinema without going through any seat, so they will not be hated by anybody. Then, viewer 5 must go through one of the seats where viewers 2 , 4 , 6 , 8 are currently seated while leaving the cinema; hence he will be hated by at least one of those viewers. Finally the remaining viewers can leave the cinema (in the order 4 , 8 , 6 , 2 ) without going through any occupied seat (actually, they can leave the cinema without going through any seat at all). Sample Input 2 4 6 7 1 4 13 16 10 9 5 11 12 14 15 2 3 8 Sample Output 2 3 Sample Input 3 6 11 21 35 22 7 36 27 34 8 20 15 13 16 1 24 3 2 17 26 9 18 32 31 23 19 14 4 25 10 29 28 33 12 6 5 30 Sample Output 3 11 | 35,275 |
I: å¶å¥ãœãŒã å顿 $0$ ãã $N-1$ ãŸã§ã®æŽæ°ãäžŠã³æ¿ããé·ã $N$ ã®é å $P$ ãäžããããŸãã 以äžã®æäœãæå€§ $30$ åãŸã§è¡ã£ãŠã $P$ ãæé ã«äžŠã¹æ¿ããŠãã ããã æäœ $1$ åã®æäœã§ã¯ã次㮠1 ãã 4 ãé ã«è¡ãã 0 ãš 1 ãããªãé·ã $N$ ã®æåå $S$ ãšãæŽæ° $t$ ( $t = 0$ ãŸã㯠$t = 1$ ) ã宣èšããã ç©ºã®æ°å $A, B$ ãçšæããæŽæ° $i$ ã $1$ ãã $N$ ãŸã§åãããªãã以äžãè¡ãã $S_i$ ã 0 ã®ãšããäœãããªãã $S_i$ ã 1 ã®ãšãã $P_i$ ãå¶æ°ãªãã° $A$ ã®æ«å°Ÿã« $P_i$ ã远å ããã $P_i$ ã奿°ãªãã° $B$ ã®æ«å°Ÿã« $P_i$ ã远å ããã æ°å $C$ ã以äžã®ããã«å®çŸ©ããã $t = 0$ ã®ãšãã $C$ 㯠$A$ ãš $B$ ããã®é ã«é£çµãããã®ãšããã $t = 1$ ã®ãšãã $C$ 㯠$B$ ãš $A$ ããã®é ã«é£çµãããã®ãšããã æŽæ° $i$ ã $1$ ãã $N$ ãŸã§åãããªãã以äžãè¡ãã $S_i$ ã 0 ã®ãšããäœãããªãã $S_i$ ã 1 ã®ãšãã $P_i$ ã $C$ ã®å
é ã®èŠçŽ ã«çœ®ãæãã $C$ ã®å
é ã®èŠçŽ ãæ¶ãã äŸãã°ã$N = 7, P = {0, 4, 2, 3, 6, 5, 1}$ ãšããŸãã $S$ ã "1101101" ãšãã$t = 1$ ãšããæäœã $1$ åè¡ããšã以äžã®å³ã®ããã« $P = {3, 1, 2, 0, 4, 5, 6}$ ãšãªããŸãã å¶çŽ $1 \leq N \leq 15000$ $P$ 㯠$0$ ãã $N-1$ ãŸã§ã®æŽæ°ãäžŠã³æ¿ããé å å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã $N$ $P_1$ $P_2$ $\ldots$ $P_N$ åºå $30$ å以å
ã®æäœã§ $P$ ãæé ã«äžŠã¹æ¿ãããããªæäœåã® $1$ ã€ã以äžã®åœ¢åŒã§åºåããããã®ãããªæäœåã¯è€æ°ååšãããããããªãããã©ããåºåããŠãæ£çãšãªãã $1$ è¡ç®ã«ã¯ãæäœãè¡ãåæ° $K$ ãåºåããããã ãã $0 \le K \le 30$ ã§ãªããã°ãªããªãã $i + 1$ è¡ç® $(1 \le i \le K)$ ã«ã¯ã $i$ åç®ã®æäœã§å®£èšããæŽæ° $t_i (t_i = 0,1)$ ããã³é·ã $N$ ã®æåå $S_i$ ããã®é ã«åºåããã $K$ $t_1$ $S_1$ $t_2$ $S_2$ $\vdots$ $t_K$ $S_K$ å
¥åäŸ1 7 0 4 2 3 6 5 1 åºåäŸ1 1 1 0100101 æäœãè¡ããšã$A = { 4, 6 }, B = { 1 }$ ãšãªãã $t = 1$ ãã $C = { 1, 4, 6 }$ ãšãªããŸãã $P$ ã®èŠçŽ ã $C$ ã«ãã£ãŠçœ®ãæãããšã $P = { 0, 1, 2, 3, 4, 5, 6 }$ ãšãªãã®ã§ããã®æäœã§ $P$ ãæé ã«äžŠã¹æ¿ããããšãã§ããŸãã å
¥åäŸ2 4 1 0 3 2 åºåäŸ2 2 0 1100 0 0011 äŸãã°ä»¥äžã®ãããªåºåãæ£çãšãªããŸãã 2 0 1111 1 0110 å
¥åäŸ3 1 0 åºåäŸ3 0 æäœãè¡ããªããŠãæ§ããŸããã | 35,276 |
Score : 300 points Problem Statement There are N integers, A_1, A_2, ..., A_N , written on the blackboard. You will choose one of them and replace it with an integer of your choice between 1 and 10^9 (inclusive), possibly the same as the integer originally written. Find the maximum possible greatest common divisor of the N integers on the blackboard after your move. Constraints All values in input are integers. 2 \leq N \leq 10^5 1 \leq A_i \leq 10^9 Output Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the maximum possible greatest common divisor of the N integers on the blackboard after your move. Sample Input 1 3 7 6 8 Sample Output 1 2 If we replace 7 with 4 , the greatest common divisor of the three integers on the blackboard will be 2 , which is the maximum possible value. Sample Input 2 3 12 15 18 Sample Output 2 6 Sample Input 3 2 1000000000 1000000000 Sample Output 3 1000000000 We can replace an integer with itself. | 35,277 |
Score : 1200 points Problem Statement In Republic of AtCoder, Snuke Chameleons (Family: Chamaeleonidae, Genus: Bartaberia) are very popular pets. Ringo keeps N Snuke Chameleons in a cage. A Snuke Chameleon that has not eaten anything is blue. It changes its color according to the following rules: A Snuke Chameleon that is blue will change its color to red when the number of red balls it has eaten becomes strictly larger than the number of blue balls it has eaten. A Snuke Chameleon that is red will change its color to blue when the number of blue balls it has eaten becomes strictly larger than the number of red balls it has eaten. Initially, every Snuke Chameleon had not eaten anything. Ringo fed them by repeating the following process K times: Grab either a red ball or a blue ball. Throw that ball into the cage. Then, one of the chameleons eats it. After Ringo threw in K balls, all the chameleons were red. We are interested in the possible ways Ringo could have thrown in K balls. How many such ways are there? Find the count modulo 998244353 . Here, two ways to throw in balls are considered different when there exists i such that the color of the ball that are thrown in the i -th throw is different. Constraints 1 \leq N,K \leq 5 \times 10^5 N and K are integers. Input Input is given from Standard Input in the following format: N K Output Print the possible ways Ringo could have thrown in K balls, modulo 998244353 . Sample Input 1 2 4 Sample Output 1 7 We will use R to represent a red ball, and B to represent a blue ball. There are seven ways to throw in balls that satisfy the condition: BRRR , RBRB , RBRR , RRBB , RRBR , RRRB and RRRR . Sample Input 2 3 7 Sample Output 2 57 Sample Input 3 8 3 Sample Output 3 0 Sample Input 4 8 10 Sample Output 4 46 Sample Input 5 123456 234567 Sample Output 5 857617983 | 35,278 |
Score : 2718 points Problem Statement There is a very long bench. The bench is divided into M sections, where M is a very large integer. Initially, the bench is vacant. Then, M people come to the bench one by one, and perform the following action: We call a section comfortable if the section is currently unoccupied and is not adjacent to any occupied sections. If there is no comfortable section, the person leaves the bench. Otherwise, the person chooses one of comfortable sections uniformly at random, and sits there. (The choices are independent from each other). After all M people perform actions, Snuke chooses an interval of N consecutive sections uniformly at random (from M-N+1 possible intervals), and takes a photo. His photo can be described by a string of length N consisting of X and - : the i -th character of the string is X if the i -th section from the left in the interval is occupied, and - otherwise. Note that the photo is directed. For example, -X--X and X--X- are different photos. What is the probability that the photo matches a given string s ? This probability depends on M . You need to compute the limit of this probability when M goes infinity. Here, we can prove that the limit can be uniquely written in the following format using three rational numbers p, q, r and e = 2.718 \ldots (the base of natural logarithm): p + \frac{q}{e} + \frac{r}{e^2} Your task is to compute these three rational numbers, and print them modulo 10^9 + 7 , as described in Notes section. Notes When you print a rational number, first write it as a fraction \frac{y}{x} , where x, y are integers and x is not divisible by 10^9 + 7 (under the constraints of the problem, such representation is always possible). Then, you need to print the only integer z between 0 and 10^9 + 6 , inclusive, that satisfies xz \equiv y \pmod{10^9 + 7} . Constraints 1 \leq N \leq 1000 |s| = N s consists of X and - . Input Input is given from Standard Input in the following format: N s Output Print three rational numbers p, q, r , separated by spaces. Sample Input 1 1 X Sample Output 1 500000004 0 500000003 The probability that a randomly chosen section is occupied converge to \frac{1}{2} - \frac{1}{2e^2} . Sample Input 2 3 --- Sample Output 2 0 0 0 After the actions, no three consecutive unoccupied sections can be left. Sample Input 3 5 X--X- Sample Output 3 0 0 1 The limit is \frac{1}{e^2} . Sample Input 4 5 X-X-X Sample Output 4 500000004 0 833333337 The limit is \frac{1}{2} - \frac{13}{6e^2} . Sample Input 5 20 -X--X--X-X--X--X-X-X Sample Output 5 0 0 183703705 The limit is \frac{7}{675e^2} . Sample Input 6 100 X-X-X-X-X-X-X-X-X-X--X-X-X-X-X-X-X-X-X-X-X-X-X-X-X--X--X-X-X-X--X--X-X-X--X-X-X--X-X--X--X-X--X-X-X- Sample Output 6 0 0 435664291 | 35,279 |
Balance Scale You, an experimental chemist, have a balance scale and a kit of weights for measuring weights of powder chemicals. For work efficiency, a single use of the balance scale should be enough for measurement of each amount. You can use any number of weights at a time, placing them either on the balance plate opposite to the chemical or on the same plate with the chemical. For example, if you have two weights of 2 and 9 units, you can measure out not only 2 and 9 units of the chemical, but also 11 units by placing both on the plate opposite to the chemical (Fig. C-1 left), and 7 units by placing one of them on the plate with the chemical (Fig. C-1 right). These are the only amounts that can be measured out efficiently. Fig. C-1 Measuring 11 and 7 units of chemical You have at hand a list of amounts of chemicals to measure today. The weight kit already at hand, however, may not be enough to efficiently measure all the amounts in the measurement list. If not, you can purchase one single new weight to supplement the kit, but, as heavier weights are more expensive, you'd like to do with the lightest possible. Note that, although weights of arbitrary positive masses are in the market, none with negative masses can be found. Input The input consists of at most 100 datasets, each in the following format. n m a 1 a 2 ... a n w 1 w 2 ... w m The first line of a dataset has n and m , the number of amounts in the measurement list and the number of weights in the weight kit at hand, respectively. They are integers separated by a space satisfying 1 †n †100 and 1 †m †10. The next line has the n amounts in the measurement list, a 1 through a n , separated by spaces. Each of a i is an integer satisfying 1 †a i †10 9 , and a i â a j holds for i â j . The third and final line of a dataset has the list of the masses of the m weights at hand, w 1 through w m , separated by spaces. Each of w j is an integer, satisfying 1 †w j †10 8 . Two or more weights may have the same mass. The end of the input is indicated by a line containing two zeros. Output For each dataset, output a single line containing an integer specified as follows. If all the amounts in the measurement list can be measured out without any additional weights, 0 . If adding one more weight will make all the amounts in the measurement list measurable, the mass of the lightest among such weights. The weight added may be heavier than 10 8 units. If adding one more weight is never enough to measure out all the amounts in the measurement list, -1 . Sample Input 4 2 9 2 7 11 2 9 6 2 7 3 6 12 16 9 2 9 5 2 7 3 6 12 17 2 9 7 5 15 21 33 48 51 75 111 36 54 57 93 113 0 0 Output for the Sample Input 0 5 -1 5 | 35,280 |
Score : 200 points Problem Statement You are given an H Ã W grid. The squares in the grid are described by H strings, S_1,...,S_H . The j -th character in the string S_i corresponds to the square at the i -th row from the top and j -th column from the left (1 \leq i \leq H,1 \leq j \leq W) . . stands for an empty square, and # stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each . in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process. Constraints 1 \leq H,W \leq 50 S_i is a string of length W consisting of # and . . Input Input is given from Standard Input in the following format: H W S_1 : S_H Output Print the H strings after the process. The i -th line should contain a string T_i of length W , where the j -th character in T_i corresponds to the square at the i -th row from the top and j -th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W) . Sample Input 1 3 5 ..... .#.#. ..... Sample Output 1 11211 1#2#1 11211 For example, let us observe the empty square at the first row from the top and first column from the left. There is one bomb square adjacent to this empty square: the square at the second row and second column. Thus, the . corresponding to this empty square is replaced with 1 . Sample Input 2 3 5 ##### ##### ##### Sample Output 2 ##### ##### ##### It is possible that there is no empty square. Sample Input 3 6 6 #####. #.#.## ####.# .#..#. #.##.. #.#... Sample Output 3 #####3 #8#7## ####5# 4#65#2 #5##21 #4#310 | 35,281 |
åé¡å Zero division checker 森äžããã¯å°ã£ãŠããŸãã... å§åããã«ããã°ã©ã ãæžããŠããã£ãã®ã§ããããã®ããã°ã©ã ãã¯ã©ãã·ã¥ããã®ã§ãã å§åããã«æžããŠããã£ãã®ã¯ãéããŒã©ã³ãèšæ³ã®åŒãèªãã§ããã®èšç®çµæãåºåããããã°ã©ã ã§ãã¯ã©ãã·ã¥ãã°ã«ãããšã 0 ã§å²ãç®ãããŠããŸã£ãã®ãåå ã®ããã§ããããã¯ã森äžãããééã£ãåŒãå
¥åããŠããŸã£ããããããããŸããããããããããããããããããå§åããã®æžããããã°ã©ã ã«ãã°ãããã®ãããããŸããã å§åããã®æžããããã°ã©ã ãèªãã§ã¿ãããšæããŸããããå§åããã®ããã°ã©ã ã¯ã¢ã»ã³ããªãšããããããããªãããšã°ã§æžãããŠããããã§ãèŠãŠããã ãã§é ãã¬ã³ã¬ã³ããŠããŸãã ããã§ã森äžããã¯ããªãã«ãåŒãééã£ãŠããªããã©ãã調ã¹ãããã°ã©ã ãæžããŠãããããšã«ããŸãããåŒãééã£ãŠããããšã¯ããã®åŒã«åŸã£ãŠèšç®ãããšã 0 ã§ã®å²ãç®ãããŠããŸãå¯èœæ§ã®ããããšããããŸãã ãªããå§åããã®æžããã³ãŒãã¯ãšãŠããµããã³ã³ãã¥ãŒã¿ãŒã§åããã®ã§ãå æžä¹é€ã¯æŽæ°ã§è¡ããçµæã¯ 8 bit ã®ç¬Šå·ãªãæŽæ°ãšããŠä¿åãããŸãã äŸãã°ã 255+1 㯠0 ã«ãªã£ãŠããŸããã 3/2 㯠1 ã«ãªããŸãã ããå§åããã«ã¯ãªãããã§ããã (åè)éããŒã©ã³ãèšæ³ã§è¡šãããåŒãèšç®ãããæ¬äŒŒã³ãŒã s = 空ã®ã¹ã¿ã㯠n = åŒã®èŠçŽ æ° for i in 1..n: if åŒã®içªç®ã®èŠçŽ ãæŽæ°: sã«ãã®æŽæ°ãããã·ã¥ãã if åŒã®içªç®ã®èŠçŽ ã倿°: sã«ãã®å€æ°ã®å€ãããã·ã¥ãã if åŒã®içªç®ã®èŠçŽ ãæŒç®å: sããå€ããããããbãšãã sããå€ããããããaãšãã if æŒç®åã'+': r = (a + b) % 256 ãšãã if æŒç®åã'-': r = (a - b + 256) % 256 ãšãã if æŒç®åã'*': r = (a * b) % 256 ãšãã if æŒç®åã'/': r = (a / b) % 256 ãšãã sã«rãããã·ã¥ãã sããå€ããããããåŒã®èšç®çµæãšãã Input m name 1 lb 1 ub 1 ... name m lb m ub m n e 1 e 2 ... e n 0 †m †100 0 †lb i †ub i †255 1 †name i (1 †i †m) ã®é·ã †20 1 †n †100 m ã¯å€æ°ã®æ°ã name i , lb i , ub i ã¯ãããã倿°iã®ååãäžéãäžéã衚ããŸãã n ã¯åŒã«å«ãŸããèŠçŽ ã®æ°ã衚ãã e i ã¯åŒã® i çªç®ã®èŠçŽ ã衚ããŸãã å倿°ã¯åŒã®äžã«é«ã
1åããçŸããŸããã Output åŒãééã£ãŠãããšãã«ã¯ error ãééã£ãŠããªããšãã«ã¯ correct ãšäžè¡ã§åºåããŠãã ããã Sample Input 1 1 a 1 10 3 10 a / Output for the Sample Input 1 correct Sample Input 2 2 a 1 10 b 1 10 5 1 a b - / Output for the Sample Input 2 error Sample Input 3 1 a 0 255 7 1 a 2 * 1 + / Output for the Sample Input 3 correct | 35,282 |
Score : 200 points Problem Statement You have an integer variable x . Initially, x=0 . Some person gave you a string S of length N , and using the string you performed the following operation N times. In the i -th operation, you incremented the value of x by 1 if S_i= I , and decremented the value of x by 1 if S_i= D . Find the maximum value taken by x during the operations (including before the first operation, and after the last operation). Constraints 1â€Nâ€100 |S|=N No characters except I and D occur in S . Input The input is given from Standard Input in the following format: N S Output Print the maximum value taken by x during the operations. Sample Input 1 5 IIDID Sample Output 1 2 After each operation, the value of x becomes 1 , 2 , 1 , 2 and 1 , respectively. Thus, the output should be 2 , the maximum value. Sample Input 2 7 DDIDDII Sample Output 2 0 The initial value x=0 is the maximum value taken by x , thus the output should be 0 . | 35,283 |
Building a Space Station You are a member of the space station engineering team, and are assigned a task in the construction process of the station. You are expected to write a computer program to complete the task. The space station is made up with a number of units, called cells. All cells are sphere-shaped, but their sizes are not necessarily uniform. Each cell is fixed at its predetermined position shortly after the station is successfully put into its orbit. It is quite strange that two cells may be touching each other, or even may be overlapping. In an extreme case, a cell may be totally enclosing another one. I do not know how such arrangements are possible. All the cells must be connected, since crew members should be able to walk from any cell to any other cell. They can walk from a cell A to another cell B, if, (1) A and B are touching each other or overlapping, (2) A and B are connected by a `corridor', or (3) there is a cell C such that walking from A to C, and also from B to C are both possible. Note that the condition (3) should be interpreted transitively. You are expected to design a configuration, namely, which pairs of cells are to be connected with corridors. There is some freedom in the corridor configuration. For example, if there are three cells A, B and C, not touching nor overlapping each other, at least three plans are possible in order to connect all three cells. The first is to build corridors A-B and A-C, the second B-C and B-A, the third C-A and C-B. The cost of building a corridor is proportional to its length. Therefore, you should choose a plan with the shortest total length of the corridors. You can ignore the width of a corridor. A corridor is built between points on two cells' surfaces. It can be made arbitrarily long, but of course the shortest one is chosen. Even if two corridors A-B and C-D intersect in space, they are not considered to form a connection path between (for example) A and C. In other words, you may consider that two corridors never intersect. Input The input consists of multiple data sets. Each data set is given in the following format. n x 1 y 1 z 1 r 1 x 2 y 2 z 2 r 2 ... x n y n z n r n The first line of a data set contains an integer n , which is the number of cells. n is positive, and does not exceed 100. The following n lines are descriptions of cells. Four values in a line are x- , y- and z- coordinates of the center, and radius (called r in the rest of the problem) of the sphere, in this order. Each value is given by a decimal fraction, with 3 digits after the decimal point. Values are separated by a space character. Each of x , y , z and r is positive and is less than 100.0. The end of the input is indicated by a line containing a zero. Output For each data set, the shortest total length of the corridors should be printed, each in a separate line. The printed values should have 3 digits after the decimal point. They may not have an error greater than 0.001. Note that if no corridors are necessary, that is, if all the cells are connected without corridors, the shortest total length of the corridors is 0.000. Sample Input 3 10.000 10.000 50.000 10.000 40.000 10.000 50.000 10.000 40.000 40.000 50.000 10.000 2 30.000 30.000 30.000 20.000 40.000 40.000 40.000 20.000 5 5.729 15.143 3.996 25.837 6.013 14.372 4.818 10.671 80.115 63.292 84.477 15.120 64.095 80.924 70.029 14.881 39.472 85.116 71.369 5.553 0 Output for the Sample Input 20.000 0.000 73.834 | 35,284 |
Score : 400 points Problem Statement Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r -th row from the top and the c -th column from the left. Each square is painted black or white. The grid is said to be good if and only if the following condition is satisfied: From (1, 1) , we can reach (H, W) by moving one square right or down repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W) . For each pair r, c ( r_0 \leq r \leq r_1, c_0 \leq c \leq c_1 ), invert the color of (r, c) - that is, from white to black and vice versa. Constraints 2 \leq H, W \leq 100 Input Input is given from Standard Input in the following format: H W s_{11} s_{12} \cdots s_{1W} s_{21} s_{22} \cdots s_{2W} \vdots s_{H1} s_{H2} \cdots s_{HW} Here s_{rc} represents the color of (r, c) - # stands for black, and . stands for white. Output Print the minimum number of operations needed. Sample Input 1 3 3 .## .#. ##. Sample Output 1 1 Do the operation with (r_0, c_0, r_1, c_1) = (2, 2, 2, 2) to change just the color of (2, 2) , and we are done. Sample Input 2 2 2 #. .# Sample Output 2 2 Sample Input 3 4 4 ..## #... ###. ###. Sample Output 3 0 No operation may be needed. Sample Input 4 5 5 .#.#. #.#.# .#.#. #.#.# .#.#. Sample Output 4 4 | 35,285 |
Loading Aizu Ocean Transport Company (AOTC) accepted a new shipping order. The pieces of the cargo included in this order all have the same square footprint (2m x 2m). The cargo room has a rectangular storage space of 4m width with various longitudinal extents. Each pieces of cargo must be placed in alignment with partition boundaries which form a 1m x 1m square grid. A straddling arrangement with a neighboring partition (for example, protrusion by 50 cm) is not allowed. Neither an angled layout nor stacked placement are allowed. Note also that there may be some partitions on which any cargo loading is prohibited. AOTC wishes to use the currently available ship for this consignment and needs to know how many pieces of cargo it can accommodate. Make a program to report the maximum cargo capacity of the cargo space given the following information: the depth (m) of the cargo space and the loading-inhibited partitions. Input The input is given in the following format. H N x_1 y_1 x_2 y_2 : x_N y_N The first line provides the longitudinal depth H (2 †H †10 4 ) of the cargo space in meters and the number of load-inhibited partitions N (0 †N †4 à 10 4 ). Each of the subsequent N lines defines the position of the i -th load-inhibited partition x_i (0 †x_i †3) and y_i (0 †y_i †H -1) in integers, where x = 0 and y = 0 indicate the bottom-left corner partition. A load-inhibited partition appears only once in the list. Output Output the maximum number of cargo pieces loaded into the cargo space. Sample Input 1 5 3 0 1 1 2 3 3 Sample Output 1 2 Input example 1 corresponds to the cargo layout shown in the left-most figure. Sample Input 2 6 4 0 2 1 3 3 4 0 5 Sample Output 2 4 | 35,286 |
Minimum-Cost Arborescence Find the sum of the weights of edges of the Minimum-Cost Arborescence with the root r for a given weighted directed graph G = ( V , E ). Input |V| |E| r s 0 t 0 w 0 s 1 t 1 w 1 : s |E|-1 t |E|-1 w |E|-1 , where |V| is the number of vertices and |E| is the number of edges in the graph. The graph vertices are named with the numbers 0, 1,..., |V| -1 respectively. r is the root of the Minimum-Cost Arborescence. s i and t i represent source and target verticess of i -th directed edge. w i represents the weight of the i -th directed edge. Output Print the sum of the weights the Minimum-Cost Arborescence. Constraints 1 †|V| †100 0 †|E| †1,000 0 †w i †10,000 G has arborescence(s) with the root r Sample Input 1 4 6 0 0 1 3 0 2 2 2 0 1 2 3 1 3 0 1 3 1 5 Sample Output 1 6 Sample Input 2 6 10 0 0 2 7 0 1 1 0 3 5 1 4 9 2 1 6 1 3 2 3 4 3 4 2 2 2 5 8 3 5 3 Sample Output 2 11 | 35,287 |
E - ãããã åéã®ããªããã€ãã®ããã¯ïŒä»æ¥ã¯äžäººã§ããããéã³ãããŠéããããšã«ããïŒ åé¢ã«æŽæ° a_1,a_2,a_3,a_4,a_5,a_6 ãæžããã6é¢ãã€ã¹ãšïŒé§ãšïŒçŽç·äžã«Måã®ãã¹ããã å·Šããé ã« 1 ãã M ãŸã§ã®çªå·ãå²ãåœãŠãããããããç€ãçšããããšã«ããïŒ ããããç€ã®åãã¹ã«ã¯æç€ºãæ°åã§æžãããŠããïŒ i çªç®ã®ãã¹ã«ã¯æ°å N_i ãæžãããŠããïŒ ããã¯ïŒãã®å€ãæ£ãªãå³ïŒè² ãªãå·Šã«ïŒãã®çµ¶å¯Ÿå€ã ãé§ãç§»åãããšããæå³ã§ããïŒ ããªãã¡ïŒ i+N_i çªç®ã®ãã¹ã«é§ãç§»åãããšããæå³ã§ããïŒ ããã¯ïŒä»¥äžã®ããã«ããŠããããéã³ãããïŒãŸãé§ãã¹ã¿ãŒãå°ç¹ã«çœ®ãïŒ æ¬¡ã«ãµã€ã³ããæ¯ãïŒãµã€ã³ããåºãç®ã®æ°ãèŠãŠïŒé§ããçŸåšã®ãã¹ããå³ã«ç§»åãããã ãå·Šã«ç§»åãããããçŸåšã®ãã¹ã«çãŸããããéžæããããšãã§ããïŒ ãã¹ããç§»åããå Žåã¯ïŒãµã€ã³ãã®åºç®ã®è·é¢ã ãé§ãç§»åããŠïŒç§»åããå
ã®ãã¹ã®æç€ºã«åŸãïŒ æç€ºã«åŸã£ãŠç§»åããå
ã®ãã¹ã®æç€ºã«ã¯åŸããªãïŒ ä»¥åŸïŒããã¯äžèšã®ããã«ãµã€ã³ããæ¯ã£ãŠé§ãç§»åããããšãç¹°ãè¿ãïŒ ç§»åããçµæããããç€ã®å€ã«é§ãåºãŠããŸã£ããããã®è² ãã§ããïŒèª€ç( Wrong Answer )ãšå€å®ãããïŒ ãã®åé¡ã®ç®çã¯ãã®ããããããŽãŒã«ããããšã§ããïŒãµã€ã³ããæ¯ãåæ°ã¯3000å以äžãšããïŒ å
¥åºååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ M a_1 a_2 a_3 a_4 a_5 a_6 s g N_1 ... N_M M ã¯ããããç€ã®ãã¹ã®æ°ã§ããïŒ a_1 ... a_6 ã¯ãµã€ã³ãã®åé¢ã«æžãããŠããæŽæ°ã®å€ã§ããïŒ s ãš g ã¯ããããããããç€ã®ã¹ã¿ãŒããšãŽãŒã«ã®çªå·ã§ããïŒ N_i 㯠i çªç®ã®ãã¹ã«æžãããŠããæç€ºã§ããïŒ ãããã®å
¥åã®åŸïŒ ãããããæ¯ã£ãçµæã衚ãå€ dice ãæ¹è¡ãšãšãã«åŒãç¶ããŠå
¥åããäžããããïŒ ããã¯ïŒãµã€ã³ããæ¯ã£ãŠåºãç®ã a dice ã§ããããšã衚ãïŒ ããã«å¯ŸããŠïŒããªãã®ããã°ã©ã ã¯é§ãé²ãããã©ãããæ±ºãïŒãã®éžæãåºåããªããã°ãªããªãïŒé§ãå³ã«ç§»åãããªãã° 1 ãïŒå·Šã«ç§»åãããªãã° -1 ãïŒçŸåšã®ãã¹ã«çãŸããªãã° 0 ãåºåããïŒåºåã®åŸã«ã¯æ¹è¡ãåºåããïŒ ããªãã®ããã°ã©ã ãé²ããæ»ããçãŸãããåºåãããšïŒæ¬¡ã®ãµã€ã³ããæ¯ã£ãçµæãå
¥åããåãåãããšãã§ããïŒãããç¹°ãè¿ãïŒ äŸãã°C/C++ã§ã¯ scanf("%d", &dice); ãšããŠãµã€ã³ãã®é¢ã®çªå·ãåãåãïŒããã«å¯ŸããŠå·Šã«ç§»åãããªã printf("-1\n"); fflush(stdout); ãšããïŒæ¬¡ã«ïŒ scanf("%d", &dice); ãšãããšïŒæ¬¡ã®ãµã€ã³ãã®é¢ã®çªå·ãåãåãããšãåºæ¥ãïŒããããã«ãŽãŒã«ãããçŽã¡ã«ããã°ã©ã ãçµäºããïŒ ãŽãŒã«ã«èŸ¿ãçããŸã§ã«ãµã€ã³ããæ¯ãåæ°ã¯3000å以äžã§ãªããã°ãªããªãïŒ ãµã€ã³ããæ¯ã£ãåæ°ãéäžã§3000åãè¶
ããå ŽåïŒèª€çãšå€å®ãããïŒ å¶çŽ 2 †M †300 1 †s †M, 1 †g †M s \neq g 1 †a_i †M-1 1 †dice †6 N_s = N_g = 0 ãã¹ã®åœä»€ã«åŸã£ãŠé§ãé²ããŠæ å€ã«åºãäºã¯ãªãïŒ dice 㯠\{1,2,âŠ,6\} ããæ¬äŒŒä¹±æ°ã§äžæ§ã©ã³ãã ã«éžã°ããïŒ ããããµã€ã³ããæ¯ã£ããšããŠããŽãŒã«ã§ããªãç€é¢ã¯äžããããªãïŒ å
¥åã®å€ã¯å
šãп޿°ã§ããïŒ å
¥åºåäŸ1 ããããã®èª¬æ ããã°ã©ã ã®åºå ããã°ã©ã ãžã®å
¥å ãµã€ã³ãã®ç® é§ã®ç§»ååŸã®ãã¹ã®çªå· 10 1 6 2 5 3 4 1 10 0 -1 3 -1 3 -2 -6 -5 -7 0 1åç®ã®ãµã€ã³ã 1 1 1åç®ã®ããã°ã©ã ã®åºå 0 1 2åç®ã®ãµã€ã³ã 3 2 2åç®ã®ããã°ã©ã ã®åºå 1 6 3åç®ã®ãµã€ã³ã 5 3 3åç®ã®ããã°ã©ã ã®åºå 0 6 4åç®ã®ãµã€ã³ã 1 1 4åç®ã®ããã°ã©ã ã®åºå -1 8 5åç®ã®ãµã€ã³ã 3 2 5åç®ã®ããã°ã©ã ã®åºå 1 10 | 35,288 |
Eulerian Flight Tour You have an airline route map of a certain region. All the airports in the region and all the non-stop routes between them are on the map. Here, a non-stop route is a flight route that provides non-stop flights in both ways. Named after the great mathematician Leonhard Euler, an Eulerian tour is an itinerary visiting all the airports in the region taking a single flight of every non-stop route available in the region. To be precise, it is a list of airports, satisfying all of the following. The list begins and ends with the same airport. There are non-stop routes between pairs of airports adjacent in the list. All the airports in the region appear at least once in the list. Note that it is allowed to have some airports appearing multiple times. For all the airport pairs with non-stop routes in between, there should be one and only one adjacent appearance of two airports of the pair in the list in either order. It may not always be possible to find an Eulerian tour only with the non-stop routes listed in the map. Adding more routes, however, may enable Eulerian tours. Your task is to find a set of additional routes that enables Eulerian tours. Input The input consists of a single test case. $n$ $m$ $a_1$ $b_1$ ... $a_m$ $b_m$ $n$ ($3 \leq n \leq 100$) is the number of airports. The airports are numbered from 1 to $n$. $m$ ($0 \leq m \leq \frac{n(n-1)}{2}$) is the number of pairs of airports that have non-stop routes. Among the $m$ lines following it, integers $a_i$ and $b_i$ on the $i$-th line of them ($1 \leq i \leq m$) are airport numbers between which a non-stop route is operated. You can assume $1 \leq a_i < b_i \leq n$, and for any $i \ne j$, either $a_i \ne a_j$ or $b_i \ne b_j$ holds. Output Output a set of additional non-stop routes that enables Eulerian tours. If two or more different sets will do, any one of them is acceptable. The output should be in the following format. $k$ $c_1$ $d_1$ ... $c_k$ $d_k$ $k$ is the number of non-stop routes to add, possibly zero. Each of the following $k$ lines should have a pair of integers, separated by a space. Integers $c_i$ and $d_i$ in the $i$-th line ($c_i < d_i$) are airport numbers specifying that a non-stop route is to be added between them. These pairs, ($c_i, d_i$) for $1 \leq i \leq k$, should be distinct and should not appear in the input. If adding new non-stop routes can never enable Eulerian tours, output -1 in a line. Sample Input 1 4 2 1 2 3 4 Sample Output 1 2 1 4 2 3 Sample Input 2 6 9 1 4 1 5 1 6 2 4 2 5 2 6 3 4 3 5 3 6 Sample Output 2 -1 Sample Input 3 6 7 1 2 1 3 1 4 2 3 4 5 4 6 5 6 Sample Output 3 3 1 5 2 4 2 5 Sample Input 4 4 3 2 3 2 4 3 4 Sample Output 4 -1 Sample Input 5 5 5 1 3 1 4 2 4 2 5 3 5 Sample Output 5 0 | 35,289 |
Problem H: ãããããªïŒ ãããšããã«ïŒæ¥æ¬åå°ããŸãããªããå売ããã瀟é·ãããïŒ åœŒã¯ããæ¥ïŒäžæè°ãªå笊ãæã«å
¥ããïŒ ãã®å笊ã䜿ããšïŒãªããšç®çå°ãŸã§ã®è·é¢ã«ãããé»è»ã®éè³ãç¡æã«ãªããšããïŒ ãã ãïŒ çŸåšã®é§
ãã飿¥ããé§
ãžç§»åããã®ã1ã¹ããããšæ°ãããšãã«ïŒ ç§»åããã¹ãããæ°ãã¡ããã©åç¬Šã«æžãããæ°ãšçãããªããªããš è¿œå æéãåãããŠããŸãïŒ ããåºéããã ã¡ã«æãè¿ããããªç§»åã¯çŠæ¢ãããŠãããïŒ æ¢ã«èšªããé§
ãåºéãè€æ°åéãããšèªäœã¯èš±ãããïŒ ããšãã°ïŒé§
1ã»é§
2ã»é§
1ãšç§»åããããšã¯ã§ããªããïŒ é§
1ã»é§
2ã»é§
3ã»é§
1ã»é§
2ã®ãããªç§»åã¯åé¡ãªãïŒ ãŸãïŒæçµçã«ç®çå°ã«å°çãããªãã°ïŒåºçºå°ãç®çå°ãäœåºŠã§ãéã£ãŠããïŒ ç€Ÿé·ã¯ãã£ãããã®åç¬Šãæ¬¡ã®ç®çå°ã«è¡ãããã«äœ¿ã£ãŠã¿ãããšèããïŒ ãããè·¯ç·å³ã¯å
¥ãçµãã§ããããïŒç°¡åã«ã¯çµè·¯ãå®ãŸããªãïŒ ããªãã®ä»äºã¯ïŒç€Ÿé·ã«ä»£ãã£ãŠç®çå°ã«ç¡æã§å°éã§ãããã©ããã å€å®ããããã°ã©ã ãæžãããšã§ããïŒ é§
㯠1 ãã N ãŸã§ã®çªå·ãæ¯ãããŠããïŒ åºçºå°ã®é§
㯠1ïŒç®çå°ã®é§
㯠N ãšæ±ºãŸã£ãŠããïŒ è·¯ç·å³ã¯2ã€ã®é§
ãçµã¶åºéã®åã«ãã£ãŠäžããããïŒ åºéã¯ã©ã¡ãã®æ¹åã«ãéè¡ããããšãã§ããïŒ åãé§
å士ãçµã¶ãããªåºéã¯ååšããªãããšãšïŒ ããé§
ã®å¯Ÿãçµã¶åºéã¯ããã ã1ã€ã§ããããšãä¿èšŒãããŠããïŒ Input å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒ ããããã®ããŒã¿ã»ããã¯æ¬¡ã®ãããªåœ¢åŒã§äžããããïŒ N M Z s 1 d 1 s 2 d 2 ... s M d M N ã¯é§
ã®ç·æ°ïŒ M ã¯åºéã®ç·æ°ã§ããïŒ Z ã¯åç¬Šã«æžãããã¹ãããæ°ã§ããïŒ s i ãš d i (1 †i †M) ã¯é§
ã®çªå·ãè¡šãæŽæ°ã§ããïŒ ããããé§
s i ãšé§
d i ã®éã«åºéãååšããããšã衚çŸããŠããïŒ N , M , Z ã¯æ£ã®æŽæ°ã§ããïŒæ¬¡ã®æ¡ä»¶ãæºããïŒ 2 †N †50, 1 †M †50, 0 < Z < 2 31 ïŒ æåŸã®ããŒã¿ã»ããã®åŸãã«ïŒ â 0 0 0 â ãšæžããã1è¡ãããïŒ ããŒã¿ã»ããã®æ°ã¯30ãè¶ããªãïŒ Output ããããã®ããŒã¿ã»ããã«å¯ŸãïŒ ãã±ããã«æžãããŠããã¹ãããæ°ã¡ããã©ã§ ç®çå°ã«å°éã§ãããªãã° â yes âïŒ å°éã§ããªããªãã° â no â ã®ã¿ãå«ã1è¡ã®æååãåºåããïŒ Sample Input 2 1 1 1 2 2 1 2 1 2 3 1 2 1 2 8 8 5778 1 2 2 3 2 4 3 5 5 6 6 7 7 8 4 8 8 8 5777 1 2 2 3 2 4 3 5 5 6 6 7 7 8 4 8 0 0 0 Output for the Sample Input yes no no yes no | 35,290 |
Score : 400 points Problem Statement Given a string t , we will call it unbalanced if and only if the length of t is at least 2 , and more than half of the letters in t are the same. For example, both voodoo and melee are unbalanced, while neither noon nor a is. You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s . Constraints 2 ⊠|s| ⊠10^5 s consists of lowercase letters. Partial Score 200 points will be awarded for passing the test set satisfying 2 ⊠N ⊠100 . Input The input is given from Standard Input in the following format: s Output If there exists no unbalanced substring of s , print -1 -1 . If there exists an unbalanced substring of s , let one such substring be s_a s_{a+1} ... s_{b} (1 ⊠a < b ⊠|s|) , and print a b . If there exists more than one such substring, any of them will be accepted. Sample Input 1 needed Sample Output 1 2 5 The string s_2 s_3 s_4 s_5 = eede is unbalanced. There are also other unbalanced substrings. For example, the output 2 6 will also be accepted. Sample Input 2 atcoder Sample Output 2 -1 -1 The string atcoder contains no unbalanced substring. | 35,291 |
ç匟ã®é£é 瞊 8ãæšª 8 ã®ãã¹ãããªãå³1 ã®ãããªå¹³é¢ããããŸãããã®å¹³é¢äžã«ãããã€ãã®ç匟ã眮ãããŠããŸããå³2 ã«ãã®äŸã瀺ããŸãïŒâ = ç匟ïŒã â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â â¡ â¡ â â¡ â¡ â¡ â¡ â¡ â¡ â â¡ â¡ â â¡ â¡ â¡ â â¡ â¡ â â¡ â¡ â â¡ â¡ â¡ â â¡ â¡ â â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â â¡ â¡ â¡ â â¡ â â¡ â¡ â¡ â â¡ â¡ â â¡ â â¡ â¡ â â¡ å³1 å³2 ç匟ãççºãããšããã®ç匟ã®äžäžå·Šå³ 3 ãã¹ã«ç颚ã®åœ±é¿ãåã³ããããã®ãã¹ã«çœ®ãããŠããç匟ãé£éçã«ççºããŸããããšãã°ãå³ 3 ã«ç€ºãç匟ãççºãããšå³ 4 ã®â ã®ãã¹ã«ç颚ã®åœ±é¿ãåã³ãŸãã â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â â¡ â¡ â¡ â¡ â¡ â¡ â¡ â â¡ â¡ â¡ â¡ â¡ â¡ â¡ â â¡ â¡ â¡ â¡ â â â â â â â â¡ â¡ â¡ â¡ â â¡ â¡ â¡ â¡ â¡ â¡ â¡ â â¡ â¡ â¡ â¡ å³3 å³4 ç匟ã眮ãããŠããç¶æ
ãšæåã«ççºããç匟ã®äœçœ®ãèªã¿èŸŒãã§ãæçµçãªå¹³é¢ã®ç¶æ
ãåºåããããã°ã©ã ãäœæããŠãã ããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã n ïŒç©ºè¡ïŒ ããŒã¿ã»ãã 1 ïŒç©ºè¡ïŒ ããŒã¿ã»ãã 2 .. .. ããŒã¿ã»ãã n ïŒè¡ç®ã«ããŒã¿ã»ããã®æ° n ( n †20) ãäžããããŸããç¶ã㊠n åã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã®çŽåã«ïŒã€ã®ç©ºè¡ãäžããããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã g 1,1 g 2,1 ... g 8,1 g 1,2 g 2,2 ... g 8,2 : g 1,8 g 2,8 ... g 8,8 X Y æåã®ïŒè¡ã«ãå¹³é¢ã衚ãïŒã€ã®æååãäžããããŸããåæååã¯ïŒæåãããªãæ°åã§ãç匟ã眮ãããŠãããã¹ã 1ã眮ãããŠããªããã¹ã 0 ã§è¡šããŸãã ç¶ãïŒè¡ã§ãæåã«ççºããç匟㮠X 座æšãš Y 座æšãäžããããŸããå·Šäžãå·Šäžãå³äžãå³äžã®åº§æšããããããã(1, 1)ã(1, 8)ã(8, 1)ã(8, 8) ã§ããäŸãã°ãå³ 4 ã«ç€ºãç匟ãæåã«ççºãããšããäžãããã座æšã¯ (4, 6) ã§ãã Output åããŒã¿ã»ããã«ã€ããŠä»¥äžã®ããã«åºåããŠäžããã ççºããªãã§æ®ã£ãç匟ã®ãããã¹ã 1ãç匟ã®ãªããã¹ã 0 ã§è¡šçŸããããšãšããŸããå¹³é¢ã®äžè¡ãæ°å 8 åãããªãäžè¡ãšã 8 è¡ã®æååã§æçµçãªå¹³é¢ã®ç¶æ
ãåºåããŠãã ãããåããŒã¿ã»ããã®å
é ã¯ããµã³ãã«åºåã®ããã« Data x : ããåºåããªããã°ãªããŸãããããã§ã x ã¯ããŒã¿ã»ããã®çªå·ã§ãã Sample Input 2 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 Output for the Sample Input Data 1: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Data 2: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 | 35,292 |
äžè§åœ¢ã®åæ°ã®å 座æšå¹³é¢äžã®åç¹$O$ãå·Šäžã座æš$(W,H)$ã«ããç¹ãå³äžãšããé·æ¹åœ¢ã®é åãäžããããŠããŸãããã®é åã«å«ãŸããã$x$座æšãš$y$座æšããšãã«æŽæ°ã§ããç¹ãïŒå以äžå«ãç¹ã®éãŸããèããŸãããã®ãããªç¹ã®éãŸãã®ãã¹ãŠã®çµã¿åããã®åæ°ã$N$ãšããç¹ã®éãŸãã®ããããã$D_1, D_2, ..., D_N$ã§è¡šãããšãã$D_1, D_2, ..., D_N$ã®ããããã«å«ãŸããç¹ãé ç¹ãšããäžè§åœ¢ãèããŸãã ããšãã°ãå³ã®ããã«$W=H=1$ã®ãšããç¹$O(0,0)$ã$A(1,0)$ã$B(1,1)$ã$C(0,1)$ã®ãã¡ãïŒå以äžå«ãç¹ã®éãŸãã¯$\{O,A,B\}$ã$\{O,A,C\}$ã$\{O,B,C\}$ã$\{A,B,C\}$ã$\{O,A,B,C\}$ã®ïŒã€ã§ãããã®äŸã®å Žåãç¹ã®éãŸãã®ããããã«å«ãŸããäžè§åœ¢ã¯æ¬¡ã®ããã«ãªããŸãã $\{O,A,B\}$ã«å«ãŸããäžè§åœ¢ã¯$OAB$ã®ã¿ã $\{O,A,C\}$ã«å«ãŸããäžè§åœ¢ã¯$OAC$ã®ã¿ã $\{O,B,C\}$ã«å«ãŸããäžè§åœ¢ã¯$OBC$ã®ã¿ã $\{A,B,C\}$ã«å«ãŸããäžè§åœ¢ã¯$ABC$ã®ã¿ã $\{O,A,B,C\}$ã«å«ãŸããäžè§åœ¢ã¯$OAB$ã$OAC$ã$OBC$ã$ABC$ã®ïŒåã ãã®äŸãããããããã«ãåãäžè§åœ¢ãïŒã€ä»¥äžã®ç¹ã®éãŸãã«å«ãŸããå ŽåããããŸããããšãã°ãäžè§åœ¢$OAB$ã¯ç¹ã®éãŸã$\{O,A,B\}$ã«ã$\{O,A,B,C\}$ã«ãå«ãŸããŸãã $W$ãš$H$ãäžãããããç¹ã®éãŸã$D_1, D_2, ..., D_N$ããããã«å«ãŸããç¹ãé ç¹ãšããäžè§åœ¢ã®åæ°ã$t_1, t_2, ..., t_N$ãšãããšããäžè§åœ¢ã®åæ°ã®å$t_1+t_2+...+t_N$ãèšç®ããããã°ã©ã ãäœæããã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $W$ $H$ ïŒè¡ã«$W$ãš$H$ ($1 \leq W,H \leq 1,000$)ãäžããããã åºå ããããã®ç¹ã®éãŸãã«å«ãŸããäžè§åœ¢ã®åæ°ã®åã1,000,000,007ã§å²ã£ãäœããïŒè¡ã«åºåããã å
¥åºåäŸ å
¥åäŸïŒ 1 1 åºåäŸïŒ 8 å
¥åäŸïŒ 1 2 åºåäŸïŒ 144 å
¥åäŸïŒ 100 100 åºåäŸïŒ 879128399 | 35,293 |
Problem L: Select Sets Problem æŽæ°ã®éåã N åããã ãããã®éåã«ã¯ãããã1ãã N ãŸã§ã®çªå·ãå²ãæ¯ãããŠããã i çªç®ã®éåã®èŠçŽ æ°ã¯ K i ã§ããããã®éåã®èŠçŽ ã®äžã§ j çªç®ã«å°ããæŽæ°ã¯ a i,j ã§ããã 倪éåã¯ãã®äžããä»»æã®æ°ã ãéåãéžã¶ããšã«ãªã£ãã ãã é©åœã«éžã¶ã ãã§ã¯ã€ãŸããªããšæã£ã倪éåã¯ãå°ãªããšã3ã€ã®éåãéžã¶ããšã«ããããŸãã"éžãã éåã®åéåã®èŠçŽ æ°"ãš"éžãã éåã®ç©éåã®èŠçŽ æ°"ã®ç©ãã§ããã ã倧ãããªãããã«éžã¶ããšã«ããã 倪éåãæé©ã«éåãéžãã ãšãã"éžãã éåã®åéåã®èŠçŽ æ°"ãš"éžãã éåã®ç©éåã®èŠçŽ æ°"ã®ç©ã®æå€§å€ãæ±ããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N K 1 a 1,1 a 1,2 ... a 1,K 1 K 2 a 2,1 a 2,2 ... a 2,K 2 ... K N a N,1 a N,2 ... a N,K N Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã å
¥åã¯å
šãп޿°ã§ããã 3 †N †20,000 1 †a i,j †22 a i,j < a i,j+1 ( 1 †i †N ) ( 1 †j < K i ) Output 倪éåãæé©ã«éžãã ãšãã®"éžãã éåã®åéåã®èŠçŽ æ°"ãš"éžãã éåã®ç©éåã®èŠçŽ æ°"ã®ç©ã®æå€§å€ãåºåããã Sample Input 1 4 1 5 2 3 5 3 3 5 7 4 3 5 7 9 Sample Output 1 8 Sample Input 2 5 4 1 4 5 6 4 1 7 8 9 3 1 2 3 3 1 2 3 3 1 2 3 Sample Output 2 9 Sample Input 3 3 2 3 4 2 2 5 2 1 6 Sample Output 3 0 | 35,294 |
åºå£èª¿æ» ãããããŒãã§è²·ãç©éé¡ã®åºå£èª¿æ»ãè¡ããŸãããè²·ãç©éé¡ã®ããŒã¿ãå
¥åãšãã1 人ãããã®å¹³åè²·ãç©éé¡ãèšç®ããåºåããããã°ã©ã ãäœæããŠãã ããã調æ»äººæ°ã¯ã10 äžäººä»¥äžãšããäžäººãããã®è²·ãç©éé¡ã¯ 100 äžåãè¶
ããªããã®ãšããŸãã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã n v 1 v 2 : v n 1 è¡ç®ã«èª¿æ»äººæ° n ãç¶ã n è¡ã« i 人ç®ã®è²·ãç©éé¡ãè¡šãæŽæ° v i ãäžããããŸãã Output å¹³åè²·ãç©éé¡ïŒæŽæ°ïŒå°æ°ç¹ä»¥äžã¯åãæšãŠïŒãïŒè¡ã«åºåããŠãã ããã Sample Input 6 12300 5600 33800 0 26495 52000 Output for the Sample Input 21699 | 35,295 |
Score : 100 points Problem Statement You are given an array a_0, a_1, ..., a_{N-1} of length N . Process Q queries of the following types. 0 p x : a_p \gets a_p + x 1 l r : Print \sum_{i = l}^{r - 1}{a_i} . Constraints 1 \leq N, Q \leq 500,000 0 \leq a_i, x \leq 10^9 0 \leq p < N 0 \leq l_i < r_i \leq N All values in Input are integer. Input Input is given from Standard Input in the following format: N Q a_0 a_1 ... a_{N - 1} \textrm{Query}_0 \textrm{Query}_1 : \textrm{Query}_{Q - 1} Output For each query of the latter type, print the answer. Sample Input 1 5 5 1 2 3 4 5 1 0 5 1 2 4 0 3 10 1 0 5 1 0 3 Sample Output 1 15 7 25 6 | 35,296 |
éç (Pencils) å顿 JOI åã¯éçã N æ¬è²·ãããã«è¿ãã®ææ¿å
·åºã«è¡ãããšã«ããïŒ ææ¿å
·åºã§ã¯éçãäžå®ã®æ¬æ°ãã€ã®ã»ããã§å£²ãããŠããïŒã»ãã X 㯠A æ¬ã§ B åïŒã»ãã Y 㯠C æ¬ã§ D åã§ããïŒ JOI åã¯ã»ãã X ãã»ãã Y ã®äžæ¹ãéžã³ïŒéžãã ã»ãããããã€ã賌å
¥ããïŒäž¡æ¹ã®ã»ããã賌å
¥ããããšã¯ã§ããªãïŒ N æ¬ä»¥äžã®éçãåŸãããã«å¿
èŠãªéé¡ã®æå°å€ãæ±ããïŒ å¶çŽ 1 \leq N \leq 1000 1 \leq A \leq 1000 1 \leq B \leq 1000 1 \leq C \leq 1000 1 \leq D \leq 1000 å
¥åã»åºå å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããïŒ N A B C D åºå JOI åã N æ¬ä»¥äžã®éçãæã«å
¥ããã®ã«å¿
èŠãªéé¡ã®æå°å€ãåºåããïŒ å
¥åºåäŸ å
¥åäŸ 1 10 3 100 5 180 åºåäŸ 1 360 JOI åã¯10æ¬ã®éçãå
¥æãããïŒã»ãã X ã¯3æ¬ã§100åïŒã»ãã Y ã¯5æ¬ã§180åã§ããïŒãã®æïŒã»ãã X ãéžãã å Žåã¯ïŒã»ããã4ã€è³Œå
¥ããå¿
èŠããã400åå¿
èŠã§ããïŒã»ãã Y ãéžãã å Žåã¯ïŒã»ããã2ã€è³Œå
¥ããå¿
èŠããã360åå¿
èŠã§ããïŒãããã£ãŠïŒå¿
èŠãªéé¡ã®æå°å€ã¯400åãš360åã®å°ããæ¹ã§360åã§ããïŒ å
¥åäŸ 2 6 2 200 3 300 åºåäŸ 2 600 ãã®ãšãïŒã»ãã X ãéžãã å Žåãã»ãã Y ãéžãã å Žåãå¿
èŠãªéé¡ã¯600åã§ããïŒå¿
èŠãªéé¡ã®æå°å€ã¯600åã§ããïŒ æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒäœ ã第 17 åæ¥æ¬æ
å ±ãªãªã³ãã㯠JOI 2017/2018 äºéžç«¶æèª²é¡ã | 35,297 |
å°åŠçã®ã€ã¯ã¿åã¯ãããæ¥ãããããããæ°åŒãæžãããçŽãããã£ãã ã©ããããããããã¯æ°åŒã®çãã®éé¡ã ããå°é£ããããããããã ã€ã¯ã¿åã¯ãŸã è¶³ãç®ãåŒãç®ãæãç®ããç¿ã£ãŠãªãã£ãã®ã§ãæ°åŒã«ãè¶³ãç®ãšåŒãç®ãšæãç®ãã䜿ãããŠããªãã éåžžã®èšç®ã§ã¯è¶³ãç®ãšåŒãç®ããæãç®ãå
ã«èšç®ããªããã°ãªããªãã®ã ããã€ã¯ã¿åã¯æŒç®åã®åªå
é äœã«ã€ããŠã®çè§£ããããµãã ã£ãã®ã§ããšããããæ°åŒã®èšç®çµæãæå€§ã«ãªããããªéœåã®è¯ãåªå
é äœãèããããšã«ããã +âà ã®3ã€ã®äºé
æŒç®åãšæ¬åŒ§ãå«ãæ°åŒãäžããããã 3ã€ã®æŒç®åã®åªå
é äœãä»»æã«å€æŽããŠãæ°åŒãæå€§åãããšãã®èšç®çµæãçããã ãã ãã以äžã®ç¹ã«æ³šæããã æŒç®åã¯å¿
ãå·Šçµåã§ããã (åãåªå
é äœã®æŒç®åã¯å¿
ãæ°åŒã®å·ŠåŽããèšç®ããã) ç°ãªãæŒç®åãåãåªå
é äœã§ãã£ãŠãããã äžã€ã®æ°åŒãèšç®ããŠããéäžã§åªå
é äœã倿ŽããŠã¯ãªããªãã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã 0ã9ã®æ°åãšæŒç®å'+','-','*'ãæ¬åŒ§'(',')'ã§æ§æãããæ°åŒ æ£ç¢ºã«èšè¿°ãããšå
¥åã¯ä»¥äžã®BNFã§ç€ºããã圢åŒã«ãªã£ãŠãã <expr> ::= ( <expr> ) | <number> | <expr> <op> <expr> <op> ::= + | - | * <number>ã¯éè² æŽæ°ã衚ãã Constraints å
¥åã¯ä»¥äžã®å¶çŽãæºããã æ°åŒã¯200æå以äžã§ããã ã©ã®ãããªåªå
é äœãèšå®ããŠããèšç®ã®çµæããã®éäžã§64bitæŽæ°åã§overflowãããããªããšã¯ãªãã Output æ°åŒããåŸãããæå€§å€ã1è¡ã§åºåããã Sample Input 1 3-2*3 Output for the Sample Input 1 3 *ã®åªå
é äœã-ããäœãããããšã§ãã®ããã«ãªãã Sample Input 2 (5-3*4)*(0-2+1) Output for the Sample Input 2 21 åªå
é äœã¯+>*>- Sample Input 3 1-2+3-4+5-6*0 Output for the Sample Input 3 3 åªå
é äœãäžè¬çãªå Žå Sample Input 4 (1989967-3*1-211+4487) Output for the Sample Input 4 8511076028 | 35,298 |
Score : 800 points Problem Statement There is a pond with a rectangular shape. The pond is divided into a grid with H rows and W columns of squares. We will denote the square at the i -th row from the top and j -th column from the left by (i,\ j) . Some of the squares in the pond contains a lotus leaf floating on the water. On one of those leaves, S , there is a frog trying to get to another leaf T . The state of square (i,\ j) is given to you by a character a_{ij} , as follows: . : A square without a leaf. o : A square with a leaf floating on the water. S : A square with the leaf S . T : A square with the leaf T . The frog will repeatedly perform the following action to get to the leaf T : "jump to a leaf that is in the same row or the same column as the leaf where the frog is currently located." Snuke is trying to remove some of the leaves, other than S and T , so that the frog cannot get to the leaf T . Determine whether this objective is achievable. If it is achievable, find the minimum necessary number of leaves to remove. Constraints 2 †H, W †100 a_{ij} is . , o , S or T . There is exactly one S among a_{ij} . There is exactly one T among a_{ij} . Input Input is given from Standard Input in the following format: H W a_{11} ... a_{1W} : a_{H1} ... a_{HW} Output If the objective is achievable, print the minimum necessary number of leaves to remove. Otherwise, print -1 instead. Sample Input 1 3 3 S.o .o. o.T Sample Output 1 2 Remove the upper-right and lower-left leaves. Sample Input 2 3 4 S... .oo. ...T Sample Output 2 0 Sample Input 3 4 3 .S. .o. .o. .T. Sample Output 3 -1 Sample Input 4 10 10 .o...o..o. ....o..... ....oo.oo. ..oooo..o. ....oo.... ..o..o.... o..o....So o....T.... ....o..... ........oo Sample Output 4 5 | 35,299 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.