#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
map <int, int> mp;
set <int> s;
int valid(int n, int inputSeq[])
{
int pos=0;
for (int i=0;i<n;i++){
if (mp.count(inputSeq[i]))
return 0;
if (inputSeq[pos]>inputSeq[i])
pos=i;
mp[inputSeq[i]]=1;
}
if (inputSeq[pos]>n)
return 1;
for (int i=0;i<n;i++)
if (inputSeq[i]<=n&&((i-pos+n)%n+inputSeq[pos]-1)%n+1!=inputSeq[i])
return 0;
return 1;
}
//----------------------
int pos[250001],cur[100001];
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
int val=0,p=0,mx=0;
for (int i=0;i<n;i++){
if (gondolaSeq[p]>gondolaSeq[i])
p=i;
mx=max(mx,gondolaSeq[i]);
}
if (gondolaSeq[p]>n)
val=1,p=0;
else
val=gondolaSeq[p];
for (int i=0;i<n;i++){
int j=((i-p+n)%n+val-1)%n+1;
pos[gondolaSeq[i]]=j;
cur[j]=j;
s.insert(i+1);
}
int l=0;
for (int i=n+1;i<=mx;i++){
if (!pos[i])
pos[i]=*s.begin();
else
s.erase(pos[i]);
replacementSeq[l]=cur[pos[i]];
l++;
cur[pos[i]]=i;
}
return l;
}
//----------------------
const int mod=1000000009;
vector <int> v;
int pw(int a, int b){
if (!b)
return 1;
int t=pw(a,b>>1);
t=1LL*t*t%mod;
return (b&1?1LL*t*a%mod:t);
}
int countReplacement(int n, int inputSeq[])
{
if (!valid(n,inputSeq))
return 0;
for (int i=0;i<n;i++)
if (inputSeq[i]>n)
v.push_back(inputSeq[i]);
v.push_back(n);
sort(v.begin(),v.end());
int res=1;
for (int i=1;i<v.size();i++)
res=1LL*res*pw(v.size()-i,v[i]-v[i-1]-1)%mod;
return res;
}
Compilation message
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:86:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | for (int i=1;i<v.size();i++)
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2904 KB |
Output is correct |
6 |
Correct |
10 ms |
4440 KB |
Output is correct |
7 |
Correct |
7 ms |
3164 KB |
Output is correct |
8 |
Correct |
19 ms |
6492 KB |
Output is correct |
9 |
Correct |
6 ms |
3788 KB |
Output is correct |
10 |
Correct |
23 ms |
7008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
10 ms |
4440 KB |
Output is correct |
7 |
Correct |
7 ms |
3164 KB |
Output is correct |
8 |
Correct |
19 ms |
6492 KB |
Output is correct |
9 |
Correct |
6 ms |
3676 KB |
Output is correct |
10 |
Correct |
23 ms |
7000 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
13 ms |
4324 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
31 ms |
7260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2492 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2496 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2400 KB |
Output is correct |
6 |
Correct |
1 ms |
2400 KB |
Output is correct |
7 |
Correct |
1 ms |
2400 KB |
Output is correct |
8 |
Correct |
1 ms |
2496 KB |
Output is correct |
9 |
Correct |
32 ms |
7000 KB |
Output is correct |
10 |
Correct |
25 ms |
6236 KB |
Output is correct |
11 |
Correct |
12 ms |
3928 KB |
Output is correct |
12 |
Correct |
12 ms |
4188 KB |
Output is correct |
13 |
Incorrect |
3 ms |
2908 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2400 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2492 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2648 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
32 ms |
6988 KB |
Output is correct |
10 |
Correct |
25 ms |
6276 KB |
Output is correct |
11 |
Correct |
9 ms |
3932 KB |
Output is correct |
12 |
Correct |
13 ms |
4176 KB |
Output is correct |
13 |
Incorrect |
3 ms |
2908 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |