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<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ST first
#define ND second
ostream& operator<<(ostream &out, string str) {
for(char c : str) out << c;
return out;
}
template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) {
return out << "(" << p.ST << ", " << p.ND << ")";
}
template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
out << "{";
for(auto it = a.begin(); it != a.end(); it = next(it))
out << (it != a.begin() ? ", " : "") << *it;
return out << "}";
}
void dump() { cerr << "\n"; }
template<class T, class... Ts> void dump(T a, Ts... x) {
cerr << a << ", ";
dump(x...);
}
#ifdef DEBUG
# define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__)
#else
# define debug(...) false
#endif
template<class T> int size(T && a) { return (int) a.size(); }
using LL = long long;
using PII = pair<int, int>;
#include "gondola.h"
int valid(int n, int inputSeq[]) {
int origin = -1;
REP(i, n) {
if(inputSeq[i] <= n) {
int x = ((i - inputSeq[i]) % n + n) % n;
if(origin == -1) origin = x;
if(origin != x) return false;
}
}
return true;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
int origin = -1, mx = -1;
REP(i, n) {
mx = max(mx, gondolaSeq[i]);
if(gondolaSeq[i] <= n && origin == -1)
origin = (i - gondolaSeq[i] + n) % n;
}
vector<int> pos(mx + 1, -1);
REP(i, n) pos[gondolaSeq[i]] = i;
vector<int> Q;
int cur = 0;
FOR(i, n + 1, mx) {
Q.emplace_back(i);
if(pos[i] != -1) {
int last = (pos[i] - origin + n) % n;
if(last == 0) last = n;
for(int x : Q) {
replacementSeq[cur++] = last;
last = x;
}
Q.clear();
}
}
return cur;
}
//----------------------
int countReplacement(int n, int inputSeq[]) {
int origin = -1, mx = -1;
REP(i, n) {
mx = max(mx, inputSeq[i]);
if(inputSeq[i] <= n){
int x = ((i - inputSeq[i]) % n + n) % n;
if(origin == -1) origin = x;
if(origin != x) return false;
}
}
vector<int> pos(mx + 1, -1);
REP(i, n) {
if(pos[inputSeq[i]] != -1)
return 0;
pos[inputSeq[i]] = i;
}
const int mod = 1e9 + 9;
int ans = 1, suff = 0;
for(int i = mx; i >= n + 1; i--) {
if(pos[i] == -1)
ans = (LL) ans * suff % mod;
else
suff++;
}
return ans;
}
# | 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... |