Powered by Starship v1.3

Tag: programming

main page
Cheesing CSES Cut and Paste with a skiplist
Mar 27 2025
8:16 PM

https://cses.fi/problemset/task/2072/

Treap is the intended solution to this task, but I didn't know treap well enough to write it on the spot. I did however know skiplist (which imo is less complicated) and so I ended up implementing this goofball:

...

read more

tags: programming cses

A possibly unusual way to solve CSES Increasing Array Queries
Mar 26 2025
12:08 PM

https://cses.fi/problemset/task/2416/

I had been kinda stuck on this for a while, mostly because I was trying to use some weird segtree bash.

...

read more

tags: programming cses

Funniest DFS ever
Dec 27 2024
11:41 AM

Continuation of my previous post about pattern-matching.

Previously, I explained how to use a depth-first-search of a trie to compute pattern-matchings in a set of strings. However, explicit trie used too much memory for the specific task I was trying to apply it on. (64 megabyte limit)

So I took some advice from Alternet and made the trie implicit - rather than even storing intermediate nodes, the entropy of the strings being stored in the trie was low enough that storing each query individually and sorting it took up less memory than a trie. Then this sorted array could be "dfsed" with divide-and-conquer.

...

read more

tags: programming

A funny pattern-matching technique
Dec 26 2024
11:19 PM

Hey yall. Been a while.

I 'discovered' an interesting way to pattern-match certain types of strings today. Extended writeup on Codeforces

Enjoy!

tags: programming

Floyd-Warshall arises naturally from matrix operations
Nov 30 2024
12:31 PM

Recall that the Floyd-Warshall algorithm computes shortest paths between every pair of nodes. It does so by repeatedly "combining" paths into longer ones: Given three distinct nodes a, b, c form the new path a -> c from the two paths a -> b, b -> c and check if it is an improvement.

How does this "arise" from matrix exponentiation?

...

read more

tags: programming

Atcoder Beginner 382
Nov 30 2024
8:47 AM

It's been a decent while since I did one of these. Speed still seems to be ok.

Solves:

  • A @ 1 minute 6 sec. Very standard

  • B @ 4 minute 4 sec. Also standard

  • C @ 9 minute 10 sec. Wrote some montonic array & binary search

  • D @ 14 minute 49 sec. DFS-like ordered sequence builder

  • F @ 52 minute 12 sec. RMQ + range set segtree on sorted list

tags: programming atcoder contest-logs

Tarjan's algorithm is cool
Nov 1 2024
2:17 PM

This post is protected by encryption. Unlock

FGouHpgtkAaTc9eSWB9Xvn15fzXBEmeVHeC0Mlz2IaFSMFfFsaH44HGO5Gc+9hWC1s+EGgxJhH/Wi6IhNQFRZA==

1BBb+QMvnTIAzvw5Uld43lx8rkKTzR+WW8bgIUJN+L0=


Solved CSES Coin Collector - first time working with SCC!

but ya tarjan is cool :D

...

read more

tags: programming

Encrypted posts!
Oct 30 2024
5:56 PM

This post is protected by encryption. Unlock

e8URR5thE7IdPweCFoFlAoQhc+Z+tnTIONC/N9VR/Kg=


Encryption is done via AES. The password used above is a good password, enjoy!

tags: programming starship-dev

Non-linear problem difficulty
Oct 27 2024
2:54 PM

"This ARC also serves as a qualification round to select the 18 contestants for the Japanese national finals, making it significantly more difficult than a regular ARC. Due to circumstances, we replaced the tasks and changed the point values. Since there are no easy tasks, the difficulty level of solving one or more tasks has increased. Please be careful. Since the difficulty level is flat, we recommend reading all the tasks and not necessarily solving them in order."

pov i forget to read this and consequently spend the entire contest on A (and fail to solve)

...

read more

tags: programming atcoder

fun trie problem
Oct 26 2024
10:27 AM

This problem is from today's atcoder beginner contest

You are given a list A of lowercase English strings.
For each string S in A, solve the following problem:

You can perform two operations to S:

- Delete the last character of S (if it is non-empty)
- Add any lowercase character to the end of S

Find the minimum number of operations to convert S into either the empty string or a string that comes before it in A.

This kind of screams trie...

read more

tags: programming atcoder contest-logs

ARC is scary
Oct 13 2024
1:44 PM

Took Atcoder Regular Contest 185 this morning. I had done one ARC virtual in the past, but that one had relatively more 'normal' questions than today's contest. I think it went alright? I don't really have a sense of scale with ARC yet.

...

read more

tags: programming atcoder contest-logs

Atcoder Beginner Contest 375
Oct 12 2024
10:06 AM

I should put more effort into these surely...

read more

