# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
296202 | arayi | Gondola (IOI14_gondola) | C++17 | 28 ms | 2932 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 <bits/stdc++.h>
#include "gondola.h"
#define ad push_back
#define MP make_pair
#define fr first
#define sc second
#define lli long long int
using namespace std;
const lli mod = 1000000009;
const int N = 3e5 + 20;
bool col[N];
int valid(int n, int inputSeq[])
{
vector <int> a;
for (int i = 0; i < n; i++) a.ad(inputSeq[i]);
for (int i = 0; i < n; i++) a.ad(inputSeq[i]);
int i1 = -1;
for (int i = 0; i < n; i++)
{
if(col[a[i]]) return 0;
col[a[i]] = true;
if(a[i] <= n)
{
i1 = (i - a[i] + 1 + n) % n;
}
}
if(i1 == -1) return 1;
for (int i = i1; i < i1 + n; i++)
{
if(a[i] > n) continue;
if(i - i1 + 1 != a[i]) return 0;
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
vector <int> a, pat;
for (int i = 0; i < n; i++) a.ad(gondolaSeq[i]);
for (int i = 0; i < n; i++) a.ad(gondolaSeq[i]);
int i1 = 0;
for (int i = 0; i < n; i++)
{
if(a[i] <= n)
i1 = (i - a[i] + 1 + n) % n;
}
vector <pair<int, int> > fp;
int nw = n + 1;
for (int i = i1; i < i1 + n; i++)
{
fp.ad(MP(a[i], i - i1 + 1));
}
sort(fp.begin(), fp.end());
for (int i = 0; i < fp.size(); i++)
{
while(nw <= fp[i].fr)
{
pat.ad(fp[i].sc);
fp[i].sc = nw;
nw++;
}
}
for (int i = 0; i < pat.size(); i++) replacementSeq[i] = pat[i];
return (int)pat.size();
}
lli bp(lli a, lli b = mod - 2LL)
{
lli ret = 1;
while(b)
{
if(b & 1) ret *= a, ret %= mod;
a *= a, a %= mod;
b >>= 1;
}
return ret;
}
int countReplacement(int n, int inputSeq[])
{
vector <lli> fp;
for (int i = 0; i < n; i++)
if(inputSeq[i] > n) fp.ad(inputSeq[i]);
lli nw = n + 1;
lli m = fp.size();
sort(fp.begin(), fp.end());
lli pat = 1;
if(m == n) pat = n;
for (lli i = 0; i < m; i++)
{
//cout << i << endl;
pat *= bp(m - i, fp[i] - nw);
pat %= mod;
nw = fp[i]+ 1;
}
return pat;
}
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... |