#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))
typedef long long int lli;
typedef pair <lli,lli> ii;
typedef pair <lli,ii> iii;
typedef vector <lli> vi;
int valid(int n, int inputSeq[])
{
lli p=-1;
for(lli i=0;i<n;++i)
{
if(inputSeq[i]<=n)
{
p=i;
break;
}
}
lli ch=0,v=inputSeq[p]-1;
if(v==0)
v=n;
for(lli i=p-1;i>=0;--i)
{
if(v==0)
v=n;
if(inputSeq[i]<=n&&inputSeq[i]!=v)
{
ch=1;
break;
}
v--;
}
v=inputSeq[p]+1;
if(v==n+1)
v=1;
for(lli i=p+1;i<n;++i)
{
if(v==n+1)
v=1;
if(inputSeq[i]<=n&&inputSeq[i]!=v)
{
ch=1;
break;
}
v++;
}
sort(inputSeq,inputSeq+n);
for(int i=1;i<n;++i)
{
if(inputSeq[i]==inputSeq[i-1])
ch=1;
}
return(!ch);
}
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
lli p=-1;
lli x=0,v=n+1,val;
lli varr[n],val1=1;
for(lli i=0;i<n;++i)
{
if(gondolaSeq[i]<=n)
{
p=i;
break;
}
}
vector<ii> v1;
if(p!=-1)
{
val1=gondolaSeq[p]-1;
varr[p]=gondolaSeq[p];
for(lli i=p-1;i>=0;--i)
{
if(val1==0)
val1=n;
varr[i]=val1;
val1--;
}
val1=gondolaSeq[p]+1;
for(lli i=p+1;i<n;++i)
{
if(val1>n)
val1=1;
varr[i]=val1;
val1++;
}
}
for(lli i=0;i<n;++i)
{
if(p==-1)
val=i+1;
else
{
val=varr[i];
}
if(gondolaSeq[i]>n)
v1.pb(mp(gondolaSeq[i],val));
}
sort(all(v1));
for(lli i=0;i<v1.size();++i)
{
replacementSeq[x]=v1[i].S;
x++;
while(v<v1[i].F)
{
replacementSeq[x]=v;
x++;
v++;
}
v++;
}
return(x);
}
lli tel(lli p,lli n)
{
lli b=0,ans=1,a=n;
while((1LL<<b)<=p)
{
if(bit(p,b))
ans=(ans*a)%1000000009;
a=(a*a)%1000000009;
b++;
}
return(ans);
}
int countReplacement(int n, int inputSeq[])
{
if(!valid(n,inputSeq))
return(0);
lli co=0,ans=1,l=n;
for(lli i=0;i<n;++i)
{
if(inputSeq[i]>n)
co++;
}
sort(inputSeq,inputSeq+n);
for(lli i=0;i<n;++i)
{
if(inputSeq[i]<=n)
continue;
if(co==n)
ans=(ans*tel(inputSeq[i]-l,co))%1000000009;
else
ans=(ans*tel(inputSeq[i]-l-1,co))%1000000009;
l=inputSeq[i];
co--;
}
return(ans);
}
Compilation message
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:111:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(lli i=0;i<v1.size();++i)
~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
12 ms |
760 KB |
Output is correct |
7 |
Correct |
23 ms |
1152 KB |
Output is correct |
8 |
Correct |
18 ms |
1024 KB |
Output is correct |
9 |
Correct |
9 ms |
512 KB |
Output is correct |
10 |
Correct |
22 ms |
1144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
12 ms |
660 KB |
Output is correct |
7 |
Correct |
23 ms |
1144 KB |
Output is correct |
8 |
Correct |
17 ms |
1016 KB |
Output is correct |
9 |
Correct |
10 ms |
512 KB |
Output is correct |
10 |
Correct |
23 ms |
1152 KB |
Output is correct |
11 |
Correct |
5 ms |
256 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
13 ms |
640 KB |
Output is correct |
14 |
Correct |
6 ms |
256 KB |
Output is correct |
15 |
Correct |
34 ms |
1152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
512 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
15 ms |
1664 KB |
Output is correct |
12 |
Correct |
18 ms |
1920 KB |
Output is correct |
13 |
Correct |
20 ms |
1824 KB |
Output is correct |
14 |
Correct |
16 ms |
1664 KB |
Output is correct |
15 |
Correct |
26 ms |
2536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
23 ms |
1024 KB |
Output is correct |
10 |
Correct |
20 ms |
896 KB |
Output is correct |
11 |
Correct |
11 ms |
512 KB |
Output is correct |
12 |
Correct |
11 ms |
640 KB |
Output is correct |
13 |
Correct |
6 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
344 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
32 ms |
1144 KB |
Output is correct |
10 |
Correct |
26 ms |
896 KB |
Output is correct |
11 |
Correct |
12 ms |
640 KB |
Output is correct |
12 |
Correct |
13 ms |
640 KB |
Output is correct |
13 |
Correct |
6 ms |
512 KB |
Output is correct |
14 |
Correct |
28 ms |
1400 KB |
Output is correct |
15 |
Correct |
32 ms |
1664 KB |
Output is correct |
16 |
Correct |
9 ms |
512 KB |
Output is correct |
17 |
Correct |
24 ms |
1280 KB |
Output is correct |
18 |
Correct |
15 ms |
896 KB |
Output is correct |