tags: programming atcoder contest-logs

Atcoder Beginner Contest 374
Oct 5 2024
10:27 AM

Woke up 10 min before contest, slow start but wow.. good contest I think

...

read more

tags: programming atcoder contest-logs

CSES Fixed-Length Paths I
Oct 4 2024
4:10 PM

Problem statement

Actually very similar problem to IOI11p2 (Race) which I did last weekend, using centroid decomposition and then naive dp. Decided to write this one in C*, which was surprisingly easy.

...

read more

tags: programming cses

le brick
Oct 1 2024
10:54 PM

vced ARC 058 w/ jasonwei

C was theoretically easy, construct from smallest digit, etc. but I messed up overflow case [twice] and that whole mess took like 30m total

D was fun combo, pathfinding nonsense that partition & track crossings kind of deleted

E was some DP that I failed, also managed to forget that complementary counting existed.. smh

didn't have anything substantial on F besides "knapsack" so ya

mid contest, definitely need to work on dp

tags: programming atcoder contest-logs

2011 IOI
Oct 1 2024
4:43 PM

Easier contest (by nature of its age) but still pretty fun. Due to schedule I started around 3 pm and therefore ended at 8, on both days, so didn't have much time to writeup each day separately.

...

read more

tags: programming ioi contest-logs

Atcoder Beginner Contest 373
Sep 28 2024
10:35 AM
  • A: trivial

  • B: invert array, trivial

  • C: trivial

  • D: pretty cool, restructure directed graph as an undirected graph w/ directed weight, DFS

  • E: possibly some sort of ranging and binary search, couldn't work out implementation

  • F: tried to run the knapsack dp as normal but store a best_cost[] alongside, and attempted to use some quasi-convexity and 2p to speed up choice but this did not work (AC x53, WA x5)

  • G: impossible wtf jasonwei orz

terrible perf lol. should I take the upcoming AGC? idk.

tags: programming atcoder contest-logs

2014 IOI day 2
Sep 19 2024
11:39 AM

Took the contest 2 days ago but was pretty busy yesterday (with some discrete math project skull) so doing writeup rn in school lmao

...

read more

tags: programming ioi contest-logs

2014 IOI day 1
Sep 17 2024
9:27 AM

Virtualed IOI14d1 yesterday. Due to time (18:30 - 23:30) I didn't feel like writing up last night, so I'm just doing this while bored at school :p

...

read more

tags: programming ioi contest-logs

"When wil calc BC ever be useful to me?"
Sep 11 2024
7:57 PM

Today, I was working on some 3d matrix projection stuff for some simulation, and needed a simple sin() approximation. Because I was writing this in a non-compileime CBAS segment, I didn't have access to <math.h>, and was too lazy to add builtin trig functions. That's when I remembered: calc has a pretty simple way to approximate complicated functions with polynomials!

Even better, I didn't need an approximation that would work over all input values of theta - only between -pi/2 and pi/2, so a taylor series to three terms did the trick:

...

read more

tags: programming math

Atcoder Beginner Contest 370 (and weird binary search?)
Sep 7 2024
10:48 AM

Decent contest. Started 6 min late bc I lost track of time while debugging some cses problem :/ but it was fine..

ABC were basically trivial, C had a pretty simple pattern (provable by optimal-choice argument) which I got relatively quickly. D was an adventure, though.

Task essentially asks us to determine in a 2d bitfield the...

read more

tags: programming atcoder contest-logs

alleged cses grind
Sep 2 2024
6:00 PM

@ the halfway point
it only gets harder...

read more

tags: programming cses

d1 fumbler (me)
Aug 31 2024
11:39 AM

I did the ABC today: https://atcoder.jp/contests/abc369

