Post on 22-Jul-2020
transcript
Problem Analysis Session
SWERC judges
January 25, 2020
SWERC judges Problem Analysis Session January 25, 2020 1 / 17
Statistics
Number of submissions: 676Most attempted: E – Extreme TemperatureLeast attempted: D – MigrationNumber of clarification requests: 78
Languages:
cpp py3 java cLanguage
200
400
# of
Sub
mis
sion
s
0
456Attempted Accepted
SWERC judges Problem Analysis Session January 25, 2020 2 / 17
E – Extreme Temperature
Solved by 83 teams before freeze.First solved after 3 min byISTo e pro voces.
correct wrong-answer timelimit run-error compiler-error no-output
20 40 60 80 100Contest Time(minutes)
0 120
50
100
150
Tota
l Sub
mis
sion
s
0
SWERC judges Problem Analysis Session January 25, 2020 3 / 17
E – Extreme Temperature
Problem
Find min and max in list.
Solution
This was an easy problem :)
SWERC judges Problem Analysis Session January 25, 2020 4 / 17
B – Hiding Nuts
Solved by 80 teams before freeze.First solved after 10 min by EP Chopper.
correct wrong-answer timelimit run-error compiler-error no-output
20 40 60 80 100Contest Time(minutes)
0 120
50
100
150
Tota
l Sub
mis
sion
s
0
SWERC judges Problem Analysis Session January 25, 2020 5 / 17
B – Hiding Nuts
Problem
Given a list of N points in the plane, which one minimizes the average ofL1 distances to all others?
Limits
N ≤ 1000
Solution
Minimizing average equivalent to minimizing the sum.
For each point, iterate over all other points and sum their distances.
Keep track of the point which minimizes that sum according todisambiguating rules.
O(N2) complexity.
SWERC judges Problem Analysis Session January 25, 2020 6 / 17
B – Hiding Nuts
Bonus solution (not required)
Decompose the L1 distance along the 4 directions aligned with theaxes.
Build partial sums for each of the 4 distance components.
For each point, sum the 4 partial sums to recover the sum of L1distances.
O(N logN)
SWERC judges Problem Analysis Session January 25, 2020 7 / 17
A – Splitting DNA
Solved by 39 teams before freeze.First solved after 20 min by UPC-1.
correct wrong-answer timelimit run-error compiler-error no-output
20 40 60 80 100Contest Time(minutes)
0 120
50
100
150
Tota
l Sub
mis
sion
s
0
SWERC judges Problem Analysis Session January 25, 2020 8 / 17
A – Splitting DNA
Problem
The chain S1 . . . SN is represented by the length of its pieces L1, . . . , LN .
Cutting Si . . . Sk into two parts Si . . . Sj and Sj+1 . . . Sk costs Li + . . .+ Lk .
Minimal cost to cut the whole chain S1 . . . SN into the pieces S1, . . . , SN?
Limits
N ≤ 500
0 ≤ Li ≤ 1014 (zero is valid! use 64-bit integers!)
Solution
Dynamic programming: minimal cost to cut Si . . . Sk , try all i ≤ j ≤ k .
Time complexity: O(N3) (tight! Use a matrix, not a hash table)
Cumulative sums do not improve complexity.
SWERC judges Problem Analysis Session January 25, 2020 9 / 17
C – Visibility
Solved by 11 teams before freeze.First solved after 48 min by EP Chopper.
correct wrong-answer timelimit run-error compiler-error no-output
20 40 60 80 100Contest Time(minutes)
0 120
10
20
30
40
Tota
l Sub
mis
sion
s
0
SWERC judges Problem Analysis Session January 25, 2020 10 / 17
C – Visibility
Problem
Given a set S of points in the plane, how many pairs (A,B) ∈ S2 can you
find such that−→AB lies within 60 of the Southern direction?
Limits
S can be large: |S| 6 100 000.
Thus we can work in time O(|S| log(|S|)) or O(|S|3/2), but not Ω(|S|2).
SWERC judges Problem Analysis Session January 25, 2020 11 / 17
C – Visibility
Idea
A sees B iff A 61 B and A 62 B.
A B
C
D
E
A
C
D
B
E
SWERC judges Problem Analysis Session January 25, 2020 12 / 17
C – Visibility
Solution: how can we count pairs (A,B) s.t. A 61 B and A 62 B?
For all points A (in 61-increasing order):
check how many points B 62 A your had already seen.
Use some (balanced) binary search tree to store points and counts!
Example: A <1 B <1 C <1 E <1 D and B <2 A <2 E <2 C <2 D
62-binary search tree
A
A
B
B
C
C
E
E
D
D
0
11
0
1122
0
1122334455
0
1122
0
11
Total count: 0
Total count: 2Total count: 4Total count: 8
Time complexity: O(|S| log(|S|))
SWERC judges Problem Analysis Session January 25, 2020 13 / 17
C – Visibility
Solution: how can we count pairs (A,B) s.t. A 61 B and A 62 B?
For all points A (in 61-increasing order):
check how many points B 62 A your had already seen.
Use some (balanced) binary search tree to store points and counts!
Example: A <1 B <1 C <1 E <1 D and B <2 A <2 E <2 C <2 D
62-binary search tree
A
A
B
B
C
C
E
E
D
D
0
11
0
1122
0
1122334455
0
1122
0
11
Total count: 0
Total count: 2Total count: 4Total count: 8
Time complexity: O(|S| log(|S|))
SWERC judges Problem Analysis Session January 25, 2020 13 / 17
C – Visibility
Solution: how can we count pairs (A,B) s.t. A 61 B and A 62 B?
For all points A (in 61-increasing order):
check how many points B 62 A your had already seen.
Use some (balanced) binary search tree to store points and counts!
Example: A <1 B <1 C <1 E <1 D and B <2 A <2 E <2 C <2 D
62-binary search tree
A
A
B
B
C
C
E
E
D
D
0
11
0
1122
0
1122334455
0
1122
0
11
Total count: 0
Total count: 2Total count: 4Total count: 8
Time complexity: O(|S| log(|S|))
SWERC judges Problem Analysis Session January 25, 2020 13 / 17
C – Visibility
Solution: how can we count pairs (A,B) s.t. A 61 B and A 62 B?
For all points A (in 61-increasing order):
check how many points B 62 A your had already seen.
Use some (balanced) binary search tree to store points and counts!
Example: A <1 B <1 C <1 E <1 D and B <2 A <2 E <2 C <2 D
62-binary search tree
A
A
B
B
C
C
E
E
D
D
0
11
0
1
122
0
1
122334455
0
1122
0
11
Total count: 0
Total count: 2Total count: 4Total count: 8
Time complexity: O(|S| log(|S|))
SWERC judges Problem Analysis Session January 25, 2020 13 / 17
C – Visibility
Solution: how can we count pairs (A,B) s.t. A 61 B and A 62 B?
For all points A (in 61-increasing order):
check how many points B 62 A your had already seen.
Use some (balanced) binary search tree to store points and counts!
Example: A <1 B <1 C <1 E <1 D and B <2 A <2 E <2 C <2 D
62-binary search tree
A
A
B
B C
C
E
E
D
D
0
11
01
1
22
01
1
22334455
0
1122
0
11
Total count: 0
Total count: 2Total count: 4Total count: 8
Time complexity: O(|S| log(|S|))
SWERC judges Problem Analysis Session January 25, 2020 13 / 17
C – Visibility
Solution: how can we count pairs (A,B) s.t. A 61 B and A 62 B?
For all points A (in 61-increasing order):
check how many points B 62 A your had already seen.
Use some (balanced) binary search tree to store points and counts!
Example: A <1 B <1 C <1 E <1 D and B <2 A <2 E <2 C <2 D
62-binary search tree
A
A
B
B C
C
E
E
D
D
0
1
1
011
2
2
011
2
2334455
0
1122
0
11
Total count: 0
Total count: 2Total count: 4Total count: 8
Time complexity: O(|S| log(|S|))
SWERC judges Problem Analysis Session January 25, 2020 13 / 17
C – Visibility
Solution: how can we count pairs (A,B) s.t. A 61 B and A 62 B?
For all points A (in 61-increasing order):
check how many points B 62 A your had already seen.
Use some (balanced) binary search tree to store points and counts!
Example: A <1 B <1 C <1 E <1 D and B <2 A <2 E <2 C <2 D
62-binary search tree
A
A
B
B
C
C
E
E
D
D
01
1
0112
2
0112
2
334455
0
1122
0
11
Total count: 0
Total count: 2Total count: 4Total count: 8
Time complexity: O(|S| log(|S|))
SWERC judges Problem Analysis Session January 25, 2020 13 / 17
C – Visibility
Solution: how can we count pairs (A,B) s.t. A 61 B and A 62 B?
For all points A (in 61-increasing order):
check how many points B 62 A your had already seen.
Use some (balanced) binary search tree to store points and counts!
Example: A <1 B <1 C <1 E <1 D and B <2 A <2 E <2 C <2 D
62-binary search tree
A
A
B
B
C
C
E
E
D
D
01
1
0112
2
01122
3
34455
0
1
122
0
1
1
Total count: 0
Total count: 2
Total count: 4Total count: 8
Time complexity: O(|S| log(|S|))
SWERC judges Problem Analysis Session January 25, 2020 13 / 17
C – Visibility
Solution: how can we count pairs (A,B) s.t. A 61 B and A 62 B?
For all points A (in 61-increasing order):
check how many points B 62 A your had already seen.
Use some (balanced) binary search tree to store points and counts!
Example: A <1 B <1 C <1 E <1 D and B <2 A <2 E <2 C <2 D
62-binary search tree
A
A
B
B
C
C
E
E
D
D
01
1
0112
2
011223
3
4455
01
1
22
01
1
Total count: 0
Total count: 2
Total count: 4Total count: 8
Time complexity: O(|S| log(|S|))
SWERC judges Problem Analysis Session January 25, 2020 13 / 17
C – Visibility
Solution: how can we count pairs (A,B) s.t. A 61 B and A 62 B?
For all points A (in 61-increasing order):
check how many points B 62 A your had already seen.
Use some (balanced) binary search tree to store points and counts!
Example: A <1 B <1 C <1 E <1 D and B <2 A <2 E <2 C <2 D
62-binary search tree
A
A
B
B
C
C
E
E
D
D
01
1
0112
2
0112233
4
455
01
1
22
01
1
Total count: 0Total count: 2
Total count: 4
Total count: 8
Time complexity: O(|S| log(|S|))
SWERC judges Problem Analysis Session January 25, 2020 13 / 17
C – Visibility
Solution: how can we count pairs (A,B) s.t. A 61 B and A 62 B?
For all points A (in 61-increasing order):
check how many points B 62 A your had already seen.
Use some (balanced) binary search tree to store points and counts!
Example: A <1 B <1 C <1 E <1 D and B <2 A <2 E <2 C <2 D
62-binary search tree
A
A
B
B
C
C
E
E
D
D
01
1
0112
2
01122334
4
55
01
1
22
01
1
Total count: 0Total count: 2
Total count: 4
Total count: 8
Time complexity: O(|S| log(|S|))
SWERC judges Problem Analysis Session January 25, 2020 13 / 17
C – Visibility
Solution: how can we count pairs (A,B) s.t. A 61 B and A 62 B?
For all points A (in 61-increasing order):
check how many points B 62 A your had already seen.
Use some (balanced) binary search tree to store points and counts!
Example: A <1 B <1 C <1 E <1 D and B <2 A <2 E <2 C <2 D
62-binary search tree
A
A
B
B
C
C
E
E
D
D
01
1
0112
2
011223344
5
5
011
2
2
01
1
Total count: 0Total count: 2Total count: 4
Total count: 8
Time complexity: O(|S| log(|S|))
SWERC judges Problem Analysis Session January 25, 2020 13 / 17
C – Visibility
Solution: how can we count pairs (A,B) s.t. A 61 B and A 62 B?
For all points A (in 61-increasing order):
check how many points B 62 A your had already seen.
Use some (balanced) binary search tree to store points and counts!
Example: A <1 B <1 C <1 E <1 D and B <2 A <2 E <2 C <2 D
62-binary search tree
A
A
B
B
C
C
E
E
D
D
01
1
0112
2
0112233445
5
0112
2
01
1
Total count: 0Total count: 2Total count: 4
Total count: 8
Time complexity: O(|S| log(|S|))
SWERC judges Problem Analysis Session January 25, 2020 13 / 17
C – Visibility
Solution: how can we count pairs (A,B) s.t. A 61 B and A 62 B?
For all points A (in 61-increasing order):
check how many points B 62 A your had already seen.
Use some (balanced) binary search tree to store points and counts!
Example: A <1 B <1 C <1 E <1 D and B <2 A <2 E <2 C <2 D
62-binary search tree
A
A
B
B
C
C
E
E
D
D
01
1
0112
2
0112233445
5
0112
2
01
1
Total count: 0Total count: 2Total count: 4
Total count: 8
Time complexity: O(|S| log(|S|))
SWERC judges Problem Analysis Session January 25, 2020 13 / 17
D – Migration
Solved by 1 team before freeze.First solved after 58 min by UPC-1.
correct wrong-answer timelimit run-error compiler-error no-output
20 40 60 80 100Contest Time(minutes)
0 120
2
4
6
8
Tota
l Sub
mis
sion
s
0
SWERC judges Problem Analysis Session January 25, 2020 14 / 17
D – Migration
Problem
Given a graph (V ,E ) with weights w on nodes, find a node cut C betweentwo nodes a and b minimizing the cost maxn∈Cw(n)× |C |.
Remark 1
By expanding each node n into a “in”-node and an “out”-node, we cantransform the problem on nodes into a problem on minimal cut on theedges of the form nin → nout .
ab
nc
dbecomes aout
bout nin noutcin
din
SWERC judges Problem Analysis Session January 25, 2020 15 / 17
D – Migration
Remark 2
If we fix M = maxn∈Cw(n) this second problem corresponds to a max-flowproblem (see min-cut-max-flow theorem) where edges that cannot be cutor with a weight above M are given an infinite capacity.
“Naive” solution
Try all the possible values for M: complexity O(V × E ) per min-cutproblem, so O(V 2 × E ) overall.
Too costly!
SWERC judges Problem Analysis Session January 25, 2020 16 / 17
D – Migration
A better solution
Instead of computing the flows independently for each possible value of M,use the result of the flow computation for M to compute the flow forM ′ > M.This provides a complexity of O(V × E ).
SWERC judges Problem Analysis Session January 25, 2020 17 / 17