Monday, August 3, 2026

Solving 3,000+ onlinejudge.org problems in 3 weeks using modern LLM coding agent

The onlinejudge.org is one of the oldest online judges (see Grokipeida for the history). My first submission was 26 years ago (2000-01-14 09:47) and the first 14 years were really formative years for me, using the online judge to develop my critical thinking, algorithm and data structures, as well as coding skills and speed. I've solved 1,521 problems by myself (with hints from the web), but since then I've been struggling to find time to continue this developments.

In the recent advent of LLM (large language models), I'm curious how far can a modern LLM coding agent solve problems from this online judge? so I did an experiment to use Antigravity ($20 subscription) and Claude Code ($100 subscription) and ask it to solve as many problems it can. In summary, Antigravity (Gemini 3.6 Flash) and Claude Code (Opus 5 + Fable 5) together can solve additional 3,354 of my unsolved problems in 3 weeks. FYI, it did write most of the solutions by itself before falling back to the web for hints when stuck.

So, it's true that modern LLM coding agent can solve about 97% competitive programming problems (at least those problems that already circulated in the web) easily and really fast too. I would (approximately) say that with Antigravity + Gemini 3.6 Flash you can use it to solve 90% easiest problems, the next 6% harder problems with Claude Code + Opus 5 and the last 1% hardest problem with Claude Code + Fable 5.

Solving 1 problem every 9 minutes

You may be wondering how did I use the LLM coding agent to solve 3,354 problems in 3 weeks (i.e., 1 problem every 9 minutes)? Did I manually copy paste each problem to the Claude Code every 9 minutes for the entire 3 weeks? Yeah... no. I used skills!

Skills for solving a problem

A skill is just a markdown file containing a tutorial of how-to do a certain task for the LLM coding agent to follow. You just write the skill once and then you can refer to it again and again in a prompt. For example, when submitting a C++ solution to an online judge, you need to first login to the onlinejudge.org, then open the quick-submit page then fill in the forms specifying the problem number, language, and upload the C++ solution. To create a skill, you can just prompt Claude Code to write a skill to do that and save it in a skills folder named "skills/submit-problem". Next time, you can just prompt submit problem 12345 using the skill without having to re-explain the steps. In the same way, you need to create skills to lookup the submission status of the solution to the problem that you've just submitted. You can also create a skill to solve a problem: first download the pdf of the problem, parse the input and output, save it to {number}.in and {number}.out, write C++ solution and save it to {number}.cc and then write down the editorial on how to solve the problem and save it to {number}.md. Yes! you can ask LLM agent to explain the solution too!

Solving the problems in parallel

Once you have the solve, submit, and check submission status skills you can then prompt: "please solve and submit problems numbers A, B, C, ... in parallel using 10 subagents until they got AC." Be careful to issue this prompt, it will drain your LLM quota quickly! only do this when you are sure the skills are well tested first! Also you will learn that doing this is not efficient since your subagents tokens will be wasted if you are out of quota in the 5-hours window. It's better to never run of quota in the 5 hours window so your subagents never need to be restarted.

Which LLM to use?

Now, when you want to run the LLM coding agent for long running tasks over 3 weeks, you want it to continuously running while you are sleeping! From my experience, Gemini 3.6 flash is not good for long running tasks: it stops in about 1 hour and need to be kicked-in-the-butt to "continue the work". There's a workaround to ask it to run cronjob to self-kick every 5 mins, but you'll discover that Gemini will often forgot that it run expensive processes and didn't terminate it before moving on to the next problem, this may crash your working computer! You can add to the prompt for Gemini to proactively cleanup the zombie processes, but it still often forgot after a while!

Claude Code with Opus 5 is far better for the long running tasks! It can run overnight if you tune the token consumption so that you are not to out of quota for the 5-hours windows. Claude Code with Fable 5 is just too slow for solving problems and burning too much tokens, this is better reserved to solve problems that are unsolvable by Opus 5.

