#include "gondola.h"
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <cassert>
#include <vector>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+9;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int valid(int n, int inputSeq[]){
int id=-1,x;
for(int i=0;i<n;i++) if(inputSeq[i]<=n){
if(id==-1) id=i,x=inputSeq[i];
if((x+i-id-1)%n!=inputSeq[i]-1) return 0;
}
set<int> st;
for(int i=0;i<n;i++) st.insert(inputSeq[i]);
return st.size()==n;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
vp a;
int id=0,x=1;
for(int i=0;i<n;i++){
if(gondolaSeq[i]>n) a.push_back({gondolaSeq[i],i});
else id=i,x=gondolaSeq[i];
}
sort(a.begin(),a.end());
int I=0,mx=n;
for(auto p:a){
replacementSeq[I++]=(p.second-id+x-1+2*n)%n+1;
mx++;
while(mx<p.first){
replacementSeq[I++]=mx;
mx++;
}
}
return I;
}
//----------------------
ll Pow(ll n,ll p){
ll r=1;
for(;p>0;p>>=1){
if(p&1) r=(r*n)%mod;
n=(n*n)%mod;
}
return r;
}
int countReplacement(int n, int inputSeq[]){
if(!valid(n,inputSeq)) return 0;
vl a;
bool B=1;
for(int i=0;i<n;i++){
if(inputSeq[i]>n) a.push_back(inputSeq[i]);
else B=0;
}
sort(a.begin(),a.end());
ll res=(B?n:1),m=a.size();
for(int i=0;i<m-1;i++) (res*=Pow(m-i,a[i]-(i?a[i-1]:n)-1))%=mod;
return (int)res;
}
Compilation message
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:47:18: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
47 | return st.size()==n;
| ~~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
14 ms |
2176 KB |
Output is correct |
7 |
Correct |
20 ms |
640 KB |
Output is correct |
8 |
Correct |
27 ms |
3960 KB |
Output is correct |
9 |
Correct |
8 ms |
1536 KB |
Output is correct |
10 |
Correct |
31 ms |
4608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
13 ms |
2176 KB |
Output is correct |
7 |
Correct |
14 ms |
640 KB |
Output is correct |
8 |
Correct |
27 ms |
3968 KB |
Output is correct |
9 |
Correct |
8 ms |
1536 KB |
Output is correct |
10 |
Correct |
29 ms |
4608 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
0 ms |
256 KB |
Output is correct |
13 |
Correct |
6 ms |
512 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
14 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
12 ms |
640 KB |
Output is correct |
12 |
Correct |
14 ms |
640 KB |
Output is correct |
13 |
Correct |
19 ms |
1296 KB |
Output is correct |
14 |
Correct |
12 ms |
640 KB |
Output is correct |
15 |
Correct |
25 ms |
2296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
43 ms |
4472 KB |
Output is correct |
10 |
Correct |
36 ms |
3832 KB |
Output is correct |
11 |
Correct |
12 ms |
1536 KB |
Output is correct |
12 |
Correct |
16 ms |
1920 KB |
Output is correct |
13 |
Correct |
4 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
45 ms |
4472 KB |
Output is correct |
10 |
Correct |
34 ms |
3832 KB |
Output is correct |
11 |
Correct |
13 ms |
1536 KB |
Output is correct |
12 |
Correct |
15 ms |
1920 KB |
Output is correct |
13 |
Correct |
4 ms |
640 KB |
Output is correct |
14 |
Correct |
71 ms |
5416 KB |
Output is correct |
15 |
Correct |
68 ms |
6136 KB |
Output is correct |
16 |
Correct |
10 ms |
1408 KB |
Output is correct |
17 |
Correct |
41 ms |
4216 KB |
Output is correct |
18 |
Correct |
21 ms |
2432 KB |
Output is correct |