Oleksiy PylypenkoOlympiad Years

All-Ukrainian Olympiad in Informatics — Finals (Odesa 2001)

Odesa, stage IV (national), 2001 · March 2001

25th place · 129 points · Diploma IIRank 25129 ptsDiploma II

3rd among 9th-graders

Winning the Kyiv city stage in February 2001 as a first-year UPML student was enough to carry me into the fourth and final stage of the national olympiad system: the finals of the All-Ukrainian Olympiad in Informatics, held in Odesa at the end of March. It was my first appearance at this level, and the first time I measured myself against the strongest school-age programmers in the country rather than just the city.

The finals ran as two full-day rounds, two problems each, on 26 and 28 March, with results and diplomas dated 30 March. The first round was disrupted by rolling power blackouts across Odesa that delayed the start of testing for hours; the second round two days later went ahead without incident. Grades 9 through 11 all sat the same four problems, so a 9th-grader was, by construction, competing up.

I placed 25th overall out of roughly 130 finalists — 69 points on day one (Square, Maze) and 60 on day two (Cipher, Schools), 129 in total — good for a Diploma II and 3rd place among the 9th-graders present. It was my first national-level medal in informatics, one round removed from the Kyiv result that had opened the door to it.

#ContestantTeamGradeDay 1Day 2Total
1Viktor SurohinUPML11193151344
2Ivan LeshchovDonetsk region1193144237
3Yevhen SobakarovKherson region1066158224
25Oleksiy PylypenkoUPML96960129
Top of the national-stage results table, with the grade-9 UPML entry.Official results table via Wayback Machine (uoi.kiev.ua)

Problems

Problems from this contest

Cipher

Шифр

dpshortest-pathstrings

Statement

A string S of length N (0 ≤ N ≤ 100) and a dictionary of M words (0 ≤ M ≤ 100) are given, all made of lowercase letters a–z, with no dictionary word longer than S. Find the minimum number of characters to delete from S so that the remaining string can be written as a concatenation of dictionary words, each usable any number of times (the empty string counts as a valid concatenation of zero words).

In the sample, deleting the letters f and t from abafchtdsya gives abachdsya, which splits into the words a, bach, dsy, a.

Input / Output

Input file CIPHER.DAT starts with a line containing two integers N and M, followed by the string S on the next line, followed by M lines each holding one dictionary word. Output file CIPHER.SOL must contain a single natural number: the minimum number of deletions required.

Constraints

0 ≤ N ≤ 100, 0 ≤ M ≤ 100, dictionary word length ≤ N, alphabet is a–z only.

Example

Input:

11 5
abafchtdsya
aba
a
bach
dsy
zero

Output:

2
Solution idea

Build a weighted DAG over the N+1 gaps between characters of S: a default edge from position i to i+1 with weight 1 represents deleting character i, and for every occurrence of a dictionary word as a subsequence of some span S[i+1..j], add an edge from i to j whose weight is the number of characters in that span skipped over by the match (i.e. the extra deletions needed to isolate the word). The answer is then the shortest path from position 0 to position N in this DAG, which the reference solution computes with a Dijkstra-style relaxation after precomputing, for each dictionary word, all its subsequence occurrences and their skip counts.

Maze

Лабіринт

bfsshortest-path

Statement

A traveler must cross a maze to reach a spring of living water. The maze is an N×N grid of cells, with walls possibly standing along cell edges. The traveler moves one step at a time to a horizontally or vertically adjacent cell, and may pass straight through a wall using magic, but only up to K times in total; the traveler may never step outside the maze. Starting at cell (1, 1), find the minimum number of steps needed to reach the spring at cell (P, Q).

Input / Output

Input file MAZE.DAT starts with a line containing N, K, P, Q (2 ≤ N ≤ 200, 0 ≤ K ≤ 250, 1 ≤ P, Q ≤ N). The next N−1 lines each contain N integers marking horizontal walls between vertically adjacent cells, followed by N lines of N−1 integers each marking vertical walls between horizontally adjacent cells (0 = no wall, 1 = wall present). Output file MAZE.SOL must contain a single line with the minimum number of steps, or −1 if the spring is unreachable.

Constraints