Competitive Programming Future

With LLM coding agents that powerful, what will happen to the future of competitive programming? Well, I think it will be even more competitive! The situation is similar to Chess or Go where there exists more powerful engine than human, but the competition between human still going strong. Human can learn even faster with the help of the engine. The engine will become cheaper and better in explaining the solutions (as long as the human still have willingness to learn).

This also means that cheating in online contests is now getting easier than ever! Contest organizers will need to figure out ways to make the competition fair for the players.

Looking at this World Ranklist below, the top ranked user is still human (Josh Bao). FYI, I did use my own user name (felix_halim) to run the experiment, and I've ended my experiment (since Claude Fable 5 also gave up on the remaining unsolved problems saying that they are research problems and too difficult to solve). So at this point, maybe human is still winning :)















Sunday, December 14, 2025

The Autonomous Horizon

Future of FSD Infographic

Note: this is an infographic produced using Gemini 3 pro deep research with the following prompt: "explore the future of self driving car. will tesla be the only winner? will other car manufacturer license tesla fsd? how hard is it to license fsd? what are the requirements? will self driving be like LLM where other companies can catch up quickly and becomes commoditized? if there are multiple winners who are the candidates? will there be like "android of fsd" where fsd get open sourced? if car manufacturer don't want to license fsd from tesla, what alternative do they have? what is the likely hood of other car manufacturer to build their own fsd technology? can they distill the fsd model from tesla? or they have to do the hard work of collecting real world data for fsd or can they just use simulation?"

THE AUTONOMOUS HORIZON

Will Tesla take it all? Exploring the data moats, licensing barriers, and the future battleground of Full Self-Driving.

THE SCALE ADVANTAGE

Data is the New Oil, and Tesla Has the Pipeline

To solve self-driving, you need to capture the "long tail" of weird edge cases (e.g., a person in a chicken suit crossing a highway). Simulation can only guess what it hasn't seen.

Tesla's fleet of millions of consumer vehicles provides a data feedback loop that traditional robotaxi fleets (like Waymo) struggle to match in pure volume. This "Data Moat" is the primary argument for Tesla's potential winner-take-most outcome.

5M+
FSD Capable Fleet
1B+
Miles Driven on FSD

Cumulative Autonomous Miles (Est.)

*Logarithmic scale visualization for impact comparison

Why Other Brands Can't Just "Install" FSD

Licensing Tesla FSD isn't like installing Android on a Samsung phone. It requires a complete architectural overhaul. The hardware and software are tightly coupled.

THE INTEGRATION STACK
1. SENSOR SUITE Exact camera placement & types required
2. COMPUTE HARDWARE Custom AI Inference Chips (HW3/HW4)
3. VEHICLE CONTROL Steering/Braking Latency & Actuation
1

Hardware Mismatch

Most cars use supplier-grade cameras and radars. FSD is trained on specific Tesla vision inputs. To license FSD, Ford or GM essentially has to build a Tesla clone.

2

The Black Box Problem

Automakers want to "own" the experience. FSD is an end-to-end neural net. You can't tweak it easily to drive "more like a BMW." It drives like a Tesla.

3

Validation Costs

Validating the software on a new chassis takes months or years. It's not a simple plug-and-play API integration.

MARKET LANDSCAPE

Is There an "Android" of Self-Driving?

While Tesla pursues a vertical Apple-like strategy, others are vying for the platform role. Who has the best shot at being the alternative?

Competitor Capability Matrix

🤖

Waymo (Google)

**Strategy:** Geo-fenced Robotaxis using Lidar + Maps.

**Pros:** Extremely safe, proven driverless operation today.
**Cons:** Doesn't scale easily to consumer cars or random locations.

🧠

NVIDIA + Mobileye

**Strategy:** The Arms Dealers. Selling chips and vision stacks to everyone else.

**Pros:** The "Android" path. Low risk for OEMs.
**Cons:** Fragmentation. Data collection is slower than a unified fleet.

