#include "gondola.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn = 1e5 + 20;
const int maxm = 2.5e5 + 20;
int ex[maxn] , num[maxm];
int valid(int n, int a[])
{
set<int> st;
for(int i = 0; i < n; i++)
{
a[i]--;
if(a[i] < 0)
return 0;
st.insert(a[i]);
}
int f = 1;
for(int i = 0; i < n; i++)
if(a[i] < n)
f &= (a[(i + 1) % n] >= n || a[(i + 1) % n] == (a[i] + 1) % n);
f &= (int)st.size() == n;
return f;
}
//----------------------
int replacement(int n, int a[], int res[])
{
memset(num , -1 , sizeof num);
bool f = 0;
for(int i = 0; i < n; i++)
{
a[i]--;
if(!f && a[i] < n)
{
for(int j = 0; j < n; j++)
ex[j] = ((a[i] + (j - i) + n) % n) + 1;
f = 1;
}
}
if(!f)
for(int i = 0; i < n; i++)
ex[i] = i + 1;
int m = *max_element(a , a + n);
int p = max_element(a , a + n) - a;
for(int i = 0; i < n; i++)
num[a[i]] = i;
for(int i = n; i <= m; i++)
{
if(num[i] < 0)
res[i - n] = ex[p] , ex[p] = i + 1;
else
res[i - n] = ex[num[i]] , ex[num[i]] = i + 1;
}
return m - n + 1;
}
//----------------------
const int mod = 1e9 + 9;
int bpw(int a , int b)
{
if(b <= 0)
return 1;
int x = bpw(a , b / 2);
x = 1LL * x * x % mod;
if(b&1)
x = 1LL * x * a % mod;
return x;
}
int countReplacement(int n, int a[])
{
if(!valid(n , a))
return 0;
bool f = 0;
int res = 1;
vector<int> cmp;
for(int i = 0; i < n; i++)
{
if(a[i] >= n)
cmp.pb(a[i]);
else
f = 1;
}
if(!f)
for(int i = 0; i < n; i++)
res = n;
sort(cmp.begin() , cmp.end());
int m = cmp.size() , last = n;
for(int i = 0; i < m; i++)
{
res = 1LL * res * bpw(m - i , cmp[i] - last) % mod;
last = cmp[i] + 1;
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
248 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
16 ms |
2268 KB |
Output is correct |
7 |
Correct |
38 ms |
3648 KB |
Output is correct |
8 |
Correct |
29 ms |
3960 KB |
Output is correct |
9 |
Correct |
10 ms |
1532 KB |
Output is correct |
10 |
Correct |
35 ms |
4604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
16 ms |
2168 KB |
Output is correct |
7 |
Correct |
39 ms |
3704 KB |
Output is correct |
8 |
Correct |
28 ms |
3960 KB |
Output is correct |
9 |
Correct |
10 ms |
1528 KB |
Output is correct |
10 |
Correct |
35 ms |
4600 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
20 ms |
2040 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
49 ms |
4728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1272 KB |
Output is correct |
2 |
Correct |
3 ms |
1272 KB |
Output is correct |
3 |
Correct |
3 ms |
1244 KB |
Output is correct |
4 |
Correct |
3 ms |
1272 KB |
Output is correct |
5 |
Correct |
3 ms |
1276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1272 KB |
Output is correct |
2 |
Correct |
3 ms |
1272 KB |
Output is correct |
3 |
Correct |
3 ms |
1272 KB |
Output is correct |
4 |
Correct |
3 ms |
1272 KB |
Output is correct |
5 |
Correct |
3 ms |
1272 KB |
Output is correct |
6 |
Correct |
3 ms |
1272 KB |
Output is correct |
7 |
Correct |
4 ms |
1372 KB |
Output is correct |
8 |
Correct |
4 ms |
1276 KB |
Output is correct |
9 |
Correct |
3 ms |
1272 KB |
Output is correct |
10 |
Correct |
3 ms |
1400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1272 KB |
Output is correct |
2 |
Correct |
3 ms |
1272 KB |
Output is correct |
3 |
Correct |
3 ms |
1276 KB |
Output is correct |
4 |
Correct |
3 ms |
1272 KB |
Output is correct |
5 |
Correct |
3 ms |
1272 KB |
Output is correct |
6 |
Correct |
3 ms |
1268 KB |
Output is correct |
7 |
Correct |
3 ms |
1272 KB |
Output is correct |
8 |
Correct |
3 ms |
1400 KB |
Output is correct |
9 |
Correct |
4 ms |
1400 KB |
Output is correct |
10 |
Correct |
3 ms |
1400 KB |
Output is correct |
11 |
Correct |
14 ms |
1912 KB |
Output is correct |
12 |
Correct |
15 ms |
2040 KB |
Output is correct |
13 |
Correct |
15 ms |
2296 KB |
Output is correct |
14 |
Correct |
14 ms |
1912 KB |
Output is correct |
15 |
Correct |
23 ms |
3192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
420 KB |
Output is correct |
3 |
Correct |
2 ms |
252 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
49 ms |
4088 KB |
Output is correct |
10 |
Correct |
41 ms |
3448 KB |
Output is correct |
11 |
Correct |
15 ms |
1528 KB |
Output is correct |
12 |
Correct |
19 ms |
1656 KB |
Output is correct |
13 |
Correct |
5 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
50 ms |
4088 KB |
Output is correct |
10 |
Correct |
39 ms |
3448 KB |
Output is correct |
11 |
Correct |
15 ms |
1528 KB |
Output is correct |
12 |
Correct |
18 ms |
1784 KB |
Output is correct |
13 |
Correct |
5 ms |
632 KB |
Output is correct |
14 |
Correct |
64 ms |
5116 KB |
Output is correct |
15 |
Correct |
74 ms |
5596 KB |
Output is correct |
16 |
Correct |
12 ms |
1400 KB |
Output is correct |
17 |
Correct |
47 ms |
3964 KB |
Output is correct |
18 |
Correct |
26 ms |
2540 KB |
Output is correct |