Solutions to Kattis competitive programming exercises, mainly in Python 3.
I also write detailed solution pages for particularly interesting exercises that I solve (see list with links in below section).
Many of the non-trivial exercises have a NOTES
comment in source file with thought process/reasoning/observations.
Email me with any comments or questions.
I try to keep same variable names as used in the Kattis problem statement, unless they are really confusing.
Otherwise I try to stick to the following notation when solving exercises:
Click to expand general notation for variables
s : a string
c : a single character
d : a dictionary/hashmap
res : whatever the final result is
inps : if inputs require some kind of processing
curr,prev,best : when doing some kind of updating of current vs. previous vs. overall best values
cnt : when counting something
seen : when storing some kind of lookup of previously seen values, visited nodes in a graph, etc.
flg : a flag boolean for exiting loops or tracking if conditions are met
t,T,tc,TC : testcases
q,Q : queries
x,xs : generic names for moving through an iterable
r,c,R,C,dr,dc : current row/column, number of rows/columns in a grid, change in row/column
moves : allowed moves in some kind of grid or maze, e.g. [(-1,0), (0,1)]
board,grid : state of some kind of input maze/game board/grid configuration
acc : accumulator/range sum
dp : dynamic programming array
goods,bads : for combinatorics exercises when counting good/bad objects or states
stk : a stack
q,pq : queue, priority queue of some kind
ss,mm,hh : when working with dates and times
hi,lo,mid : when binary searching
PRECOMPUTE,LOOKUP,REF : in exercises with multiple queries of a precomputed answer
Exercises which I found particularly interesting for some reason, and decided to write-up a solution page:
- Lucky Draw - kattis: luckydraw
- Swap Space - kattis: swapspace
- Sequential Manufacturing - kattis: sequentialmanufacturing
- Exits in Excess - kattis: exitsinexcess
- Please, Go First - kattis: pleasegofirst
- Farey Sums - kattis: fareysums
- Lopsided Lineup - kattis: lopsidedlineup
- Distance - kattis: distance
- Factorial Power - kattis: factorialpower
- Burizon Fort - kattis: burizonfort
- Johnny Applesack - kattis: applesack
- Accounting a.k.a. Bokforing - kattis: bokforing
- Jumping Yoshi - kattis: jumpingyoshi
- Ada Loveslaces - kattis: adaloveslaces
- Digit Division - kattis: digitdivision
- Integer Estate Agent - kattis: estate
- The Paladin - kattis: thepaladin
- Srednji - kattis: srednji
- Left and Right - kattis: leftandright
- Dams in Distress - kattis: damsindistress
- Sums - kattis: consecutivesums
- Divisible Subsequences - kattis: divisible
- Joyless Game - kattis: joylessgame
- Powers and Modulus - kattis: powers
- Clock Construction - Kattis: clockconstruction
- Divisibility Shortcut - Kattis: shortcut
- Eko - Kattis: eko
- The Sound of Silence - Kattis: sound
- Escape from Enemy Territory - Kattis: enemyterritory
- Happy and Unhappy Numbers - Kattis: happyandunhappynumbers
- Alehouse - Kattis: alehouse
- Razbibriga - Kattis: razbibriga
- Common Factors - Kattis: commonfactors
- ICPC Team Selection - Kattis: icpcteamselection
- Boiling Vegetables - Kattis: vegetables
- Spiderman - Kattis: spiderman
- Wolf - Kattis: wolf
- Tram - Kattis: tram
- Envious Exponents - Kattis: enviousexponents
- Canvas Line - Kattis: canvasline
- Kratki - Kattis: kratki
- Logland - Kattis: logland
- Low Power - Kattis: low
- Stop Counting! - Kattis: stopcounting
- Chemist's Vows - Kattis: chemistsvows
- Research Productivity Index - Kattis: researchproductivityindex
- Combination Lock - Kattis: combinationlock
- Financial Planning - Kattis: financialplanning
- Svada - Kattis: svada
- Orderly Class - Kattis: orderlyclass
- ETA - Kattis: eta
- Delft Distance - Kattis: delftdistance
- Irrational Division - Kattis: irrationaldivision
- Pianino - Kattis: pianino
- Reservoir - Kattis: reservoir
- LCM Pair Sum - Kattis: lcmpairsum
- Eidam-Sand Lair - Kattis: eidamsandlair
- Andrew the Ant - Kattis: andrewant
- Cake - Kattis: cake
- Frogger - Kattis: frogger
Current list of exercises to write-up
- Ocean Monument
- Brick Wall (redo the dynamic programming approach)