AGM 2023, Final Round, Day 1
A. BaldTree
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output
Example
Input
9 6
1 1 1 3 2 4 4 7
1 1 1 4 2 3 5 8
Output
18

B. Balls
time limit per test
1.5 seconds
memory limit per test
262 megabytes
input
standard input
output
standard output
Example
Input
2
1 1 1
1 2 1
Output
420

C. Cycles
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output
Example
Input
5 2
3 5 2 4 1
2 3
1 4
Output
3
2

D. Exhausted
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output
Example
Input
7 50
2 1 20
3 1 19
4 2 17
5 3 16
6 3 13
7 4 18
Output
2 6

E. Football
time limit per test
5 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

F. ForkBomb
time limit per test
2 seconds
memory limit per test
262 megabytes
input
standard input
output
standard output
Example
Input
6
0 4 6 7 8 9
a = 3
for index in 1...1
b = 4
if fork() == 0
c = 3
else
c = 4
d = 1
fork()
d = 0
Output
1
1
1
2
2
4

G. Language
time limit per test
4 seconds
memory limit per test
524 megabytes
input
standard input
output
standard output
Examples
Input
3 6 1 0
2
0 1 0
0 1 1
1 2 0
1 2 1
2 0 0
2 0 1
5 10 2 0
2 4
0 1 0
1 2 0
1 2 1
2 0 0
2 0 1
0 3 1
3 4 0
3 4 1
4 0 0
4 0 1
Output
YES
Input
2 4 1 0
0
0 0 0
0 1 1
1 1 0
1 1 1
4 8 1 0
2
0 1 1
1 1 0
1 1 1
0 2 0
2 2 0
2 3 1
3 3 0
3 3 1
Output
NO

H. Matrix
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output
Example
Input
3 4
1 2 0
3 0 1
3 7 5
Output
Yes

I. Quarto
time limit per test
5 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output
Example
Input
1
15
0 0 WRSO
0 1 BRSH
0 2 BRLO
0 3 WCSO
1 0 WRSH
1 1 BCSH
1 2 WRLO
1 3 WCLH
2 0 BCLH
2 1 WRLH
2 2 BCLO
2 3 BCSO
3 0 BRSO
3 2 WCSH
3 3 BRLH
WCLO
Output
1

J. ConnectSquares
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output
Example
Input
3 3
1 0 1
0 0 0
1 1 0
Output
YES
1 2 2 
1 2 0 
1 2 0 

K. Tarot reading
time limit per test
3 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output
Example
Input
8 17 5
1 2 39 39
2 4 32 32
3 6 35 35
4 8 7 25
4 2 6 25
4 6 9 25
4 7 3 25
5 5 30 30
6 3 3 16
6 5 2 16
6 4 3 16
6 7 2 16
6 1 6 16
7 6 15 25
7 8 10 25
8 4 5 8
8 3 3 8
8 7 3
1 5 2
8 6 3
3 2 3
3 1 3
Output
1
1
1
1
1

L. Beautiful Trips
time limit per test
4 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output
Examples
Input
3 3 2
1 2
2 3
3 1
1 2 4
1 2 4
1 2 0
Output
6
4
Input
6 7 5
1 2
2 3
3 1
1 4
4 5
5 6
6 4
1 2 4 8 16 32
1 4 3
2 5 8
1 6 20
3 4 15
3 6 9
Output
11
40
52
14
41