# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
790195 | Sohsoh84 | Gondola (IOI14_gondola) | C++17 | 33 ms | 9200 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 <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define sep ' '
#define debug(x) cerr << #x << ": " << x << endl;
const int MAXN = 1e6 + 10;
typedef long long ll;
typedef pair<ll, ll> pll;
int A[MAXN];
int valid(int n, int inputSeq[]) {
int s = -1;
set<int> tst;
for (int i = 0; i < n; i++) inputSeq[i]--;
for (int i = 0; i < n; i++) {
if (inputSeq[i] < n)
s = i;
tst.insert(inputSeq[i]);
}
if (int(tst.size()) < n) return 0;
if (s == -1) return 1;
int shift_val = (s - inputSeq[s] + n) % n;
for (int j = 0; j < n; j++)
A[j] = inputSeq[(j + shift_val) % n];
set<int> st;
for (int i = 0; i < n; i++) {
if (A[i] < n)
if (A[i] != i) return 0;
else
A[i] = i;
st.insert(A[i]);
}
return st.size() == n;
}
//----------------------
int replacement(int n, int inputSeq[], int res[]) {
for (int i = 0; i < n; i++) inputSeq[i]--;
int s = -1;
for (int i = 0; i < n; i++) {
if (inputSeq[i] < n)
s = i;
}
int shift_val = (s == -1 ? 0 : (s - inputSeq[s] + n) % n);
for (int j = 0; j < n; j++)
A[j] = inputSeq[(j + shift_val) % n];
set<int> st;
int mx = *max_element(A, A + n);
for (int i = 0; i <= mx; i++)
st.insert(i);
for (int i = 0; i < n; i++)
st.erase(A[i]);
set<pll> gond;
for (int i = 0; i < n; i++)
gond.insert({A[i], i});
int m = 0;
while (gond.rbegin() -> X > n) {
auto [x, ind] = *prev(gond.end());
gond.erase(prev(gond.end()));
if (st.find(x - 1) != st.end()) {
A[ind] = x - 1;
st.erase(x - 1);
res[m++] = x - 1;
} else {
A[ind] = ind;
st.erase(ind);
res[m++] = ind;
}
gond.insert({A[ind], ind});
}
reverse(res, res + m);
return m;
}
//----------------------
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... |