Solution
Solution
Scientific Committee
Result at 4 th hour
Total: 57 teams
First 4 hours only A B C D E F G H I J K
10/44 0/3 42/93 3/19 55/105 52/103 26/166 5/27 7/18 17/57 0/1
Solved / Tries (22%) (0%) (45%) (15%) (52%) (50%) (15%) (18%) (38%) (29%) (0%)
Average tries 2.32 3 1.82 1.73 1.84 1.81 3.19 1.93 1.5 2.28 1
Averages tries to solve 3 -- 1.79 1.33 1.62 1.71 2.5 1.6 1.29 2.35 --
• Problem J: Association of Cats and Magical Lights
• Problem H: Association for Convex Main Office
• Problem D: Association of Computer Maintenance
• Problem B: Association for Cool Machineries (Part 2)
• Problem I: Apples, Cherries, and Mangos
• Problem K: Association of Camera Makers
e f g
Simple solution
• For each query Query(u),
– directly count the number of colors below node u
– Report the number of colors whose counts are
odd
• For each update Update(c, u),
– Directly update the color of the node u
1 2 3 4 5 6 7
Node a b e f c g d
a b c d e f g
S 1 2 5 7 3 4 6
E 7 4 6 7 3 4 6
1 2 3 4 5 6 7
Node a b e f c g d
White 0 1 0 0 1 0 0
Build modified
Black 1 0 1 0 0 1 1 Fenwick tree
Red 0 0 0 1 0 0 0
1
a
Example 2 5 7
b c d
• Query(b) is the sum of range parity of [2 4]
– White: 1 3 4 6
– Black: 1 e f g
– Red: 1
– Ans: 3
a b c d e f g
S 1 2 5 7 3 4 6
E 7 4 6 7 3 4 6
1 2 3 4 5 6 7
Node a b e f c g d
White 0 1 0 0 1 0 0
Build modified
Black 1 0 1 0 0 1 1 Fenwick tree
Red 0 0 0 1 0 0 0
Additional note
• Our intended solution is to represent 100 bits as
2 long long (2 * 64bits).
• Then, build a Fenwick tree for the 2 long long.
• Then, we just need to make one Fenwick tree
query.
• Example: N=4
(0,1) (2,1)
(1,0)
How to generate a convex office?
• Example: N=16
• We form a set of N/4 right-angle triangles, all
have different slope.
• Example: K = 23 * 7
– A=7 minimizes f(A)=A+K/A=7+8
– We output f(A)=7+8=15
Observation
f(A) = A + 25/A
A=5 minimizes
A+25/A
Brute-force solution
A techique that requires us to verify
~105 divisors
Example
• Initialize A=1
• For x1=1, y1=343 x1*y1 = 343
• For x2=2, y2=343 x2*y2 = 686
• For x3=3, y3=245 x3*y3 = 735
• For x4=4, y4=49 x4*y4=196
• For x5=6, y5=49 x5*y5=294
• For x6=8, y6=49 x6*y6=392
• For x7=9, y7=49 x7*y7=441
• For x8=12, y8=49 x8*y8=588
K1 K2 • For x9=18, y9=49 x9*y9=882
1 X
12005 • For x10=24, y10=35 x10*y10=840
2 X
2401
• For x11=36, y11=7 x11*y11=252
• For x12=72, y12=7 x12*y12=504
3 X
1715
4 X
343 • The biggest is A=x9*y9=882=2*32*72.
6 245
X K/A=22*51*72=980.
8 • A + K/A = 882+980=1862.
X
49
9 35
X
12 7
18 5
24 1
36
72
Handle big number
• Multiplication of big number is slow.
• Solution: Use logarithm
– Replace X * Y by log X + log Y
• It reduces the running time.
Association for Cool Machineries
(Part 2)
Problem B
The problem for part 1
• Give a NxN grid and a sequence of <,>,^,v
• Output X, which is the smallest repetition trail
• Example program: ^v>^<
###### ###### ###### ###### ######
# # # # # # # # # # # # # # #
# # # # # # ^ # # R# # #R # > # # R#
# R # # R# # # # # # #
## # ## # ## # ## # ## #
###### ###### ###### ###### ###### The
^ > < v ^ smallest
###### ###### ###### ###### ###### repetition
# # # # # # # # # # #R # # # R# trail is of
# #R # v # # # # #R # ^ # # # < # # # length 4
# # # R # # # # # # #
## # ## # ## # ## # ## #
###### ###### ###### ###### ######
The problem for part 2
• Design
– a 200x200 grid and
– a sequence of <,>,^,v
• such that the smallest repetition trail is of
length > 106
Idea
• Design a sequence (say, vv<<<^^^>>) and walls that allows the
robot to move up, down, left and right.
• E.g. ## #
#c#
#b# # a#
#a# ## #
# # # b#
# # ## #
# c#
Problem I
Problem
• WLOG, assume A ≥ C ≥ M
• We need to arrange them so that adjacent fruits are
different
• Example: A=2, C=1, M=1
Solution: DP
• V(A, C, M) = no of valid ways to allocate all fruits
• VA(A, C, M) = no of valid ways to allocate all fruits given that the first fruit is Apple
• VC(A, C, M) = no of valid ways to allocate all fruits given that the first fruit is Cherry
• VM(A, C, M) = no of valid ways to allocate all fruits given that the first fruit is Mango
• Base cases:
– VA(1, 0, 0) = 1, VC(0, 1, 0) = 1, VM(0, 0, 1) = 1
– Vw(x, y, z) = 0 if x<0 or y<0 or z<0
• Recursive cases:
– VA(A, C, M) = VC(A-1, C, M) + VM(A-1, C, M)
– VC(A, C, M) = VA(A, C-1, M) + VM(A, C-1, M)
– VM(A, C, M) = VA(A, C, M-1) + VC(A, C, M-1)
– V(A, C, M) = VA(A, C, M) + VC(A, C, M) + VM(A, C, M)
^ ^ ^ ^ ^ ^
A+1 bins: ……
^ ^ ^ ^ ^
A bins: ……
^ ^ ^ ^ ^
A bins: ……
^ ^ ^ ^
A-1 bins: ……
Number of valid arrangements of
A,C,M
……
^ ^ ^ ^ ^ ^
A+1 bins: ……
^ ^ ^ ^ ^
A bins: ……
^ ^ ^ ^ ^
A bins: ……
^ ^ ^ ^
A-1 bins: ……
Valid arrangement for cherries and
mangos in each bin
• Suppose we don’t have apple
• Assume we have c cherries and m mangos
• To have a valid arrangement, we need
c=m or c=m-1 or c=m+1
Problem K
Association of Camera Makers
• Input:
– A set of points (X1,Y1), …, (XN, YN)
– A threshold K
• Output:
– The minimum radius R such that a circle of radius R that covers K
points
(-2,0) (2,0) (6,0)
(0,-2)
Can we verify if a radius-R circle cover
K points?
• VerifyRadius(R, K) is a function that returns true if a radius-R circle exists
that covers K points
• Suppose there exists a radius-R circle that contains K points
– Then, the radius-R circles of the K points should overlap
– Any point in the overlapping region can be the center of the radius-R circle.
• In particular, we can set any intersecting point as the center of the radius-R circle.
Idea for VerifyRadius(R,K)
• Let (Xi, Yi) and (Xj, Yj) be any two points
• Let Q and Q’ be the intersecting points of the radius-R circles of (Xi, Yi) and
(Xj, Yj)
• If there exist (K-2) other points whose distances from Q (or Q’) are less
than R, then
– VerifyRadius(R, K) returns true.
(Xi, Yi)
Q’
(Xj, Yj)
Q
VerifyRadius(R,K)
Function VerifyRadius(R, K)
• For every pair of points (Xi,Yi) and (Xj,Yj),
– If the radius-R circles of (Xi,Yi) and (Xj,Yj) overlap,
• Let the intersecting points be Q and Q’
• Check if there are (K-2) points whose distances from Q
(or Q’) are less than R;
• If yes, return true;
• Return false;
• FindRadius(L, U)
– If (L and U are the same up to 2 decimal place) report L;
– M=(L+U)/2;
– If VerifyRadius(M, K) is true,
• FindRadius(M, U);
– Else
• FindRadius(L, M);
Still not good enough
• Previous solution runs in
O(N3 log 108) = O(27 N3) time
• It can handle cases where N<1000
• Hence, it can solve 10 out of 16 test cases