🇨🇳

Chinese EVs (XPeng/Huawei)

**Strategy:** Fast follow + aggressive domestic mapping.

**Pros:** Innovation speed is matching Tesla.
**Cons:** Geopolitical barriers to Western markets.

Comma.ai

**Strategy:** Open Source / Consumer Hardware Retrofit.

**Pros:** Cheap, runs on many cars.
**Cons:** Limited authority over car controls; niche market.

Will FSD Be Commoditized Like LLMs?

With Large Language Models (LLMs), we saw rapid commoditization (OpenAI -> Llama -> Mistral) because text data is available on the open internet.

**Self-driving is different.** You cannot scrape the internet for physical driving intuition. You need video stamped with steering angles and acceleration data. This creates a much deeper moat.

  • LLM Barrier: Compute Cost (Medium), Data Access (Low)
  • FSD Barrier: Real World Data (Extremely High), Regulation (High)

Training Data Value Composition

Legacy Auto's Hard Choice

Legacy Auto Manufacturer
Can we build it in-house?
Requires $10B+, 5+ years, AI talent
YES (The Hard Way)
Collect Data: Fleet needed.
Distill: Can't copy Tesla directly.
Risk: Bankruptcy if failed.
NO (The Partnership)
Option A: License Tesla

Requires hardware redesign. Swallow pride. Pay royalty.

Option B: Use Mobileye/Nvidia

Become a commodity hardware assembler. Loss of differentiation.

Projected Evolution of Autonomy Costs

Conclusion

Tesla currently holds a winning hand due to the sheer scale of real-world data, which serves as a massive barrier to entry. While others like Mobileye and Waymo offer alternatives, the path for legacy auto is treacherous: license and lose control, or build and risk billions. FSD is unlikely to be commoditized quickly; instead, we may see a "Winner-Take-Most" scenario where 2-3 dominant global AI drivers emerge.

Generated with ❤️ by Canvas Infographics. No SVG or Mermaid JS used.

Wednesday, April 16, 2025

Using Google AI Studio for Competitive Programming

Last year, Gemini was estimated to be better than 85% of competition participants in solving competitive programming problems.

This blog post shows how to use Google AI Studio using the latest Gemini 2.5 Pro (Preview 03-25) model to solve a competitive programming problem from onlinejudge.org and then ask it to write an editorial explaining how the problem is solved.

Here are the steps:
  1. Pick a problem. Let's say problem 1595.

  2. Create an image screenshot like this and save it to your computer:

  3. Open Google AI Studio: https://aistudio.google.com/prompts/new_chat

  4. Attach the image (from step 2) and type in this prompt:
    Given a competitive programming problem in the attached image.
    Write a C++ code to solve the problem.
    Make sure to follow the input and output specifications.
    See the sample input and sample output for some examples.
  5. Click Run:

  6. It will run for a few minutes to think and solve the problem.
    You can click "Expand to view model thoughts" to see the details.

  7. After it completes, you should be able to click the copy button for the solution code:


  8. Paste the solution to the quick submit


  9. See the status at https://uhunt.onlinejudge.org/ make sure it is "Accepted":


  10. Now, go back to the Google AI Studio, type in this prompt, then click Run:
    Write one page editorial explaining how you solved the problem.
  11. You should get a good explanation on how to solve the problem 1595:


  12. You can continue the prompt to ask follow up questions if you have.

In the past, I have to dig into forums to find hints on how to solve the problems when I'm stuck, which wasted a lot of my time. Nowdays, we can use Google AI Studio to minimize the time to find hints!

The competitive programming field is going to be even more competitive than ever ...

Saturday, August 25, 2018

Migrating to Blogger

Believe it or not, this site is hosted on Blogger!

I just realized how customizable Blogger theme is. It allows you to edit the entire layout (using xml that allows you to "program" the html and css). I managed to keep the iconic header of my site, and use an existing theme for the contents and navigations.

