#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(a) a.begin(), a.end()
#define F first
#define S second
#define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
#define fm(a,i,c) for(int (a) = (i); (a) >= (c); (a)--)
#define vii vector<int>
#define vll vector<ll>
const long long mod=1e9+9;
ll binpow(ll a, ll n){
if(n==0) return 1;
ll res=binpow(a,n/2);
res=(res*res)%mod;
if(n%2) res=(res*a)%mod;
return res;
}
int valid(int n, int a[])
{
map<int,int> mp;
vector<pair<int,int>> pos;
for(int i=0;i<n;i++){
if(mp.count(a[i])) return 0;
mp[a[i]]=i;
}
bool ok=1;
for(int i=1;i<=n;i++){
if(mp.count(i)){
pos.push_back({mp[i],i});
}
}
for(int i=1;i<pos.size();i++){
int d=abs(pos[i-1].F-pos[i].F);
if(pos[i-1].F>pos[i].F){
d=n-d;
}
if(d!=pos[i].S-pos[i-1].S) return 0;
}
return 1;
}
//----------------------
int replacement(int n, int g[], int ans[])
{
int mn=0;
for(int i=0;i<n;i++){
if(g[mn]>g[i]) mn=i;
} vector<int> ng(n);
if(g[mn]<=n){
int cnt=0;mn-=g[mn]-1;
if(mn<0) mn+=n;// cout<<mn<<" mN\n";
for(int i=mn;i<n;i++) ng[cnt++]=g[i];
for(int i=0;i<mn;i++) ng[cnt++]=g[i];
}else for(int i=0;i<n;i++) ng[i]=g[i];
vector<pair<int,int>> pos;
for(int i=0;i<n;i++){
pos.push_back({ng[i],i+1});
}//for(int i=0;i<n;i++) cout<<ng[i]<<' ';cout<<endl;
sort(pos.begin(),pos.end());
int cur=n+1;
vector<int> res;
for(int i=0;i<n;i++){
if(pos[i].F==pos[i].S) continue;
res.push_back(pos[i].S);
while(cur<pos[i].F) res.push_back(cur++);
cur++;
}
for(int i=0;i<cur-n-1;i++) ans[i]=res[i];
return cur-n-1;
}
//----------------------
int countReplacement(int n, int inputSeq[])
{
if(valid(n,inputSeq)==0) return 0;
vector<ll> ng(n);
ll cnt=0;
for(int i=0;i<n;i++) ng[i]=inputSeq[i],cnt+=(ng[i]>n);
sort(all(ng));
ll cur=n+1;
ll ans=1; if(cnt==n) ans=n;
for(int i=0;i<n;i++){
if(ng[i]<=n) continue;
ans*=binpow(cnt,ng[i]-cur); ans%=mod; cnt--; cur=ng[i]+1;
}return ans;
}
Compilation message
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:39:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(int i=1;i<pos.size();i++){
| ~^~~~~~~~~~~
gondola.cpp:33:8: warning: unused variable 'ok' [-Wunused-variable]
33 | bool ok=1;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
21 ms |
3024 KB |
Output is correct |
7 |
Correct |
11 ms |
884 KB |
Output is correct |
8 |
Correct |
32 ms |
5364 KB |
Output is correct |
9 |
Correct |
10 ms |
1984 KB |
Output is correct |
10 |
Correct |
44 ms |
5908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
16 ms |
3000 KB |
Output is correct |
7 |
Correct |
8 ms |
832 KB |
Output is correct |
8 |
Correct |
32 ms |
5312 KB |
Output is correct |
9 |
Correct |
11 ms |
1888 KB |
Output is correct |
10 |
Correct |
42 ms |
5960 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
20 ms |
2236 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
49 ms |
5612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
300 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
304 KB |
Output is correct |
5 |
Correct |
1 ms |
304 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
12 ms |
2244 KB |
Output is correct |
12 |
Correct |
11 ms |
2380 KB |
Output is correct |
13 |
Correct |
14 ms |
1760 KB |
Output is correct |
14 |
Correct |
13 ms |
2380 KB |
Output is correct |
15 |
Correct |
25 ms |
2404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
312 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
304 KB |
Output is correct |
9 |
Correct |
60 ms |
4756 KB |
Output is correct |
10 |
Correct |
35 ms |
4108 KB |
Output is correct |
11 |
Correct |
13 ms |
1540 KB |
Output is correct |
12 |
Correct |
15 ms |
1868 KB |
Output is correct |
13 |
Correct |
3 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
304 KB |
Output is correct |
9 |
Correct |
42 ms |
4692 KB |
Output is correct |
10 |
Correct |
36 ms |
4116 KB |
Output is correct |
11 |
Correct |
11 ms |
1492 KB |
Output is correct |
12 |
Correct |
14 ms |
1876 KB |
Output is correct |
13 |
Correct |
3 ms |
596 KB |
Output is correct |
14 |
Correct |
51 ms |
5336 KB |
Output is correct |
15 |
Correct |
57 ms |
6048 KB |
Output is correct |
16 |
Correct |
9 ms |
1364 KB |
Output is correct |
17 |
Correct |
37 ms |
4148 KB |
Output is correct |
18 |
Correct |
19 ms |
2464 KB |
Output is correct |