The fumbling started on problem A, where I misread the input format and consequently got 2 WA (don't worry why this caused 2 WA and not 1). Then I did a dumb thing...

read more

tags: programming atcoder contest-logs

implementation implementation implementation
Aug 24 2024
12:28 AM

I finally stopped procrastinating on upsolving IOI18 day 1 p2 today.. lol

The implementation of this problem was some 2d grid swap updates that update a segtree... overall just a massive pain to deal with


I started writing up (for specifically subtask 5, which enforced that the grid was a line) my solution this morning, building off of the stuff I had from the virtual. Then I kinda got distracted with some cses problems and...

read more

tags: programming ioi

Should I use normal binlift
Aug 22 2024
8:42 PM

Up until about now I've been using the binlift from this cf blog, which is linear in space and build complexity, but has a higher constant factor. This has really never been useful to me, and it's a little more complicated to write, too..

tags: programming codeforces

2018 IOI day 1
Aug 20 2024
12:04 AM

Completed the second half of IOI18. Performance was kinda eh, but wasn't expecting much :clown:


0:00 - 1:30

Solved Combo. Essentially the construction I found was to guess the next 2 bits in the sequence over the course of two queries: there were 3^2 = 9 possible arrangements of next bits, and each query had three possible return values, which worked out to a...

read more

tags: programming ioi contest-logs

Getting trolled by subtasks (again)
Aug 18 2024
10:48 PM

I was attempting some afternoon funsies for most of today, which I basically totally bricked.

Here is a hopefully not too scuffed breakdown. (would say it has spoilers, but I barely solved any of the actually interesting problems so nah)

...

read more

tags: programming ioi contest-logs

Sqrt Exponentiation
Aug 17 2024
1:17 PM

While helping out a friend on some CSES exponentiation problem, I came up with this humorous way to compute fast exponentiate:

So you see, the standard way to go about this sort of problem is to use binary exponentiation. But sometimes when there is a log based solution, there is a somewhat similar sqrt solution.

...

read more

tags: programming

Activation energy
Aug 14 2024
2:03 PM

Hey yall. Been a while :P

My schedule has been kinda strange ever since coming back from road trip - firstly I started a project with some friends over that trip, SARA, which took up a decent portion of my first few days back. Then I had to deal with some school related stuff, and got involved with a new project after that... and all in all I haven't had had as much time to work on contest recently, or update this blog.

Finally decided to allocate a block of time to updating blog, so here we are! (hence the title)

Also, now that most of the projects I've been working on are at reasonably complete stages, I can talk a bit about them here! This is a short overview of what I've been up to recently:

...

read more

tags: programming life

Square Root Decomposition is underrated
Jul 24 2024
9:01 PM

Finished up ccc '17 s5, which I failed to get in yesterday's practice contest. Ended up using sqrt bucketing, which I've never used before.

...

read more

tags: programming ccc

CSS-only image expansion on click
Jul 24 2024
10:54 AM

Completely JS free...

read more

tags: programming

Binlifting <3
Jul 23 2024
10:13 PM

I very recently finished this USACO gold question, and my friend was interested in my (mildly scuffed) binary lifting approach. Here it is, I guess :P

...

read more

tags: programming usaco

CCC 2017 Senior Division
Jul 23 2024
2:41 PM

Simulated this contest today - here are my notes and solutions!

...

read more

tags: programming ccc contest-logs

CCC 2018 Senior Division
Jul 22 2024
8:23 PM

Not much, just my solutions and some comments from my practice contest today :)

Spoiler warning - contains full solutions!

...

read more

tags: programming ccc contest-logs

No more manual code formatting!
Jul 22 2024
12:59 PM

For c-like languages, that is :P

Anyway, I got tired of adding in hundreds of <span> elements anytime I wanted to put up pretty code on my posts, so I wrote this script. It works pretty well!

Example formatting of one of my various half-finished CSES solutions:

...

read more

tags: starship-dev programming

The m in logn stands for magic
Jul 19 2024
10:22 PM

I swear binary exponentiation on matrices is actually magic.

While explaining this CSES problem to a friend, it occured to me that I could improve my O(n) solution, which used state machine DP, into a O(log n) one, by using matrix exp.

But even though I've used it quite a few times before, it still feels like magic. Take this task for example:

...

read more

tags: programming cses math

Bad CF Practices, part 2
Jul 19 2024
11:43 AM

Today I was working through another simulated CCC contest and noticed how codeforces/speedforces has shaped my problem triage process - as CF doesn't award partials, my brain has gotten used to this decision tree:

...

read more

tags: programming codeforces

Bad CF Practices
Jul 18 2024
12:06 PM

So today I was working on this problem on DMOJ.

First, some observations:

  • We're dealing with a tree of max size 2e5
  • Result is the count of some type of paths
  • DP contained-subtree etc etc

Constraint analysis: Result is bounded by something on the order of 4e10, higher than the 32-bit limit.

This is where my bad CF habits kick in...

read more

tags: programming codeforces

A rigid-body 2d physics engine!
Jul 8 2024
9:03 PM

Continuation of this post


Previously, we created a basic particle-based physics engine. Each point was stored as simply a position and velocity, and iterated to produce natural-looking motion.

How can we extend this to more complex shapes?

Before we even try to simulate such shapes, we'll need a way to store them. A simple point can be represented fully with a position and velocity, as...

read more

tags: programming

The beginnings of a 2d physics engine
Jul 7 2024
1:40 PM

In this blog post, we'll be covering the basics of how iteration-based physics works,and then implementing a very simple proto-engine in C.


Let's start with some background on iterative simulations as a whole.

Essentially all computer animations are done iteratively. Computer displays have a finite...

read more

tags: programming