Back in year 2000, I wrote PHP script for my site connecting to MySQL database to store the posts and comments. I was 18 years younger back then and had plenty of time to code. The problem is, sometimes I will need to migrate the site to another server and I don't have the time. I was thinking to convert it to a static site so that server migration will be as simple as copy-pasting (no database setup needed), but still converting the layout is a painful experience.. Do I have to copy paste the header and footer to all the pages? Then there is this idea of using Angular to create a static bundle like how the angular.io site is built for the tutorials and docs, and host the comments in Firebase, but as I said, I don't have the time to build it. There has to be a better way...

I decided to take a chance of migrating my site to Blogger (it has been around for almost 20 years now and there's no sign of being shutdown). The offered functionalities are basic, but I did try including a <script> tag and it runs. I think I can do a lot fancy stuffs with it. Nowadays, static sites (that can run Javascript) can pretty much do anything by calling API to other servers.

I will gradually migrate my old contents to this site as I have the time ...

Saturday, August 9, 2014

Kawal Pemilu 2014

How does Kawal Pemilu work? See my answer at Quora and the system design document.

Nasional

Nasional

Color Legend

Prabowo / Hatta
Jokowi / JK

The data source for number of votes is taken from KawalPemilu.org and imported into Google Fusion Tables.

The data source for the administrative boundary map is taken from PemiluAPI.

I manually reconcile the IDs from shapefiles in the PemiluAPI with the IDs from KawalPemilu.org.

The datasets for each level of administration (for more details, click File -> About this table):

Thursday, October 24, 2013

ACM ICPC Jakarta 2013 - Problem J - Alien Abduction Again

Last year contestants (or contestants who practiced with last year ICPC Jakarta 2012 problemset) should immediately know, only by looking at the problem title, that this problem is related to last year Problem H - Alien Abduction. Also, they should have guessed that this problem is either as hard, or harder than last year :D.

It took me several weeks to come up with this problem (and the solution). My criterion for the problem are:

  • The problem must be hard. This is necessary to avoid the embarrasement (to the problem-setters) that some teams sweept clean all the problems in 3 hours >.< (yes I'm talking about you, +1 ironwood branch).
  • The problem must be a rare problem. That is, I want it to be the decider problem to separate the teams at the top. I do not want to pick the problem from the Competitive Programming Book Chapter 9 - Rare Topics, because it would be too obvious :P.
  • The problem must have a secret message. Well... the secret message is meaningless for any contestants (i.e., the message will not help anyone to gain better insight in solving the problem). Instead, the secret message was intended for one of the special guests in the closing ceremony :).

Given the criterion above, how should I write the problem? I search for inspiration by reading blogs, TopCoder forum posts, etc. After two weeks I decided to write a BIT (Binary Indexed Tree) with range update. I always surprised by BIT that it can be used differently than its original design (prefix sums). For example, BIT can be used to compute range minimum query, and range updates too (see Petr Mitrichev blog as well as the links in the comments section).

Here is the problem statement, you can try submit your solution below.

In short, the problem statement is like this (Click here to see the full problem statement):

Given lines/curves segments as a set of functions fp(x) = ax3 + bx2 + cx + d, each on a range [x1p, x2p], what is the total sum of the y-values of the points (generated by the functions) with integral x-values in range [x1, x2] ?

Naively, this problem can be easily solved using (Lazy) Segment Tree + coordinate compression. I do not want this solution to pass (remember that I want to create a BIT range update problem). Coordinate compression is a trick to make the input range smaller by pre-reading all input data and then make it dense. This will help the Segment Tree solution that it only needs to allocate 100K instead of 1M tuples. Luckily, there is a trick to make coordinate compression to fail: make it as an interactive problem. However, ICPC style usually do not involve interactive problems, so I have to uglify the input that the next input depends on the previous output of the program (i.e., to simulate an interactive problem). This is the reason that "the space distortion" was introduced every time the transporter is used. With this, coordinate compression will no longer work, but I agree that this made the problem harder to read. In fact from the survey, almost half of the teams voted problem J as the least liked problem :(. I guess that's the price I have to pay.

What about the (Lazy) Segment Tree? How to make it fail to work? I know that normally, in programming contests, two solutions with the same complexity should both get Accepted. But, this problem is an exception. I made it clear in the problem statement that your solution must be very-very efficient (otherwise the device will be too late to disrupt the transport operation by the alien ship). So, constant factor matters in this problem. I was hoping that the contestants realize that when reading the problem statement.

If you are familiar with Segment Tree, you should have an insight how slow it can be. Thus you should pick solutions with lower constant factor if any (e.g., Binary Indexed Tree). The Segment Tree solutions run in 5+ seconds while the BIT solutions run in less than 2 seconds. Moreover, the memory consumption for Segment Tree will exceed 64 MB. If you recall, in the briefing, Suhendry mentioned that all of the judges solutions use less than 32 MB. That should give you another hint that Segment Tree is not the way to go.

Unfortunately, due to PC2 inaccuracy in measuring the time limit, some teams got lucky to get it accepted with Segment Tree (albeit, they need to insanely optimize their code to get it run in 5 seconds). We set the time limit for this problem to be 4 seconds in the PC2, but somehow PC2 still accepts solutions with 5 seconds runtime! I didn't re-adjust the time limit to 3 seconds during the contest and decided to let it be (otherwise I will be cursed by the accepted teams :P).

No team solved this problem using BIT range updates. It is not easy to convert a (Lazy) Segment Tree into BIT range updates. It probably deserve a problem on its own. To give an example, consider the simplest case where f(x) = d. That is, the values for a, b, and c are all zero. In this case, the problem is equal to a very simple BIT range update. Here is a nice post on how to simulate a (Lazy) Segment Tree using two BITs. We can generalize this for the other powers (a, b, and c) and we will need five BITs. The runtime for this approach is less than 2 seconds and it consumes only ~20MB memory. This problem also requires the knowledge of mod-inverse. That is, you will need to do division with modulo somewhere in the calculation.

Well, the first two criterion have been fulfilled. The last criteria is the secret message. I hid the message in plain sight. No other judge (even the chief of judge) was aware that there was a secret message. But no worries, the message is meaningless to anyone except me and the intended recipient :). I really had fun in setting this problem :D.

Wednesday, October 17, 2012

ACM ICPC Jakarta 2012 - Problem H - Alien Abduction

During the interview with the champion team (+1 ironwood branch), Pi-Hsun (Peter) Shih said that his favorite problem is problem H (this problem). I should've asked why did he like it? is it because of the problem statement? or because he had fun in writing the solution :). Anyway, this problem is set by me and I would like to tell you how this problem was created / prepared.

Initially, this problem was set to be "easier", that a simple K-d Tree or Quadtree solution will work fine. However, since Problem D is already using K-d Tree for finding the nearest neighbors, to give good variations to the problemset, I rewrote this problem so that it is NOT solvable using (static) K-d Tree nor Quadtree (unless you are able to code "dynamic" K-d Tree / Quadtree in contest time :P).

This problem is solvable using Range Tree. I taught Range Tree during Pelatnas (training camp) 3 TOKI 2012 to 8 of Indonesian students to prepare them for IOI 2012. There are several other students from University of Indonesia were present during the training camp and those same students were participating in ICPC Jakarta 2012. I was surprised that they didn't get this problem accepted in contest time!

I think Range Tree is a rare problem in programming contest. I won't discuss it in detail here, since it is a classic algorithm in computational geometry, you can search for it to learn more. Perhaps it will be included in the next version of the Competitive Programming Book. Rare problems like this usually become the "decider problems" that set apart teams at the top.

Many (inexperienced) teams were submitting naive (not even clever) brute-force solutions O(N*Q). Of course they will get "No - Time Limit Exceeded" reply. Then, they tried optimizing on reading the input more efficiently, optimize the loop, etc, but the complexity is still the same O(N*Q). This problem can be a time-waster for inexperienced teams. As the problem setter, I feel sorry for them.

Here is the problem statement, you can try submit your solution below.

I'd like to talk about how this problem was prepared, to give you an idea what is it like to be a problem setter. It took me a lot of time to prepare, especially for the test data since I have to kill off simple/clever brute-force solutions. Moreover, I have to kill off solutions using (static) K-d Tree and Quadtree :)

For the test cases, I prepared 4 types of tests:

  1. To kill off plain bruteforce solutions O(Q*N), a simple random positions and random alien abductions positions and energy will do. However, if we keep the people positions in sorted order, O(Q*N) solution can run pretty fast! So,
  2. To kill off brute force solutions with sorted Xi and Yi coordinate, I created tests where the positions of the people have very close to each other in X coordinate but random in Y coordinate, and vice-versa. Thus bruteforce solutions that sort by X will still have to iterate many Y positions, and vice-versa. However, if we localized the coordinates, that is, by grouping all people in nearby coordinate (within 1000 distance), then you can prune a lot of people (given the energy and position of the alien ship), and thus the first two kinds of test case can run pretty fast! So,
  3. To kill off nearby/localized spatial indexing solutions, I created test cases where all the people are in coordinate (0 <= Xi,Yi < 1000) and all the alien abductions operations are everywhere randomly with very large energy, but so that no abduction is happening. This will force the all local groups to be scanned every query because the energy is large enough to cover all the group in one axis or another (but not both). With these three kinds of tests, I am still concerned that K-d tree or Quadtree indexing will pass. So,
  4. To kill off K-d Tree and Quadtree solutions, I set the positions of all people to (0 <= Xi,Yi < 10) initially. Then, I move (using the alien abduction operation) the person with identifier = 1 to the right 7000 times, and then move it 8000 times on the other (perpendicular) axis. Then, the next alien abduction operation will spread randomly the rest of the people all over the Earth. Then followed by a random alien abductions as in the first kind of testcase. So, if you were to index the INITIAL positions using (static) indexing data structure, and you don't rebalance your index tree during the translation, your index will be very skewed and unbalanced once they are translated and scattered to another part of Earth with clean index. This test case also kills off those who don't actually delete nodes from the K-d Tree / Quadtree (i.e, you flag the nodes as deleted), because the alien abductions will cover the initial positions often, and thus those "ghost nodes" will be revisited again and again if they are only flagged (not deleted).
  5. If the contestants are cleverer than this, I will happily accept their solutions :)

There is one team I know (Azureus_HKU) using a clever brute-force that I didn't anticipate. They create a multimap for each x-coordinate, so for each x-coordinate they can know wheater there are people abducted in log(N), by binary searching the y-coordinate. But fortunately, the 3rd kind of testcase above also kills of this solution :). This clever brute-force algorithm can still run in O(1000*Q*log(N)) if the input is like this: all people are at coordinate between (0 <= Xi,Yi < 1000) and the alien abduction operations are at Xk = 5000, Yk = 0, Ek = 4000. What will happen is that each query, you need to scan/iterate all 1000 distinct X coordinate (and immediately find that the Y coordinate is not qualified). Thus it will need to iterate Q*1000*log(N) = 50000 * 1000 * 10 = TLE. It took 15+ seconds, while the Range Tree solution is around 5 seconds. BTW, the time limit for the problem is 10 seconds, which is quite generous :)

This is the input generator for problem H. You can try to test whether your bruteforce solution will pass the 10 second time limit. Remember to compile your C++ program WITHOUT using any optimizations.

So how does this Range Tree solution works? you asked. Well, we have to wait for our beloved chief of judge, Suhendry Effendy, to write a blog post about it. Please kindly remind him every now and then, because he often forgot to blog >:D.