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 ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
#include "gondola.h"
signed valid(signed n, signed a[])
{
set <int> ms;
for (int i = 0; i < n; ++i)
ms.insert(a[i]);
if (ms.size() < n)
return 0;
int pos = -1;
for (int i = 0; i < n; ++i) {
if (a[i] <= n) {
pos = i;
break;
}
}
if (pos == -1)
return 1;
else {
for (int sh = 0; sh < n; ++sh) {
int i = (pos + sh) % n;
int val = a[pos] + sh;
if (val > n)
val -= n;
if (a[i] <= n && a[i] != val)
return 0;
}
return 1;
}
}
//----------------------
signed replacement(signed n, signed a[], signed ans[])
{
int pos = -1, S;
for (int i = 0; i < n; ++i) {
if (a[i] <= n) {
pos = i;
S = a[i];
break;
}
}
if (pos == -1) {
pos = 0;
S = 1;
}
vector <ii> ar;
for (int sh = 0; sh < n; ++sh) {
int i = (pos + sh) % n;
int val = S + sh;
if (val > n)
val -= n;
if (a[i] > n) {
ar.app(mp(a[i], val));
}
}
sort(all(ar));
int ptr = 0;
int xp = n + 1;
for (auto e : ar) {
int cur = e.s;
while (xp <= e.f) {
//cout << cur << "->" << xp << endl;
ans[ptr++] = cur;
cur = xp++;
}
}
return ptr;
}
//----------------------
const ll MOD = 1000 * 1000 * 1000 + 9;
ll mod(ll n) {
n %= MOD;
if (n < 0) return n + MOD;
else return n;
}
ll fp(ll a, ll p) {
ll ans = 1, c = a;
for (int i = 0; (1ll << i) <= p; ++i) {
if ((p >> i) & 1) ans = mod(ans * c);
c = mod(c * c);
}
return ans;
}
ll dv(ll a, ll b) { return mod(a * fp(b, MOD - 2)); }
signed countReplacement(signed n, signed a[])
{
if (!valid(n, a))
return 0;
int pos = -1;
for (int i = 0; i < n; ++i) {
if (a[i] <= n) {
pos = i;
break;
}
}
vector <int> ar = {n};
for (int i = 0; i < n; ++i)
if (a[i] > n)
ar.app(a[i]);
sort(all(ar));
ll ans = 1;
int r = 0;
for (int i = (int)ar.size() - 2; i >= 0; --i) {
++r;
int len = ar[i + 1] - ar[i] - 1;
ans = mod(ans * fp(r, len));
}
if (pos == -1)
ans = mod(ans * n);
return ans;
}
Compilation message (stderr)
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:21:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (ms.size() < n)
~~~~~~~~~~^~~
# | 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... |