SlideShare a Scribd company logo
1 of 21
Download to read offline
ACM ICPC 2014{2015 
Northeastern European Regional Contest 
Problems Review 
Roman Elizarov 
December 7, 2014
Problem A. Alter Board 
I The minimal answer to this problem is bn=2c + bm=2c 
I The solution is to make inversions on each even row and each 
even column 
I To prove that the answer is minimal consider the
rst column 
with its n cells that form n  1 neighbouring pairs 
I to turn all cells of the
rst column in the same color inversions 
must span the
rst column 
I each spanning inversion makes at most two neighbouring pairs 
of the same color 
I so the minimum of d(n  1)=2e = bn=2c inversions are needed 
I Then consider the top row in the same way
Problem B. Burrito King 
I Consider the problem as a sum of vectors in (a; b) coordinates 
I The resulting vector may not go above b = B line and must 
extend on a axis as far as possible 
I It is optimal to greedily add (ai ; bi ) ingredient vectors starting 
from the ones that have the least angle to 0a line (or maximal 
ai=bi ), until b = B line is crossed 
I Be careful about corner cases with ai = 0 and/or bi = 0 
a 
b 
B 
0 A
Problem C. Cactus Generator 
I This is a straightforward problem for parsing and OO design 
I De
ne class for graph with a method to generate graph given 
index of the
rst and the vertices 
I De
ne class for various range types 
I Parse and construct classes tree 
I Build the resulting graph 
I Connect arbitrary pairs of vertices of odd degree in the 
resulting graph using temporary edges 
I Use classical algorithm for Eulerian path 
I Remove temporary edges to get the minimal number of 
covering paths
Problem D. Damage Assessment 
I Numerically integrate the square section by dx 
I The square of the cut at a given x coordinate is a simple 
planar geometry problem 
I Take care about leftmost point with in
nite derivative 
I however, the required precision does not make this a big 
problem 
I the square section at this point is small 
x
Problem E. Epic Win! 
I There is a simple solution with up to n2 states 
I Build your FSM as n copies of a winning FSM with n states 
I Each state of a winning FSM corresponds to a state in the 
opponent FSM 
I Each move of a winning FSM is a winning move for the 
corresponding opponent's move 
I Next state in a winning FSM corresponds to the opponent 
move and opponent's next state 
I Leave other transitions unde
ned 
I The
rst copy of a winning FMS starts in its
rst state and 
wins an opponent that stats in it
rst state by construction 
I Model the behaviour of the opponent and your FSM for all 
opponent start states from the states 2 to n 
I When a yet unde
ned transition is reached, then insert a 
transition to a fresh copy of a winning FSM into the state 
corresponding to the opponent's, thus ensuring win in this copy 
I Stop modelling when loop is detected 
I Loop is inside one copy of a winning FSM and is always 
winning by construction
Problem F. Filter 
I Nothing fancy here 
I Just implement what the problem statement asks for in a 
straightforward way 
I The hardest part seems to be reading and understanding the 
problem statement
Problem G. Gomoku 
I The
rst player's strategy has pretty strict priorities in the 
moves it makes and it can be exploited 
I Make the

More Related Content

What's hot

What's hot (20)

Course 102: Lecture 20: Networking In Linux (Basic Concepts)
Course 102: Lecture 20: Networking In Linux (Basic Concepts) Course 102: Lecture 20: Networking In Linux (Basic Concepts)
Course 102: Lecture 20: Networking In Linux (Basic Concepts)
 
3 d transformation Rotation
3 d transformation   Rotation3 d transformation   Rotation
3 d transformation Rotation
 
Operating system 22 threading issues
Operating system 22 threading issuesOperating system 22 threading issues
Operating system 22 threading issues
 
Parallel Computing
Parallel ComputingParallel Computing
Parallel Computing
 
Fundamentals of operating system
Fundamentals of operating systemFundamentals of operating system
Fundamentals of operating system
 
Heuristc Search Techniques
Heuristc Search TechniquesHeuristc Search Techniques
Heuristc Search Techniques
 
Intro to AI STRIPS Planning & Applications in Video-games Lecture2-Part2
Intro to AI STRIPS Planning & Applications in Video-games Lecture2-Part2Intro to AI STRIPS Planning & Applications in Video-games Lecture2-Part2
Intro to AI STRIPS Planning & Applications in Video-games Lecture2-Part2
 
Kernels and its types
Kernels and its typesKernels and its types
Kernels and its types
 
Hill climbing algorithm
Hill climbing algorithmHill climbing algorithm
Hill climbing algorithm
 
AI Lecture 7 (uncertainty)
AI Lecture 7 (uncertainty)AI Lecture 7 (uncertainty)
AI Lecture 7 (uncertainty)
 
Problem solving
Problem solvingProblem solving
Problem solving
 
Gauss Elimination Method With Partial Pivoting
Gauss Elimination Method With Partial PivotingGauss Elimination Method With Partial Pivoting
Gauss Elimination Method With Partial Pivoting
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
 
2.5 dfs & bfs
2.5 dfs & bfs2.5 dfs & bfs
2.5 dfs & bfs
 
Decision theory
Decision theoryDecision theory
Decision theory
 
Prim Algorithm and kruskal algorithm
Prim Algorithm and kruskal algorithmPrim Algorithm and kruskal algorithm
Prim Algorithm and kruskal algorithm
 
algorithm Unit 3
algorithm Unit 3algorithm Unit 3
algorithm Unit 3
 
Computer organisation -morris mano
Computer organisation  -morris manoComputer organisation  -morris mano
Computer organisation -morris mano
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
 
Allocating of Frames.pptx
Allocating of Frames.pptxAllocating of Frames.pptx
Allocating of Frames.pptx
 

Viewers also liked

ACM ICPC 2013 NEERC (Northeastern European Regional Contest) Problems Review
ACM ICPC 2013 NEERC (Northeastern European Regional Contest) Problems ReviewACM ICPC 2013 NEERC (Northeastern European Regional Contest) Problems Review
ACM ICPC 2013 NEERC (Northeastern European Regional Contest) Problems Review
Roman Elizarov
 
Многопоточные Алгоритмы (для BitByte 2014)
Многопоточные Алгоритмы (для BitByte 2014)Многопоточные Алгоритмы (для BitByte 2014)
Многопоточные Алгоритмы (для BitByte 2014)
Roman Elizarov
 
Многопоточное Программирование - Теория и Практика
Многопоточное Программирование - Теория и ПрактикаМногопоточное Программирование - Теория и Практика
Многопоточное Программирование - Теория и Практика
Roman Elizarov
 
The theory of concurrent programming for a seasoned programmer
The theory of concurrent programming for a seasoned programmerThe theory of concurrent programming for a seasoned programmer
The theory of concurrent programming for a seasoned programmer
Roman Elizarov
 
Теоретический минимум для понимания Java Memory Model (для JPoint 2014)
Теоретический минимум для понимания Java Memory Model (для JPoint 2014)Теоретический минимум для понимания Java Memory Model (для JPoint 2014)
Теоретический минимум для понимания Java Memory Model (для JPoint 2014)
Roman Elizarov
 
ACM ICPC 2012 NEERC (Northeastern European Regional Contest) Problems Review
ACM ICPC 2012 NEERC (Northeastern European Regional Contest) Problems ReviewACM ICPC 2012 NEERC (Northeastern European Regional Contest) Problems Review
ACM ICPC 2012 NEERC (Northeastern European Regional Contest) Problems Review
Roman Elizarov
 
11 x1 t14 06 sum of a geometric series (2012)
11 x1 t14 06 sum of a geometric series (2012)11 x1 t14 06 sum of a geometric series (2012)
11 x1 t14 06 sum of a geometric series (2012)
Nigel Simmons
 
13 3 arithmetic and geometric series and their sums
13 3 arithmetic and geometric series and their sums13 3 arithmetic and geometric series and their sums
13 3 arithmetic and geometric series and their sums
hisema01
 
Problem solving on acm international collegiate programming contest
Problem solving on acm international collegiate programming contestProblem solving on acm international collegiate programming contest
Problem solving on acm international collegiate programming contest
Fedor Tsarev
 
20130420 bitbyte
20130420 bitbyte20130420 bitbyte
20130420 bitbyte
Devexperts
 

Viewers also liked (20)

ACM ICPC 2015 NEERC (Northeastern European Regional Contest) Problems Review
ACM ICPC 2015 NEERC (Northeastern European Regional Contest) Problems ReviewACM ICPC 2015 NEERC (Northeastern European Regional Contest) Problems Review
ACM ICPC 2015 NEERC (Northeastern European Regional Contest) Problems Review
 
ACM ICPC 2013 NEERC (Northeastern European Regional Contest) Problems Review
ACM ICPC 2013 NEERC (Northeastern European Regional Contest) Problems ReviewACM ICPC 2013 NEERC (Northeastern European Regional Contest) Problems Review
ACM ICPC 2013 NEERC (Northeastern European Regional Contest) Problems Review
 
ACM ICPC 2016 NEERC (Northeastern European Regional Contest) Problems Review
ACM ICPC 2016 NEERC (Northeastern European Regional Contest) Problems ReviewACM ICPC 2016 NEERC (Northeastern European Regional Contest) Problems Review
ACM ICPC 2016 NEERC (Northeastern European Regional Contest) Problems Review
 
Why GC is eating all my CPU?
Why GC is eating all my CPU?Why GC is eating all my CPU?
Why GC is eating all my CPU?
 
Wait for your fortune without Blocking!
Wait for your fortune without Blocking!Wait for your fortune without Blocking!
Wait for your fortune without Blocking!
 
Многопоточные Алгоритмы (для BitByte 2014)
Многопоточные Алгоритмы (для BitByte 2014)Многопоточные Алгоритмы (для BitByte 2014)
Многопоточные Алгоритмы (для BitByte 2014)
 
Многопоточное Программирование - Теория и Практика
Многопоточное Программирование - Теория и ПрактикаМногопоточное Программирование - Теория и Практика
Многопоточное Программирование - Теория и Практика
 
Пишем самый быстрый хеш для кэширования данных
Пишем самый быстрый хеш для кэширования данныхПишем самый быстрый хеш для кэширования данных
Пишем самый быстрый хеш для кэширования данных
 
The theory of concurrent programming for a seasoned programmer
The theory of concurrent programming for a seasoned programmerThe theory of concurrent programming for a seasoned programmer
The theory of concurrent programming for a seasoned programmer
 
Теоретический минимум для понимания Java Memory Model (для JPoint 2014)
Теоретический минимум для понимания Java Memory Model (для JPoint 2014)Теоретический минимум для понимания Java Memory Model (для JPoint 2014)
Теоретический минимум для понимания Java Memory Model (для JPoint 2014)
 
ACM ICPC 2012 NEERC (Northeastern European Regional Contest) Problems Review
ACM ICPC 2012 NEERC (Northeastern European Regional Contest) Problems ReviewACM ICPC 2012 NEERC (Northeastern European Regional Contest) Problems Review
ACM ICPC 2012 NEERC (Northeastern European Regional Contest) Problems Review
 
MIPT Fall Programming Training
MIPT Fall Programming TrainingMIPT Fall Programming Training
MIPT Fall Programming Training
 
11 x1 t14 06 sum of a geometric series (2012)
11 x1 t14 06 sum of a geometric series (2012)11 x1 t14 06 sum of a geometric series (2012)
11 x1 t14 06 sum of a geometric series (2012)
 
13 3 arithmetic and geometric series and their sums
13 3 arithmetic and geometric series and their sums13 3 arithmetic and geometric series and their sums
13 3 arithmetic and geometric series and their sums
 
Problem solving on acm international collegiate programming contest
Problem solving on acm international collegiate programming contestProblem solving on acm international collegiate programming contest
Problem solving on acm international collegiate programming contest
 
05 динамическое программирование
05 динамическое программирование05 динамическое программирование
05 динамическое программирование
 
Advanced Search Techniques
Advanced Search TechniquesAdvanced Search Techniques
Advanced Search Techniques
 
20130420 bitbyte
20130420 bitbyte20130420 bitbyte
20130420 bitbyte
 
Codefreeze rus
Codefreeze rusCodefreeze rus
Codefreeze rus
 
How to improve java performance
How to improve java performanceHow to improve java performance
How to improve java performance
 

Similar to ACM ICPC 2014 NEERC (Northeastern European Regional Contest) Problems Review

Engineering garphics projection of solids
Engineering garphics   projection of solidsEngineering garphics   projection of solids
Engineering garphics projection of solids
Pranav Kulshrestha
 
Projection of solids
Projection of solidsProjection of solids
Projection of solids
gtuautonomous
 
Projection of solids(thedirectdata.com)
Projection of solids(thedirectdata.com)Projection of solids(thedirectdata.com)
Projection of solids(thedirectdata.com)
India
 
surface development.ppt
surface development.pptsurface development.ppt
surface development.ppt
ssuser6cdd2d
 
1mm1g3a-sumofinteriorandexterioranglesinpolygons-170218173450.ppt
1mm1g3a-sumofinteriorandexterioranglesinpolygons-170218173450.ppt1mm1g3a-sumofinteriorandexterioranglesinpolygons-170218173450.ppt
1mm1g3a-sumofinteriorandexterioranglesinpolygons-170218173450.ppt
ReifalynFulig
 
sum of interior and exterior angles in polygons
   sum of interior and exterior angles in polygons   sum of interior and exterior angles in polygons
sum of interior and exterior angles in polygons
Aneesha Jesmin
 

Similar to ACM ICPC 2014 NEERC (Northeastern European Regional Contest) Problems Review (20)

Engineering garphics projection of solids
Engineering garphics   projection of solidsEngineering garphics   projection of solids
Engineering garphics projection of solids
 
Projection of Solids
Projection of SolidsProjection of Solids
Projection of Solids
 
Projection of solids
Projection of solidsProjection of solids
Projection of solids
 
Projectionofsolids 120517063655-phpapp01
Projectionofsolids 120517063655-phpapp01Projectionofsolids 120517063655-phpapp01
Projectionofsolids 120517063655-phpapp01
 
Projection of solids
Projection of solidsProjection of solids
Projection of solids
 
Projectionofsolids(thedirectdata[1].com)
Projectionofsolids(thedirectdata[1].com)Projectionofsolids(thedirectdata[1].com)
Projectionofsolids(thedirectdata[1].com)
 
5 projection of solids
5 projection of solids5 projection of solids
5 projection of solids
 
Projection of solids(thedirectdata.com)
Projection of solids(thedirectdata.com)Projection of solids(thedirectdata.com)
Projection of solids(thedirectdata.com)
 
UNIT-3 PROJECTION OF SOLIDS.ppt
UNIT-3 PROJECTION OF SOLIDS.pptUNIT-3 PROJECTION OF SOLIDS.ppt
UNIT-3 PROJECTION OF SOLIDS.ppt
 
6. Projection of solids.ppt
6. Projection of solids.ppt6. Projection of solids.ppt
6. Projection of solids.ppt
 
Unit -4.pptx
Unit -4.pptxUnit -4.pptx
Unit -4.pptx
 
surface development.ppt
surface development.pptsurface development.ppt
surface development.ppt
 
1mm1g3a-sumofinteriorandexterioranglesinpolygons-170218173450.ppt
1mm1g3a-sumofinteriorandexterioranglesinpolygons-170218173450.ppt1mm1g3a-sumofinteriorandexterioranglesinpolygons-170218173450.ppt
1mm1g3a-sumofinteriorandexterioranglesinpolygons-170218173450.ppt
 
UNIT-3 PROJECTION OF SOLIDS.ppt
UNIT-3 PROJECTION OF SOLIDS.pptUNIT-3 PROJECTION OF SOLIDS.ppt
UNIT-3 PROJECTION OF SOLIDS.ppt
 
Unit 5
Unit 5Unit 5
Unit 5
 
projection of solids
projection of solidsprojection of solids
projection of solids
 
projection of solide
projection of solideprojection of solide
projection of solide
 
Unit 6
Unit 6Unit 6
Unit 6
 
Projection of planes revised
Projection of planes revisedProjection of planes revised
Projection of planes revised
 
sum of interior and exterior angles in polygons
   sum of interior and exterior angles in polygons   sum of interior and exterior angles in polygons
sum of interior and exterior angles in polygons
 

More from Roman Elizarov

Java Serialization Facts and Fallacies
Java Serialization Facts and FallaciesJava Serialization Facts and Fallacies
Java Serialization Facts and Fallacies
Roman Elizarov
 
Millions quotes per second in pure java
Millions quotes per second in pure javaMillions quotes per second in pure java
Millions quotes per second in pure java
Roman Elizarov
 

More from Roman Elizarov (12)

Kotlin Coroutines in Practice @ KotlinConf 2018
Kotlin Coroutines in Practice @ KotlinConf 2018Kotlin Coroutines in Practice @ KotlinConf 2018
Kotlin Coroutines in Practice @ KotlinConf 2018
 
Deep dive into Coroutines on JVM @ KotlinConf 2017
Deep dive into Coroutines on JVM @ KotlinConf 2017Deep dive into Coroutines on JVM @ KotlinConf 2017
Deep dive into Coroutines on JVM @ KotlinConf 2017
 
Introduction to Coroutines @ KotlinConf 2017
Introduction to Coroutines @ KotlinConf 2017Introduction to Coroutines @ KotlinConf 2017
Introduction to Coroutines @ KotlinConf 2017
 
Fresh Async with Kotlin @ QConSF 2017
Fresh Async with Kotlin @ QConSF 2017Fresh Async with Kotlin @ QConSF 2017
Fresh Async with Kotlin @ QConSF 2017
 
Scale Up with Lock-Free Algorithms @ JavaOne
Scale Up with Lock-Free Algorithms @ JavaOneScale Up with Lock-Free Algorithms @ JavaOne
Scale Up with Lock-Free Algorithms @ JavaOne
 
Kotlin Coroutines Reloaded
Kotlin Coroutines ReloadedKotlin Coroutines Reloaded
Kotlin Coroutines Reloaded
 
Lock-free algorithms for Kotlin Coroutines
Lock-free algorithms for Kotlin CoroutinesLock-free algorithms for Kotlin Coroutines
Lock-free algorithms for Kotlin Coroutines
 
Introduction to Kotlin coroutines
Introduction to Kotlin coroutinesIntroduction to Kotlin coroutines
Introduction to Kotlin coroutines
 
Non blocking programming and waiting
Non blocking programming and waitingNon blocking programming and waiting
Non blocking programming and waiting
 
DIY Java Profiling
DIY Java ProfilingDIY Java Profiling
DIY Java Profiling
 
Java Serialization Facts and Fallacies
Java Serialization Facts and FallaciesJava Serialization Facts and Fallacies
Java Serialization Facts and Fallacies
 
Millions quotes per second in pure java
Millions quotes per second in pure javaMillions quotes per second in pure java
Millions quotes per second in pure java
 

Recently uploaded

Recently uploaded (20)

Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 

ACM ICPC 2014 NEERC (Northeastern European Regional Contest) Problems Review

  • 1. ACM ICPC 2014{2015 Northeastern European Regional Contest Problems Review Roman Elizarov December 7, 2014
  • 2. Problem A. Alter Board I The minimal answer to this problem is bn=2c + bm=2c I The solution is to make inversions on each even row and each even column I To prove that the answer is minimal consider the
  • 3. rst column with its n cells that form n 1 neighbouring pairs I to turn all cells of the
  • 4. rst column in the same color inversions must span the
  • 5. rst column I each spanning inversion makes at most two neighbouring pairs of the same color I so the minimum of d(n 1)=2e = bn=2c inversions are needed I Then consider the top row in the same way
  • 6. Problem B. Burrito King I Consider the problem as a sum of vectors in (a; b) coordinates I The resulting vector may not go above b = B line and must extend on a axis as far as possible I It is optimal to greedily add (ai ; bi ) ingredient vectors starting from the ones that have the least angle to 0a line (or maximal ai=bi ), until b = B line is crossed I Be careful about corner cases with ai = 0 and/or bi = 0 a b B 0 A
  • 7. Problem C. Cactus Generator I This is a straightforward problem for parsing and OO design I De
  • 8. ne class for graph with a method to generate graph given index of the
  • 9. rst and the vertices I De
  • 10. ne class for various range types I Parse and construct classes tree I Build the resulting graph I Connect arbitrary pairs of vertices of odd degree in the resulting graph using temporary edges I Use classical algorithm for Eulerian path I Remove temporary edges to get the minimal number of covering paths
  • 11. Problem D. Damage Assessment I Numerically integrate the square section by dx I The square of the cut at a given x coordinate is a simple planar geometry problem I Take care about leftmost point with in
  • 12. nite derivative I however, the required precision does not make this a big problem I the square section at this point is small x
  • 13. Problem E. Epic Win! I There is a simple solution with up to n2 states I Build your FSM as n copies of a winning FSM with n states I Each state of a winning FSM corresponds to a state in the opponent FSM I Each move of a winning FSM is a winning move for the corresponding opponent's move I Next state in a winning FSM corresponds to the opponent move and opponent's next state I Leave other transitions unde
  • 15. rst copy of a winning FMS starts in its
  • 16. rst state and wins an opponent that stats in it
  • 17. rst state by construction I Model the behaviour of the opponent and your FSM for all opponent start states from the states 2 to n I When a yet unde
  • 18. ned transition is reached, then insert a transition to a fresh copy of a winning FSM into the state corresponding to the opponent's, thus ensuring win in this copy I Stop modelling when loop is detected I Loop is inside one copy of a winning FSM and is always winning by construction
  • 19. Problem F. Filter I Nothing fancy here I Just implement what the problem statement asks for in a straightforward way I The hardest part seems to be reading and understanding the problem statement
  • 21. rst player's strategy has pretty strict priorities in the moves it makes and it can be exploited I Make the
  • 22. rst move into the free space of the board 2 1 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19
  • 23. Problem G. Gomoku cont'd I The opponent must play around the center and you form a diagonal 2 4 3 1 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19
  • 24. Problem G. Gomoku cont'd I The opponent forms three in a row and you make defensive moves 2 4 6 3 1 5 7 8 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19
  • 25. Problem G. Gomoku cont'd I The opponent closes two in a row at one side, and you extend in on the other 10 2 4 9 6 3 1 5 7 8 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19
  • 26. Problem G. Gomoku cont'd I The opponent closes the three on the other side, but you continue oence at building a winning position 11 10 2 4 12 9 6 3 1 5 7 8 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19
  • 27. Problem G. Gomoku cont'd I Force the opponent into a sequence of defensive moves I Then close four in a row with a hole that is formed by the opponent defence 15 11 14 18 10 19 2 20 4 16 12 17 9 13 6 3 1 5 7 8 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19
  • 28. Problem G. Gomoku cont'd I The opponent closes your open three, you extend it, forming a winning fork 15 22 11 14 18 10 19 2 20 4 16 12 17 9 21 13 6 3 1 5 7 8 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19
  • 29. Problem G. Gomoku win I You win I It is very hard to win otherwise, because playing
  • 30. rst in gomoku gives an enormous advantage even to such a simple strategy 26 23 15 22 11 14 18 10 19 2 20 4 16 12 17 24 9 21 13 25 6 3 1 5 7 8 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19
  • 31. Problem H. Hidden Maze I Make a rooted tree I Lets compute how many times each edge is a median I Start with an edge with lowest ci and work in increasing order of ci I For each edge ci look at its lowest vertex j in the tree I For each path from j down into the subtree, let the balance be the number of edges with c higher than current ci minus the number of edges with c lower than current ci I For each vertex j maintain an array bj I with 2dj + 1 elements bj [] for jj di , where dj is a depth of subtree rooted at j I each item bj [] contains a number of paths down from j with a balance I including an empty path with balance zero
  • 32. Problem H. Hidden Maze cont'd I Initial bj [] is the number of paths of a length down from vertex j P I It is easy to compute recursively in O( dj ) while building rooted tree I From the current vertex j walk up the tree I For all vertices k up tree from j compute the number of paths with balance zero going from down up to j , then up to k then down to other subtree of k I paths with zero balance are the ones where ci is the median X =dj :::dj bj [] (bk [ k;j] bk#[ k;j k;k#]) I where k # is the next vertex from k down on the path to j and j is the next vertex up from j I and k;j is the sum of balances on a path from k to j I The total complexity is O( P dj hj ), where hj is the height of vertex j | length of path from root
  • 33. Problem H. Hidden Maze cont'd I Update bj [] when done with an edge ci I For all vertices k up tree from j update the bk arrow taking into account that ci balance changes from 1 to 1 bk [] bk [] + bj [ k;j + 1] bj [ k;j 1] I The total complexity is also O( P dj hj ) I However, for the graph randomly generated as described in the problem statement P (dj hj ) = O(n p n)
  • 34. Problem I. Improvements I Consider transposition aj | the number of ship at coordinate j , that is reverse to what is given in the input I It is easy to prove that the chain of ships that remain on their initial position corresponds to a subsequence of aj with a special property: I it is an increasing sequence of numbers aj followed by decreasing sequence of numbers aj I Increasing/decreasing subsequence is a well-known problem with O(n log n) solution using dynamic programming 0 0 1 1 3 2 4 3 2 4
  • 35. Problem J. Jokewithpermutation I This problem is solved with exhaustive search I for each number try all positions that it can occupy I start search with numbers that can occupy fewest number of possible positions
  • 36. Problem K. Knockout Racing I Nothing fancy here I Just implement what the problem statement asks for in a straightforward way I This is the easiest problem in the contest