Технокубок 2020 - Финал


A. Contest for Robots
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 1 1 0 0
0 1 1 1 1
Output
3
Input
3
0 0 0
0 0 0
Output
-1
Input
4
1 1 1 1
1 1 1 1
Output
-1
Input
8
1 0 0 0 0 0 0 0
0 1 1 0 1 1 1 1
Output
7
----------------------------------------------------------------------------------------------------
B. Journey Planning
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
10 7 1 9 10 15
Output
26
Input
1
400000
Output
400000
Input
7
8 9 26 11 12 29 14
Output
55
----------------------------------------------------------------------------------------------------
C. Remove Adjacent
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8
bacabcab
Output
4
Input
4
bcda
Output
3
Input
6
abbbbb
Output
5
----------------------------------------------------------------------------------------------------
D. Navigation System
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
6 9
1 5
5 4
1 2
2 3
3 4
4 1
2 6
6 4
4 2
4
1 2 3 4
Output
1 2
Input
7 7
1 2
2 3
3 4
4 5
5 6
6 7
7 1
7
1 2 3 4 5 6 7
Output
0 0
Input
8 13
8 7
8 6
7 5
7 4
6 5
6 4
5 3
5 2
4 3
4 2
3 1
2 1
1 8
5
8 7 5 2 1
Output
0 3
----------------------------------------------------------------------------------------------------
E. World of Darkraft: Battle for Azathoth
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
2 3 3
2 3
4 7
2 4
3 2
5 11
1 2 4
2 1 6
3 4 6
Output
1
----------------------------------------------------------------------------------------------------
F. Treeland and Viruses
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
7
1 2
1 3
2 4
2 5
3 6
3 7
3
2 2
4 1
7 1
1 3
2 2
4 3
7 1
1 3
3 3
1 1
4 100
7 100
1 2 3
Output
1 2
1 1
1 1 1
----------------------------------------------------------------------------------------------------
G. Reachable Strings
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
11011
3
1 3 3
1 4 2
1 2 3
Output
Yes
Yes
No
----------------------------------------------------------------------------------------------------
H. Blocks and Sensors
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4 3 2
1 4
3 2
6 5
1 4
3 2
6 7
1 4
1 4
0 0
0 7
6 5
6 5
0 0
0 7
1 3 6
1 3 6
0 0 0
0 0 7
4 3 5
4 2 5
0 0 0
0 0 7
Output
1 4
3 0
6 5
1 4
3 2
6 5
0 0
0 0
0 0
0 0
0 0
0 7
Input
1 1 1
0
0
0
0
0
0
Output
0
Input
1 1 1
0
0
1337
0
0
0
Output
-1
Input
1 1 1
1337
1337
1337
1337
1337
1337
Output
1337
----------------------------------------------------------------------------------------------------
