#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pi;
typedef vector<pi> pii;
typedef tuple<int,int,int> tii;
typedef vector<ll> li;
typedef vector<li> lii;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define LSOne(s) ((s)&(-s))
ll INF=1e18+10;
int inf=1e9+10;
ll M=1e9+9;
int valid(int n, int inputSeq[])
{
bool flag=1;
int pos=0,val=inf;
REP(i,0,n)if(inputSeq[i]<val){
val=inputSeq[i];
pos=i;
}
if(val>n){
sort(inputSeq,inputSeq+n);
REP(i,0,n-1)if(inputSeq[i]==inputSeq[i+1])flag=0;
if(flag)return 1;
return 0;
}
int c=pos;
pos++;val++;
pos%=n;val%=n;if(val==0)val=n;
while(pos!=c){
if(inputSeq[pos]!=val&&inputSeq[pos]<=n){
flag=0;
break;
}
pos++;val++;
pos%=n;val%=n;if(val==0)val=n;
}
sort(inputSeq,inputSeq+n);
REP(i,0,n-1)if(inputSeq[i]==inputSeq[i+1])flag=0;
if(flag)return 1;
return 0;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
int pos=0,val=inf;
REP(i,0,n)if(gondolaSeq[i]<val){
val=gondolaSeq[i];
pos=i;
}
priority_queue<pi,vector<pi>,greater<pi>> pq;
int c=pos;pos%=n;val%=n;if(val==0)val=n;
if(gondolaSeq[pos]!=val)pq.push({gondolaSeq[pos],val});
pos++;val++;
pos%=n;val%=n;if(val==0)val=n;
while(pos!=c){
if(gondolaSeq[pos]!=val)pq.push({gondolaSeq[pos],val});
pos++;val++;
pos%=n;val%=n;if(val==0)val=n;
}
vi ans;int k=n+1;
while(!pq.empty()){
int x=pq.top().F;
int y=pq.top().S;
pq.pop();
ans.PB(y);
REP(i,k,x)ans.PB(i);
k=x+1;
}
int m=ans.size();
REP(i,0,m)replacementSeq[i]=ans[i];
return m;
}
//----------------------
int countReplacement(int n, int inputSeq[])
{
ll ans=1;
if(valid(n,inputSeq)==0)return 0;
int val=inputSeq[0];
if(val>n)ans=n;
int pos=n-1;vi arr;
while(inputSeq[pos]>n&&pos>=0)arr.PB(inputSeq[pos--]);
if(arr.empty())return 1;
arr.PB(n);pos=0;
ll k=0;ll val2=arr[0];pos++;k++;
int s=arr.size();
while(pos<s){
int t=val2-arr[pos]-1;
if(t!=0){
vector<ll> brr(31);
brr[0]=1;brr[1]=k;
REP(i,2,31){
brr[i]=brr[i-1]*brr[i-1];
brr[i]%=M;
}
REP(i,0,30)if(t&(1<<i)){
ans*=brr[i+1];
ans%=M;
}
}
val2=arr[pos];
pos++;k++;
}
return (int)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 |
0 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 |
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 |
4 ms |
348 KB |
Output is correct |
7 |
Correct |
8 ms |
604 KB |
Output is correct |
8 |
Correct |
6 ms |
604 KB |
Output is correct |
9 |
Correct |
3 ms |
536 KB |
Output is correct |
10 |
Correct |
9 ms |
736 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 |
6 ms |
348 KB |
Output is correct |
7 |
Correct |
8 ms |
604 KB |
Output is correct |
8 |
Correct |
6 ms |
600 KB |
Output is correct |
9 |
Correct |
3 ms |
348 KB |
Output is correct |
10 |
Correct |
9 ms |
764 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
4 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
10 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 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 |
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 |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
6 ms |
600 KB |
Output is correct |
12 |
Correct |
9 ms |
604 KB |
Output is correct |
13 |
Correct |
10 ms |
1368 KB |
Output is correct |
14 |
Correct |
5 ms |
600 KB |
Output is correct |
15 |
Correct |
12 ms |
2376 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
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 |
9 |
Correct |
14 ms |
1096 KB |
Output is correct |
10 |
Correct |
11 ms |
984 KB |
Output is correct |
11 |
Correct |
5 ms |
604 KB |
Output is correct |
12 |
Correct |
6 ms |
604 KB |
Output is correct |
13 |
Correct |
2 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 |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 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 |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
14 ms |
1116 KB |
Output is correct |
10 |
Correct |
11 ms |
984 KB |
Output is correct |
11 |
Correct |
6 ms |
604 KB |
Output is correct |
12 |
Correct |
6 ms |
776 KB |
Output is correct |
13 |
Correct |
2 ms |
344 KB |
Output is correct |
14 |
Correct |
20 ms |
1404 KB |
Output is correct |
15 |
Correct |
24 ms |
2368 KB |
Output is correct |
16 |
Correct |
5 ms |
1112 KB |
Output is correct |
17 |
Correct |
17 ms |
1628 KB |
Output is correct |
18 |
Correct |
8 ms |
1116 KB |
Output is correct |