The presentation I gave along with my team - 'Pyoneers', as a part of the Computer Science and Engineering Seminar series at IIT Gandhinagar. We talk about our experience and also discuss some of problems we encountered.
1. cse seminar series
Experiences and Problems from
the ACM-ICPC 2016 Regionals
Akash Pallath Chinmay Sonar P.R. Vaidyanathan
(from pyoneers import *)
April 17, 2017
Indian Institute of Technology Gandhinagar
3. acm-icpc format
∙ Team contest - 3 members (+1 optional reserve)
∙ Online Qualifiers -> Onsite Regionals -> India Finals -> World
Finals
∙ Onsite Regionals in India - Amritapuri, Chennai, Kharagpur,
Kolkata
∙ India Finals - Kolkata, Gwalior (top N teams selected from each
site)
∙ Qualifiers - 7 questions, 3 hours
∙ Onsite rounds - 10-13 questions, 5 hours
∙ Different difficulty levels - E.g. - at Chennai, top team solved 6
out of 10 problems (3 problems remained unsolved by any
team), at Amritapuri, same team solved 10 out of 11 problems
(only 1 problem remained unsolved by any team)
2
4. our experience
∙ Chennai - Ranked 56 (out of 128 teams). Solved 4. Top team
solved 6.
∙ Amritapuri - Ranked 40 at Coimbatore subsite (out of 124
teams). Solved 3 :( Top team solved 10.
∙ Learning experience
∙ Interaction with competitive programming community
∙ Language issues - Python, although slower, given same time
limit constraints on DOMJudge (Amritapuri). CodeChef, however,
gives Python 5 × time limit, and Java 2 × time limit (all other
sites).
∙ Used Python for cakewalk problems, C++ for the rest.
3
8. chn16g - voting fraud
Problem Statistics
∙ Total correct submissions - 117
∙ Accuracy - 89.31%
∙ Number of submissions we made - 1
∙ Verdict - AC
7
9. brief problem statement
There are N students who took part in the voting. Each student has a
student ID using that they will vote. Help the officials to find out if
any one has voted more than once, by giving them the total number
of fraud votes. Each student is supposed to cast at most one vote
only. So, if a students has cast more than one vote, all votes except
one vote will be fraud votes.
8
10. constraints and examples
Constraints:
∙ 1 ≤ T ≤ 100
∙ 1 ≤ N ≤ 100
∙ 1 ≤ Ai ≤ 100
Examples:
1. Given the total number of votes casted to be 4 and the actual
voter ID’s are 1, 2, 3, 2
Answer: 1
2. Given the total number of votes casted to be 4 and the actual
voter ID’s are 1, 2, 2, 2
Answer: 2
9
12. time complexity
Running time: Time required to process all the input voter ID’s and
each voter ID can be processed in constant time. Hence, the total
running time is,
n ∗ constant ≈ O(n)
11
14. chn16f - acm-icpc world finals accommodation
Problem Statistics
∙ Total correct submissions - 116
∙ Accuracy - 61.7%
∙ Number of submissions we made - 1
∙ Verdict - AC
13
15. brief problem statement
Given a floor of n ∗ m rooms arranged in a rectangular fashion. There
are teams from total of C countries, with each country having ci
teams. We need to accommodate these teams such that, all the
teams from a country should be able to communicate with each
other.
The condition for communication between teams is,
1. when 2 teams of same country share a common wall
2. when 2 teams of same country have common neighbor (i.e.
neighbor is a team sharing a wall) of the same country
14
16. constraints and examples
Constraints:
∙ 1 ≤ T, n, m ≤ 50
∙ 1 ≤ C, ci ≤ n ∗ m
∙
∑
ci = n ∗ m
Examples:
1. Given a 2 ∗ 2 rectangular hall with 4 rooms. Accommodate the
teams from 2 countries satisfying the given condition such that,
there are 2 teams from each country.
2. Given a 2 ∗ 2 rectangular hall with 4 rooms. Accommodate 4
teams from a single country
15
20. chn16c - birthday pizza party
Problem Statistics
∙ Total correct submissions - 85
∙ Accuracy - 24.71%
∙ Number of submissions we made - 3
∙ Verdict - 2 WA [Integer Overflow], 1 AC
19
21. brief problem statement
Steffi wants to treat N friends at her birthday party. Every pizza can
be divided into A equal pieces. Find the minimum number of Pizzas
she should buy given that,
∙ Each friend should get equal number of pieces
∙ Steffi should get exactly one piece
∙ Any piece of pizza should not be wasted
20
22. constraints and examples
Constraints:
∙ 1 ≤ T ≤ 100, 000
∙ 1 ≤ A ≤ 1012
∙ 1 ≤ N ≤ 1012
Examples:
1. The number of friends (N) is 3 and a pizza can be divided into
(A) 2 parts.
Answer: 2
2. The number of friends (N) is 4 and pizza cannot be further
subdivided into smaller parts (A = 1) (i.e. 1 pizza = 1 piece).
Answer: 5
21
24. solution
Assume,
X → minimum number of pizza(s) that should be bought
I → number of pieces given to each friend
To satisfy the given constraints we need to solve,
AX − NI = 1 (1)
Claims:
1. On the RHS of (1) we can only obtain integer multiples of
(GCD(A, N))
2. GCD of any 2 numbers can be expressed as linear combination
of those 2 numbers with integral coefficients [Bézout’s Identity]
23
26. chn16b - mancunian candidate master forever
Problem Statistics
∙ Total correct submissions - 38
∙ Accuracy - 33.05%
∙ Number of submissions we made - 1
∙ Verdict - AC
25
27. problem statement
∙ You are given N drinks
∙ Each drink is characterized by the salt and sugar in it
∙ Each drink also has a cost associated with it
∙ Your task is to find a subset of drinks of minimum cost to buy
∙ Such that all the drinks can be ”prepared” using the purchased
drinks
26
28. problem statement
Definition
Preparing a drink, means mixing two or more drinks in some
proportion, yielding a new drink. The sugar and salt in this drink is
the weighted mean of the sugar and salt contents of the constituent
drinks.
Note
It is not necessary to prepare all the N drinks simultaneously.
It is sufficient to be able to prepare all the N drinks independently.
27
29. example
Name Sugar Salt Cost
A 4 2 1
B 3 3 5
C 2 4 10
Answer: Drink A and Drink B costing 11. Mixing them in 1:1 proportion
gives Drink C
28
31. solution
Intuition
∙ Represent a drink with x mg sugar and y mg salt as (x, y)
∙ Visualize drink as a point on Cartesian plane
∙ Understand what mixing means in this setting
∙ Ignore cost aspect, for now just try to find a subset of drinks
which can be used to prepare the remaining
30
35. chn16i - alice and bob play contact
Problem Statistics
∙ Total correct submissions - 69
∙ Accuracy - 25.94%
∙ Number of submissions we made - 0 (fell short of time).
34
36. brief problem statement
∙ Alice’s ’Vocabulary’ - set of strings SAlice = {A1, A2, . . . , An}
∙ Bob’s ’Vocabulary’ - set of strings SBob = {B1, B2, . . . , Bm}
∙ A game is played for each word Ai in SAlice
∙ In the jth
iteration of the ith
game, Bob uses a word from SBob
that has a prefix of length j common with Ai.
∙ In a particular game, Bob cannot re-use a word he has already
used in that game.
∙ Game ends when Bob has made |Ai| moves, or when Bob has no
word left to make a move.
35
37. brief problem statement
∙ Problem: Find the sum of maximum number of moves Bob can
make for each of the n games.
Constraints
∙ 1 ≤ n, m ≤ 105
∙ 1 ≤ |Ai|, |Bi| ≤ 105
∙ 1 ≤
∑n
i−1 |Ai| ≤ 106
∙ 1 ≤
∑m
i−1 |Bi| ≤ 106
∙ All strings consist of upper-case English alphabets
∙ All strings in SAlice are distinct, all strings in SBob are distinct
36
38. strategies
Aim
Maximize the length of each game.
Strategy 1
For jth
move in a game, pick up any word from SBob which has prefix
of length j in common with Ai.
Will this work?
Strategy 2
For jth
move in a game, select an unused word from SBob with
minimum prefix length ≥ j, common with Ai.
This is the optimal strategy
37
39. naive solution
∙ For each game i, maintain a list of words from SBob, with the
option to mark words as ’used’.
∙ Calculate and store the lengths of prefixes of each word with Ai.
∙ At iteration j, pick a usable word that has minimum length of
common prefix with Ai, such that the prefix length is ≥ j. Mark
this word as used.
∙ If no such word is found, or if j > |Ai|, then the game has
terminated
38
40. time complexity
∙ For each game i, maintain a list of words from SBob, with the
option to mark words as ’used’. O(n) iterations
∙ Calculate and store the lengths of prefixes of each word from
SBob with Ai. O(|Ai| +
∑m
j=1 |Bj|) time
∙ At iteration j, pick a usable word that has minimum length of
common prefix with Ai, such that the prefix length is ≥ j. Mark
this word as used.
∙ If no such word is found, or if j > |Ai|, then the game has
terminated.
Running time is O(
∑n
i=1 |Ai| + n ×
∑m
j=1 |Bj|)
= O(106
+ 105
× 106
) = O(1011
) operations
Verdict
Time Limit Exceeded
39
42. moving to an efficient algorithm
Question
Can we bring the running time down to O(
∑n
i=1 |Ai| +
∑m
j=1 |Bj|)?
How?
A hint to the approach
For each Ai in SAlice, determine length of game by scanning a single
word in Bob’s vocabulary.
Another hint
The alphabet size is fixed (only uppercase letters). Why would the
problem author set this constraint?
Everything points to a Trie-based approach
41
43. moving to an efficient algorithm
∙ Hoard all Bob’s strings into a trie. O(
∑m
i=1 |Bi|) = O(106
)
∙ At each node, maintain total number of leaves reachable from
that node.
∙ For each string Ai, search for Ai in trie - following certain
constraints:
∙ If there are nx strings at node x, one of them has to be used at
that node
∙ Greedy strategy - use string that overlaps as little as possible with
search path
42
44. an example to demonstrate the approach
Bob’s Vocabulary
∙ ant
∙ bat
∙ bestow
∙ bested
∙ besxyz
∙ bust
∙ cat
Alice’s current word : bestow
https://www.cs.usfca.edu/ galles/visualization/Trie.html
43
45. final algorithm
Algorithm 1 Determining Length of a Game
1: glen ← 0, avl ← |Ai|, j ← 0
2: t ← root of trie
3: while j < |Ai| do
4: if avl = 0 then
5: break
6: if jth
character of Ai not found in trie then
7: break
8: t ← node of trie storing jth
character of Ai
9: avl ← min(avl-1 , paths from t -1)
10: glen ← glen + 1, j ← j + 1
11: glen is the maximum game length
44
47. attribution
This presentation has been made using the LATEX theme mtheme
Get the source of this theme and the demo presentation from
github.com/matze/mtheme
The theme itself is licensed under a Creative Commons
Attribution-ShareAlike 4.0 International License.
cba
46
50. useful material
Links to Problems (ACM-ICPC Asia Chennai 2016 Regionals)
Problem Link
Voting Fraud CHN16G
ACM ICPC World Finals Accomodation CHN16F
Birthday Pizza Party CHN16C
Mancunian Candidate Master Forever CHN16B
Alice and Bob Play Contact CHN16I
Applet Demonstrating CHN16B (developed by P.R. Vaidyanathan)
49