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>
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, s, n) for(ll i = ll(s); i < ll(n); ++i)
#define rrep(i, n) for(ll i = ll(n) - 1; i >= 0; --i)
#define rrep2(i, n, t) for(ll i = ll(n) - 1; i >= ll(t); --i)
#define pb push_back
#define eb emplace_back
#define SZ(a) int(a.size())
#define all(a) a.begin(), a.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<P>;
using vvp = vector<vp>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;
const int inf = 1001001001;
const ll linf = 1001001001001001001;
template<class T>
bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T>
bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int valid(int n, int inputSeq[]) {
int p1 = -1;
set<int> st;
rep(i, n) {
int now = inputSeq[i];
if (st.count(now)) return 0;
st.insert(now);
if (now <= n) {
int p = (i - (now - 1) + n) % n;
if (p1 != -1 and p1 != p) return 0;
p1 = p;
}
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
int p1 = -1;
int mx = n, mx_id = -1;
rep(i, n) {
int now = gondolaSeq[i];
if (chmax(mx, now)) mx_id = i;
if (now <= n) {
int p = (i - (now - 1) + n) % n;
assert(p1 == -1 or p1 == p);
p1 = p;
}
}
if (mx == n) return 0;
if (p1 == -1) p1 = 0;
vi pre(mx + 1, -1);
rep(i, n) {
if (i == mx_id or gondolaSeq[i] <= n) continue;
pre[gondolaSeq[i]] = 1 + (i - p1 + n) % n;
}
int now = 1 + (mx_id - p1 + n) % n;
rep2(i, n + 1, mx + 1) {
if (pre[i] == -1) {
pre[i] = now;
now = i;
}
replacementSeq[i - (n + 1)] = pre[i];
}
return mx - n;
}
//----------------------
int countReplacement(int n, int inputSeq[]) {
if (!valid(n, inputSeq)) return 0;
return 1;
}
# | 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... |