# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1143641 | Rufat | Gondola (IOI14_gondola) | C++20 | 0 ms | 0 KiB |
//Author Gpt O3-Mini
#include <bits/stdc++.h>
using namespace std;
/*
We implement three functions:
1. int valid(int n, int inputSeq[]);
Checks whether the array inputSeq[0..n-1] is a valid gondola sequence.
Under our (simplified) model the gondola system is as follows:
- Initially there are n gondolas numbered 1,2,…,n in order on a circular rail.
- When a gondola breaks down it is replaced immediately by the first available spare.
(Thus if n = 5 the first spare is 6, the second is 7, etc.)
- In our simplified model we assume that any gondola that broke down was replaced only once.
- Finally, the observer may “see” the gondolas in any cyclic shift of the circle.
Our check is as follows. Suppose that a rotation (shift) r (0 ≤ r < n) makes the circle “line up” so that
the expected original numbers (if no breakdown had occurred) are 1,2,…,n in that order.
Then for each position j (0-indexed) we have:
- If no breakdown occurred there then the observed number must equal j+1.
- If a breakdown occurred then (by our simplified rule) the spare number assigned is
n + (k) where k is the count (starting at 1) of replaced gondolas in the order encountered.
(Thus, for example, if n = 5 and gondola 1 breaks down then the spare is 6; if gondola 4 breaks down then its spare is 7.)
We try all rotations r and if one is consistent with the rule we return 1; otherwise we return 0.
2. int replacement(int n, int gondolaSeq[], int replacementSeq[]);
Given that gondolaSeq is a valid gondola sequence (by the above definition),
we “reconstruct” one possible replacement sequence.