# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
296391 | emil_physmath | Gondola (IOI14_gondola) | C++17 | 42 ms | 5240 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "gondola.h"
#include <numeric>
#include <algorithm>
#include <set>
#include <vector>
#include <iostream>
using namespace std;
#define BUGO(x) cerr << #x << " = " << x << '\n';
int valid(int n, int a[])
{
if (set<int>(a, a + n).size() != n) return false;
vector<int> b; b.reserve(n);
for (int i = 0; i < n; ++i)
if (a[i] <= n)
b.push_back(a[i]);
if (b.empty()) return true;
int i = 0;
while (i + 1 < b.size() && b[i] < b[i + 1]) ++i;
if (i == n - 1) return true;
int j = b.size() - 1;
while (j - 1 >= 0 && b[j - 1] <= b[j]) --j;
return (b.back() < b[0] && i + 1 == j);
}
//----------------------
int replacement(int n, int a[], int ans[])
{
int anslen = 0;
vector<int> must(n, -1);
for (int i = 0; i < n; ++i)
if (a[i] <= n) {
for (int j = i; j < i + n; ++j) {
must[j % n] = (a[i] + j - i) % n;
if (!must[j % n]) must[j % n] = n;
}
break;
}
if (must[0] == -1)
iota(must.begin(), must.end(), 1);
vector<int> inds; inds.reserve(n);
for (int i = 0; i < n; ++i)
if (a[i] > n)
inds.push_back(i);
auto comp = [&a](int l, int r) {
return a[l] < a[r];
};
sort(inds.begin(), inds.end(), comp);
int gondol = n + 1;
for (int i: inds)
while (must[i] < a[i]) {
ans[anslen++] = must[i];
must[i] = gondol++;
}
return anslen;
}
//----------------------
int countReplacement(int n, int inputSeq[])
{
return -3;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |