Skip to content

davghouse/SPOJ

Repository files navigation

SPOJ

C# solutions to the 200 most-solved problems on SPOJ: www.spoj.com/users/davidgalehouse/

Problems are ranked (roughly) by difficulty using the levels from Civ V, from Settler (easiest) to Deity (hardest).

Submission History

Date Problem Solution Tags Difficulty
2015/04/28 TEST TEST.cs #io Settler
2015/09/20 PRIME1 PRIME1.cs #primes #sieve King
2015/12/28 ADDREV ADDREV.cs #ad-hoc #digits Chieftain
2016/01/01 ONP ONP.cs #parsing #recursion #stack #strings Prince
2016/01/05 FCTRL FCTRL.cs #factorial #factors #math King
2016/06/04 FCTRL2 FCTRL2.cs #big-numbers #factorial Emperor
2016/06/05 SAMER08F SAMER08F.cs #ad-hoc #dynamic-programming-1d #math King
2016/06/05 NSTEPS NSTEPS.cs #ad-hoc Chieftain
2016/06/07 ACPC10A ACPC10A.cs #sequence Warlord
2016/06/08 CANDY CANDY.cs #ad-hoc #division Warlord
2016/06/10 FASHION FASHION.cs #ad-hoc #sorting Prince
2016/06/10 TOANDFRO TOANDFRO.cs #ad-hoc #strings Warlord
2016/06/12 AE00 AE00.cs #division #math Prince
2016/06/12 LASTDIG LASTDIG.cs #digits #mod-math King
2016/06/16 JULKA JULKA.cs #big-numbers #math Emperor
2016/06/19 CANDY3 CANDY3.cs #division #mod-math Warlord
2016/06/19 COINS COINS.cs #dynamic-programming-1d #recursion King
2016/06/25 EIGHTS EIGHTS.cs #digits #math Prince
2016/06/26 HANGOVER HANGOVER.cs #binary-search #sequence Warlord
2016/06/28 PALIN PALIN.cs #ad-hoc King
2016/06/30 ACODE ACODE_v1.cs #dynamic-programming #memoization #recursion King
2016/07/03 WILLITST WILLITST.cs #game #math Prince
2016/07/03 ABSYS ABSYS.cs #ad-hoc #strings Warlord
2016/07/04 CANTON CANTON.cs #ad-hoc #math #sequence King
2016/07/05 STAMPS STAMPS.cs #sorting Warlord
2016/07/06 PERMUT2 PERMUT2.cs #ad-hoc #permutations Prince
2016/07/07 ARMY ARMY.cs #ad-hoc Chieftain
2016/07/09 TRICOUNT TRICOUNT.cs #math #proof King
2016/07/10 AP2 AP2.cs #math #sequence Prince
2016/07/10 FENCE1 FENCE1.cs #math Warlord
2016/07/10 STPAR STPAR.cs #ad-hoc #greedy #stack King
2016/07/12 PT07Y PT07Y.cs #graph-theory #tree King
2016/07/16 GIRLSNBS GIRLSNBS.cs #division Warlord
2016/07/17 NGM NGM.cs #game King
2016/07/17 INVCNT INVCNT.cs #ad-hoc #bst Emperor
2016/07/21 CRDS CRDS.cs #ad-hoc #sequence Warlord
2016/07/21 EDIST EDIST.cs #dynamic-programming-2d #strings Emperor
2016/07/26 BEENUMS BEENUMS.cs #formula #math #proof King
2016/08/02 PT07Z PT07Z.cs #bfs #graph-theory #longest-path #proof #tree Immortal
2016/08/07 AGGRCOW AGGRCOW.cs #binary-search #greedy #optimization Emperor
2016/08/08 BISHOPS BISHOPS.cs #ad-hoc #math Prince
2016/08/08 BYTESM2 BYTESM2.cs #dynamic-programming-2d #path-optimization King
2016/08/09 OLOLO OLOLO.cs #binary #io Emperor
2016/08/09 OFFSIDE OFFSIDE.cs #ad-hoc Prince
2016/08/10 MAXLN MAXLN.cs #math #proof King
2016/08/11 HPYNOS HPYNOS.cs #digits #simulation Prince
2016/08/11 NY10A NY10A.cs #buckets #sorting #strings Warlord
2016/08/14 LASTDIG2 LASTDIG2.cs #big-numbers #digits #mod-math King
2016/08/14 HUBULLU HUBULLU.cs #game #proof Emperor
2016/08/15 EASYPROB EASYPROB.cs #binary #recursion Prince
2016/08/15 ARITH2 ARITH2.cs #ad-hoc #parsing #strings Prince
2016/08/21 GSS1 GSS1.cs #divide-and-conquer #segment-tree Immortal
2016/09/05 BITMAP BITMAP.cs #bfs King
2016/09/05 PARTY PARTY.cs #dynamic-programming-2d #knapsack #optimization King
2016/09/07 ETF ETF.cs #factors #formula #math #primes #sieve Emperor
2016/09/08 MARBLES MARBLES.cs #big-numbers #combinatorics #math King
2016/09/09 TRT TRT_v1.cs #memoization #optimization #recursion Emperor
2016/09/10 EGYPIZZA EGYPIZZA.cs #ad-hoc #division Prince
2016/09/10 AMR10G AMR10G.cs #sorting King
2016/09/11 AIBOHP AIBOHP.cs #dynamic-programming-2d #optimization Emperor
2016/09/12 FARIDA FARIDA.cs #dynamic-programming-1d Prince
2016/09/14 ANARC09A ANARC09A.cs #greedy #recursion #stack Emperor
2016/09/17 PIGBANK PIGBANK_v1.cs #dynamic-programming-1d #knapsack #optimization King
2016/09/17 NHAY NHAY.cs #strings Emperor
2016/09/18 MIXTURES MIXTURES.cs #dynamic-programming-2d #memoization #optimization Emperor
2016/09/19 SBANK SBANK.cs #hash-table #radix-sort #sorting Emperor
2016/09/19 JAVAC JAVAC.cs #ad-hoc #strings Warlord
2016/09/21 QUADAREA QUADAREA.cs #formula Chieftain
2016/09/21 HOTELS HOTELS.cs #greedy #optimization #sliding-window King
2016/09/22 DOTAA DOTAA.cs #ad-hoc #division #game #io Warlord
2016/09/25 HORRIBLE HORRIBLE_v1.cs #divide-and-conquer #lazy #segment-tree Immortal
2016/10/02 BUGLIFE BUGLIFE.cs #dfs #graph-theory Emperor
2016/10/02 FACEFRND FACEFRND.cs #ad-hoc #hash-table Prince
2016/10/02 GUESSING GUESSING.txt #ad-hoc Chieftain
2016/10/02 GCD2 GCD2.cs #big-numbers #gcd #math Prince
2016/10/03 ARRAYSUB ARRAYSUB.cs #deque #sliding-window Emperor
2016/10/04 GSS3 GSS3.cs #divide-and-conquer #segment-tree Immortal
2016/10/05 TWOSQRS TWOSQRS.cs #factors #math #mod-math #primes #sieve Emperor
2016/10/06 ANARC05B ANARC05B.cs #sequence #sorting King
2016/10/07 TDPRIMES TDPRIMES.cs #primes #sieve King
2016/10/08 ABCDEF ABCDEF.cs #ad-hoc #combinatorics #hash-table #math Emperor
2016/10/09 MAJOR MAJOR_v1.cs #ad-hoc King
2016/10/09 ACPC11B ACPC11B.cs #binary-search #merge #sorting King
2016/10/10 PPATH PPATH.cs #graph-theory #primes #sieve Emperor
2016/10/11 FIBOSUM FIBOSUM.cs #formula #math #memoization #mod-math #sequence Emperor
2016/10/12 PIR PIR.cs #formula #math Warlord
2016/10/12 ENIGMATH ENIGMATH.cs #gcd #math Prince
2016/10/14 SILVER SILVER.cs #ad-hoc #binary #combinatorics #proof Emperor
2016/10/14 COMDIV COMDIV.cs #division #factors #io #math #primes #sieve Emperor
2016/10/15 AMR12D AMR12D.cs #ad-hoc #strings Warlord
2016/10/15 GLJIVE GLJIVE.cs #ad-hoc #binary #sequence Prince
2016/10/15 DANGER DANGER.cs #formula #game #math Prince
2016/10/16 HISTOGRA HISTOGRA.cs #ad-hoc #optimization #sliding-window #stack Immortal
2016/10/16 MCOINS MCOINS.cs #dynamic-programming #game King
2016/10/17 ACPC10D ACPC10D.cs #dynamic-programming-2d #path-optimization King
2016/10/17 ALICESIE ALICESIE.cs #division #sieve Prince
2016/10/18 PHONELST PHONELST.cs #strings #trie Emperor
2016/10/19 CPRMT CPRMT.cs #ad-hoc #buckets #strings Prince
2016/10/19 MISERMAN MISERMAN.cs #dynamic-programming-2d #path-optimization King
2016/10/22 DISUBSTR DISUBSTR.cs #sorting #strings #suffixes Emperor
2016/11/12 BYECAKES BYECAKES.cs #ad-hoc #division #optimization Warlord
2016/11/12 FAVDICE FAVDICE.cs #math #probability #proof Emperor
2016/11/12 DIEHARD DIEHARD.cs #game #memoization King
2016/11/14 DQUERY DQUERY.cs #bit #offline #sorting Deity
2016/11/16 SUMITR SUMITR.cs #dynamic-programming-2d #golf #path-optimization King
2017/02/26 CSTREET CSTREET.cs #graph-theory #greedy #heap #mst #prims Immortal
2018/04/10 BUSYMAN BUSYMAN.cs #ad-hoc #greedy #sorting King
2018/07/08 ABCPATH ABCPATH.cs #dag #dfs #greedy #memoization King
2018/07/08 KGSS KGSS.cs #divide-and-conquer #segment-tree Immortal
2018/07/09 HACKRNDM HACKRNDM_v1.cs #sliding-window #sorting King
2018/07/23 SHPATH SHPATH.cs #dijkstras #graph-theory #greedy #heap #shortest-path Immortal
2018/07/26 AMR11E AMR11E.cs #factors #math #primes #sieve King
2018/07/26 SUMFOUR SUMFOUR.cs #ad-hoc #binary-search #combinatorics #hash-table Emperor
2018/07/27 MUL MUL.cs #big-numbers Chieftain
2018/07/28 BRCKTS BRCKTS.cs #divide-and-conquer #segment-tree Immortal
2018/07/29 LABYR1 LABYR1.cs #bfs #graph-theory #longest-path #proof #tree Immortal
2018/07/30 MICEMAZE MICEMAZE.cs #dijkstras #graph-theory #greedy #heap #shortest-path Immortal
2018/08/03 LCA LCA.cs #divide-and-conquer #graph-theory #lca #segment-tree #stack #tree Immortal
2018/08/09 INTEST INTEST.cs #io Emperor
2018/08/11 INOUTEST INOUTEST.cs #io Emperor
2019/01/04 QTREE QTREE_v1.cs #divide-and-conquer #graph-theory #hld #lca #segment-tree #tree Deity
2019/01/06 CADYDIST CADYDIST.cs #ad-hoc #sorting Warlord
2019/01/06 EC_CONB EC_CONB.cs #ad-hoc #binary Warlord
2019/01/07 RPLC RPLC.cs #ad-hoc Warlord
2019/01/07 CAM5 CAM5.cs #dfs #disjoint-sets Emperor
2019/01/09 BOMARBLE BOMARBLE.cs #math Warlord
2019/01/10 ABSP1 ABSP1.cs #ad-hoc #proof Prince
2019/01/11 ROOTCIPH ROOTCIPH.cs #factors #formula #io #math Immortal
2019/01/13 MRECAMAN MRECAMAN.cs #ad-hoc #memoization Warlord
2019/01/13 UPDATEIT UPDATEIT.cs #bit Immortal
2019/01/13 BYTESE2 BYTESE2.cs #ad-hoc #sorting King
2019/01/13 TRGRID TRGRID.cs #ad-hoc #recursion King
2019/01/14 JNEXT JNEXT.cs #ad-hoc #greedy #sorting King
2019/01/14 NY10E NY10E.cs #dynamic-programming-2d King
2019/01/15 ZSUM ZSUM.cs #ad-hoc #math #mod-math #sequence King
2019/01/16 POUR1 POUR1.cs #ad-hoc #mod-math #simulation Emperor
2019/01/17 NOTATRI NOTATRI.cs #binary-search #sliding-window #sorting Emperor
2019/01/18 LENGFACT LENGFACT.cs #formula #math Prince
2019/01/18 CRSCNTRY CRSCNTRY.cs #dynamic-programming-2d King
2019/01/19 NAKANJ NAKANJ.cs #bfs King
2019/01/19 PERMUT1 PERMUT1.cs #dynamic-programming-2d #permutations Emperor
2019/01/24 ABA12C ABA12C.cs #dynamic-programming-2d #knapsack #optimization Emperor
2019/01/25 TWENDS TWENDS.cs #dynamic-programming-2d #game #optimization Emperor
2019/01/26 GAMES GAMES.cs #ad-hoc #gcd #proof King
2019/01/26 CUBEFR CUBEFR.cs #sieve Prince
2019/01/26 ALIEN ALIEN.cs #sliding-window Emperor
2019/01/27 EKO EKO.cs #binary-search #sorting Emperor
2019/01/27 ONEZERO ONEZERO.cs #ad-hoc #bfs #bitmask #mod-math Emperor
2019/01/27 ASSIGN ASSIGN.cs #bitmask #dynamic-programming Immortal
2019/01/28 CHOCOLA CHOCOLA.cs #ad-hoc #greedy #sorting Emperor
2019/01/29 DSUBSEQ DSUBSEQ.cs #dynamic-programming #memoization #mod-math Emperor
2019/01/29 TSHOW1 TSHOW1.cs #binary #math King
2019/01/30 ATOMS ATOMS.cs #math Warlord
2019/01/30 HIGHWAYS HIGHWAYS.cs #dijkstras #graph-theory #greedy #heap #shortest-path Immortal
2019/01/30 PT07X PT07X.cs #graph-theory #greedy Emperor
2019/01/31 MFLAR10 MFLAR10.cs #ad-hoc Warlord
2019/01/31 CEQU CEQU.cs #formula #gcd #math King
2019/01/31 EBOXES EBOXES.cs #math Prince
2019/02/01 IITKWPCB IITKWPCB.cs #factors #math #proof King
2019/02/02 BWIDOW BWIDOW.cs #ad-hoc Warlord
2019/02/02 SCPC11B SCPC11B.cs #ad-hoc #sorting Warlord
2019/02/02 ANARC09B ANARC09B.cs #gcd Prince
2019/02/02 SPEED SPEED.cs #ad-hoc #gcd #math Emperor
2019/02/03 UJ UJ.cs #big-numbers Warlord
2019/02/03 WACHOVIA WACHOVIA.cs #dynamic-programming-2d #knapsack #optimization King
2019/02/03 MAYA MAYA.cs #ad-hoc Warlord
2019/02/03 STREETR STREETR.cs #ad-hoc #gcd Prince
2019/02/03 WORDCNT WORDCNT.cs #ad-hoc Warlord
2019/02/03 POLEVAL POLEVAL.cs #ad-hoc Warlord
2019/02/04 RPLN RPLN.cs #divide-and-conquer #segment-tree Immortal
2019/02/04 BLINNET BLINNET.cs #disjoint-sets #mst Emperor
2019/02/05 SUBST1 SUBST1.cs #sorting #strings #suffixes Emperor
2019/02/05 QTREE2 QTREE2.cs #divide-and-conquer #graph-theory #lca #segment-tree #tree Immortal
2019/02/06 APS APS.cs #factors #primes #sieve Emperor
2019/02/06 SHOP SHOP.cs #dijkstras #graph-theory #greedy #heap #shortest-path Immortal
2019/02/07 ANARC08H ANARC08H.cs #formula #game King
2019/02/07 CODESPTB CODESPTB.cs #bit #sorting Immortal
2019/02/08 NEG2 NEG2.cs #ad-hoc #binary Emperor
2019/02/09 CATM CATM.cs #bfs #simulation King
2019/02/09 PON PON.cs #math #primes Emperor
2019/02/10 SQRBR SQRBR.cs #dynamic-programming-2d Emperor
2019/02/10 ROCK ROCK.cs #dynamic-programming-2d Emperor
2019/02/10 IOIPALIN IOIPALIN.cs #dynamic-programming-2d #optimization Emperor
2019/02/10 ELEVTRBL ELEVTRBL.cs #bfs Prince
2019/02/10 ANARC05H ANARC05H.cs #dynamic-programming-2d Emperor
2019/02/11 LITE LITE.cs #divide-and-conquer #lazy #segment-tree Immortal
2019/02/11 SCUBADIV SCUBADIV.cs #memoization #recursion Emperor
2019/02/12 FREQUENT FREQUENT.cs #divide-and-conquer #segment-tree Immortal
2019/02/12 CPCRC1C CPCRC1C.cs #ad-hoc #digits Emperor
2019/02/13 YODANESS YODANESS.cs #ad-hoc #bst Emperor
2019/02/13 MATSUM MATSUM.cs #bit Immortal
2019/02/13 PIE PIE.cs #binary-search #optimization Emperor
2019/02/13 ALLIZWEL ALLIZWEL.cs #dfs #recursion Emperor
2019/02/14 MULTQ3 MULTQ3.cs #divide-and-conquer #lazy #segment-tree Deity
2019/02/14 M3TILE M3TILE.cs #ad-hoc #dynamic-programming #recursion Emperor
2019/02/14 GNYR09F GNYR09F.cs #binary #dynamic-programming-3d King
2019/02/15 BEADS BEADS.cs #ad-hoc #sorting King
2019/02/15 CHICAGO CHICAGO.cs #dijkstras #graph-theory #greedy #heap #shortest-path Immortal
2019/02/15 RENT RENT.cs #binary-search #dynamic-programming-1d #sorting Emperor
2019/02/16 WORDS1 WORDS1.cs #euler-path #graph-theory Immortal
2019/02/16 BABTWR BABTWR.cs #ad-hoc #dynamic-programming-1d Emperor
2019/02/17 KQUERY KQUERY.cs #bit #offline #sorting Immortal
2019/02/18 MKTHNUM MKTHNUM.cs #binary-search #divide-and-conquer #merge #segment-tree #sorting Deity
2019/07/14 CMPLS CMPLS.cs #math #sequence King
2019/09/12 ORDERSET ORDERSET.cs #binary-search #bit #compression #offline #sorting Deity
2020/03/04 GERGOVIA GERGOVIA.cs #greedy King

Notes

Solutions are unit tested, which relies on compiling them from source programmatically using Roslyn. This is necessary because I want them to be submittable to SPOJ without modification or namespace clutter, so their build actions have to be set to none to prevent compilation errors like CS0101 and CS0017.

To keep everything clean, I/O is separated from the actual problem solving. Performance of .NET's number parsing and Console I/O can be an issue. I use them whenever possible, but custom I/O handling is sometimes necessary.

Reusable components are housed in the Spoj.Library project. Due to performance concerns I usually don't bother programming with extensibility or safety in mind.

Releases

No releases published

Packages

No packages published