Problem Description
**UPD**. I solved the problem.
Let `DP[i][vertex_a][vertex_b]` is the state with `i` cities visited and two players standing at vertices `vertex_a, vertex_b` (is is guaranteed one of then stands at `list[i]`). WLOG assume `vertex_a ≤ vertex_b` as this `DP` table doesn't carry information about players positions. Only three states can be reached from `DP[i][vertex_a][vertex_b]`, namely `DP[i + 1][vertex_a][vertex_b]`, `DP[i + 1][list[i]][vertex_b]`, `DP[i + 1][vertex_a][list[i]]`. We also only need to store two layers of `DP`, so only `sizeof(int) * 2 * 200 * 200` bytes needed to compute optimal path cost. To get the path there would be `last_move_id[i][vertex_a][vertex_b]` carrying information about the player that made move at state `DP[i][vertex_a][vertex_b]` and `last_move_positions[i][vertex_a][vertex_b]` storing the number of vertex from which player reached `list[i]`. As vertex number doesn't exceed 200 it's save to store those as `byte`, so `sizeof(byte) * 1000 * 200 * 200` bytes for each array. To maintain these arrays there'd have to be another array `positions[i][vertex_a][vertex_b][3]` carrying information about position of each player, only last two layers are needed, so `sizeof(byte) * 2 * 200 * 200 * 3` bytes for this one. Time complexity `O(N * L * L)`.
My `C++` implementation uses `76Mb` and `320 ms`.
I am struggling with the following competitive programming problem from a Russian online judge http://informatics.mccme.ru/moodle/mod/statements/view.php?chapterid=3379 . According to rules, one must provide the source of the problem as far as I remember
Unfortunately, there's no English version of website so I'll try to describe the problem.
> Input consists of the complete digraph `G` with `L` vertices and some list of vertices (length at most `N`). Three people start at vertices `1, 2, 3` respectively. They have to visit each vertex from the input list, order matters, vertex `i + 1` is necessarily visit...
AI-Generated Solution
Powered by LMSouq AI · GPT-4.1-mini
Analyzing problem and generating solution…
Was this solution helpful?