#include "gondola.h"
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define pii pair<ll, ll>
const ll mod = 1e9 + 9;
const ll mxN = 3e5 + 5;
using namespace std;
ll fastpow(ll x, ll p)
{
if (p == 0)
return 1;
ll ans = fastpow(x, p / 2);
return p % 2 == 0 ? (ans * ans) % mod : (((ans * ans) % mod) * x) % mod;
}
map<int, int> realS;
set<int> nums;
bool allB;
bool cnt;
int aval;
int mx = 0;
int valid(int n, int inputSeq[])
{
allB = 1;
realS.clear();
map<int, bool> vis;
int st = 0;
int val = 1;
for (int i = 0; i < n; i++)
{
mx = max(mx, inputSeq[i]);
if (vis[inputSeq[i]])
return 0;
vis[inputSeq[i]] = 1;
if (inputSeq[i] <= n)
{
allB = 0;
aval--;
st = i;
val = inputSeq[i];
}
}
int og = st;
while (1)
{
st++;
val++;
if (st >= n)
st = 0;
if (val > n)
val = 1;
realS[inputSeq[st]] = val;
if (inputSeq[st] > n)
nums.insert(inputSeq[st]);
if (st == og)
break;
if (inputSeq[st] != val && inputSeq[st] <= n)
return 0;
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
if (!valid(n, gondolaSeq))
return 0;
int id = 0;
for (int i = n + 1; i <= mx; i++)
{
if (!realS[i])
{
replacementSeq[id] = realS[mx];
realS[mx] = i;
}
else
replacementSeq[id] = realS[i];
id++;
}
return id;
}
//----------------------
int countReplacement(int n, int inputSeq[])
{
cnt = 1;
aval = n;
ll ans = 1;
if (!valid(n, inputSeq))
return 0;
int st = n + 1;
for (auto x : nums)
{
ll num = fastpow(aval, x - st);
ans *= num;
ans %= mod;
aval--;
st = x + 1;
}
if (allB)
ans *= n;
ans %= mod;
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
14 ms |
3960 KB |
Output is correct |
7 |
Correct |
6 ms |
604 KB |
Output is correct |
8 |
Correct |
28 ms |
7256 KB |
Output is correct |
9 |
Correct |
8 ms |
2496 KB |
Output is correct |
10 |
Correct |
33 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
15 ms |
3992 KB |
Output is correct |
7 |
Correct |
6 ms |
604 KB |
Output is correct |
8 |
Correct |
30 ms |
7256 KB |
Output is correct |
9 |
Correct |
9 ms |
2652 KB |
Output is correct |
10 |
Correct |
38 ms |
8452 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
13 ms |
2140 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
35 ms |
4692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
31 ms |
8020 KB |
Output is correct |
12 |
Correct |
37 ms |
9044 KB |
Output is correct |
13 |
Correct |
51 ms |
6228 KB |
Output is correct |
14 |
Correct |
35 ms |
8020 KB |
Output is correct |
15 |
Correct |
54 ms |
10832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
58 ms |
10752 KB |
Output is correct |
10 |
Correct |
42 ms |
9020 KB |
Output is correct |
11 |
Correct |
18 ms |
3676 KB |
Output is correct |
12 |
Correct |
20 ms |
4444 KB |
Output is correct |
13 |
Correct |
5 ms |
1372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
56 ms |
10780 KB |
Output is correct |
10 |
Correct |
43 ms |
8532 KB |
Output is correct |
11 |
Correct |
16 ms |
3552 KB |
Output is correct |
12 |
Correct |
20 ms |
4432 KB |
Output is correct |
13 |
Correct |
4 ms |
1372 KB |
Output is correct |
14 |
Correct |
73 ms |
13072 KB |
Output is correct |
15 |
Correct |
94 ms |
14932 KB |
Output is correct |
16 |
Correct |
13 ms |
3160 KB |
Output is correct |
17 |
Correct |
52 ms |
10008 KB |
Output is correct |
18 |
Correct |
28 ms |
5724 KB |
Output is correct |