2 ≤ N ≤ 200, 0 ≤ K ≤ 250, start and target cells are within the grid.

Example

Input:

3 1 2 3
0 0 0
0 1 0
1 0
1 0
0 0

Output:

3
Solution idea

Model the grid as a graph where moving to a neighbor through an open edge costs 0 magic uses and moving through a wall costs 1, up to the budget K; the answer is then the shortest path from (1,1) to (P,Q) in this graph. The jury solution processes cells in a single queue ordered by increasing number of magic uses spent so far (a 0/1 BFS): from each cell it first pushes open-edge neighbors at the same "layer," then wall-crossing neighbors into the next layer, and stops as soon as the target is popped, which is guaranteed to happen with the minimum step count since layers are explored in non-decreasing order of magic uses.

Schools

Школи

mstgraphs

Statement

To prepare for an informatics olympiad, the mayor wants reliable power for every school in the city. A line must be run from an alternative power source, "Maybuttya," to any one school, and lines may also connect pairs of schools directly; a school has reliable power if it is connected, directly or through other reliably-powered schools, back to the source. Given the costs of the possible connections between school pairs, compute the total cost of each of the two cheapest such power schemes (the cost of a scheme is the sum of the costs of the connections it uses).

Input / Output

Input file SCHOOLS.DAT starts with a line containing N (3 ≤ N ≤ 100), the number of schools, and M, the number of possible connections. Each of the next M lines contains three numbers Ai, Bi, Ci — a possible connection between schools Ai and Bi at cost Ci (1 ≤ Ci ≤ 300). Output file SCHOOLS.SOL must contain a single line with two natural numbers S1 and S2 (S1 ≤ S2) — the costs of the two cheapest schemes; S1 = S2 only when several minimum-cost schemes exist.

Constraints

3 ≤ N ≤ 100, connection costs 1 ≤ Ci ≤ 300, the connection graph need not be complete.

Example

Input:

5 8
1 3 75
3 4 51
2 4 19
3 2 95
2 5 42
5 4 31
1 2 9
3 5 66

Output:

110 121
Solution idea

The cheapest scheme is a minimum spanning tree (S1), built with Prim's algorithm. For the second-cheapest distinct scheme (S2), the reference solution uses the classic "next best spanning tree" technique: for every edge not in the MST, replacing it into the tree and dropping the heaviest edge on the tree path it closes into a cycle gives another valid spanning tree, so it precomputes, for every pair of vertices, the maximum edge weight on their MST path (via a DFS from each vertex over the tree), and takes the minimum over all non-tree edges of (MST weight − heaviest path edge + non-tree edge weight) as S2.

Square

Квадрат

geometryternary-search

Statement

A triangle is given by the coordinates of its three vertices on the plane. Find the side length L of the smallest-area square that can contain the triangle, with all three vertices lying inside the square or on its edges. The square may be placed at any position and any rotation. It is enough to find L to within 1e-4.

Input / Output

Input file SQUARE.DAT contains one line with six real numbers X1 Y1 X2 Y2 X3 Y3, separated by spaces — the coordinates of the triangle's vertices (-10000 ≤ each coordinate ≤ 10000). Output file SQUARE.SOL must contain a single number: the side length L of the smallest enclosing square.

Constraints

Coordinates are bounded by 10000 in absolute value; the answer is accepted with a tolerance of 1e-4.

Example

Input:

0.0 0.0 1.1 0.0 0.0 1.1

Output:

1.1
Solution idea

For a fixed rotation angle, the side of the axis-aligned bounding box of the rotated triangle is a simple function of that angle; as the square turns, this bounding-box side changes unimodally between the angles where two vertices "switch" which pair determines the box, which lets a ternary search over rotation angle locate the minimum for a given anchoring of the triangle. The reference solution runs this search three times — once per triangle edge used as the base direction being swept through — and keeps the smallest bounding square side found over the three sweeps, which turns out to be sufficient to find the true minimum-area enclosing square.

Evidence

Scans & photographs

Sources

  1. [1]Official results table via Wayback Machine (uoi.kiev.ua)
  2. [2]Jury protocol, offline archive (ftp.pmg17.vn.ua)