#include "gondola.h"
#include<bits/stdc++.h>
#define pii pair<int,int>
#define ll long long
using namespace std;
const ll mod=1e9+9;
ll bigmod(ll a,ll b)
{
if(b==0)return 1;
ll mid=b/2;
ll c=bigmod(a,mid);
if(b%2==0)return (c*c)%mod;
c=(c*c)%mod;
return (a*c)%mod;
}
int valid(int n, int inputSeq[])
{
vector<int> b;
int st=-1;
for(int i=0;i<n;i++)
{
b.push_back(inputSeq[i]);
if(inputSeq[i]<=n && st==-1)
st=i;
}
sort(b.begin(),b.end());
for(int i=1;i<n;i++)if(b[i]==b[i-1])return 0;
if(st==-1)return 1;
int kb=inputSeq[st]+1;
for(int i=st+1;i<n;i++)
{
if(kb>n)kb=1;
if(inputSeq[i]!=kb++ && inputSeq[i]<=n)return 0;
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
int st=-1;
vector<pii> v;
for(int i=0;i<n;i++)
{
if(gondolaSeq[i]<=n)
{
st=i;
break;
}
}
if(st==-1)
{
for(int i=0;i<n;i++)if(gondolaSeq[i]>n)v.push_back({gondolaSeq[i],i+1});
}
else
{
int s;
if(gondolaSeq[st]>st)s=gondolaSeq[st]-st;
else s=n-(st-gondolaSeq[st]);
for(int i=0;i<n;i++)
{
if(s==n+1)s=1;
if(gondolaSeq[i]>n)
{
v.push_back({gondolaSeq[i],s});
}
s++;
}
}
sort(v.begin(),v.end());
int li=0;
int tr=n+1;
for(int i=0;i<v.size();i++)
{
replacementSeq[li++]=v[i].second;
while(tr<v[i].first)
{
replacementSeq[li++]=tr++;
}
tr++;
}
return li;
}
//----------------------
int countReplacement(int n, int inputSeq[])
{
if(!valid(n,inputSeq))return 0;
sort(inputSeq,inputSeq+n);
ll last=n;
ll res=1;
if(inputSeq[0]>n)res=n;
for(int i=0;i<n;i++)
{
if(inputSeq[i]<=n)continue;
ll dd=inputSeq[i]-1-last;
res*=bigmod(n-i,dd);
res%=mod;
last=inputSeq[i];
}
return res%mod;
}
Compilation message
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:88:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v.size();i++)
~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 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 |
252 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
11 ms |
888 KB |
Output is correct |
7 |
Correct |
21 ms |
1268 KB |
Output is correct |
8 |
Correct |
15 ms |
1268 KB |
Output is correct |
9 |
Correct |
7 ms |
632 KB |
Output is correct |
10 |
Correct |
20 ms |
1268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
10 ms |
888 KB |
Output is correct |
7 |
Correct |
21 ms |
1268 KB |
Output is correct |
8 |
Correct |
15 ms |
1224 KB |
Output is correct |
9 |
Correct |
7 ms |
632 KB |
Output is correct |
10 |
Correct |
20 ms |
1268 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
10 ms |
888 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
22 ms |
1268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
380 KB |
Output is correct |
5 |
Correct |
3 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 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 |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
268 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
46 ms |
632 KB |
Output is correct |
12 |
Correct |
13 ms |
632 KB |
Output is correct |
13 |
Correct |
19 ms |
1276 KB |
Output is correct |
14 |
Correct |
12 ms |
636 KB |
Output is correct |
15 |
Correct |
24 ms |
2276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
# |
결과 |
실행 시간 |
메모리 |
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 |
4 |
Correct |
2 ms |
376 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 |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
26 ms |
1268 KB |
Output is correct |
10 |
Correct |
21 ms |
1016 KB |
Output is correct |
11 |
Correct |
15 ms |
632 KB |
Output is correct |
12 |
Correct |
17 ms |
760 KB |
Output is correct |
13 |
Correct |
4 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 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 |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 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 |
256 KB |
Output is correct |
9 |
Correct |
26 ms |
1268 KB |
Output is correct |
10 |
Correct |
22 ms |
1016 KB |
Output is correct |
11 |
Correct |
9 ms |
632 KB |
Output is correct |
12 |
Correct |
11 ms |
632 KB |
Output is correct |
13 |
Correct |
4 ms |
376 KB |
Output is correct |
14 |
Correct |
33 ms |
1268 KB |
Output is correct |
15 |
Correct |
36 ms |
1320 KB |
Output is correct |
16 |
Correct |
8 ms |
632 KB |
Output is correct |
17 |
Correct |
24 ms |
1016 KB |
Output is correct |
18 |
Correct |
14 ms |
888 KB |
Output is correct |