#include "gondola.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const ll MOD=1e9+9;
ll pot(ll a, ll b) {
ll ans=1;
while(b) {
if(b&1) ans=(ans*a)%MOD;
a=(a*a)%MOD;
b/=2;
}
return ans;
}
int valid(int n, int T[]) {
rep(i, n) --T[i];
map<int,int>mp;
rep(i, n) {
++mp[T[i]];
if(mp[T[i]]>1) return 0;
}
rep(i, n) if(T[i]<n) {
rep(j, n) if(T[(i+j)%n]<n) {
if(T[(i+j)%n]!=(T[i]+j)%n) return 0;
}
return 1;
}
return 1;
}
int replacement(int n, int T[], int ans[]) {
rep(i, n) if(T[i]<=n) {
int P[n];
rep(j, n) P[(j+T[i]-1-i+n)%n]=T[j];
rep(j, n) T[j]=P[j];
break;
}
int ma=0;
rep(i, n) ma=max(ma, T[i]);
rep(i, n) if(T[i]>n && T[i]!=ma) ans[T[i]-n-1]=i+1;
rep(i, n) if(T[i]==ma) {
int lst=i+1;
rep(j, ma-n) if(!ans[j]) {
ans[j]=lst;
lst=j+n+1;
}
}
return ma-n;
}
int countReplacement(int n, int T[]) {
if(!valid(n, T)) return 0;
vector<ll>V;
V.pb(0);
rep(i, n) if(T[i]>=n) V.pb(T[i]-n+1);
sort(all(V));
ll ans=1;
for(ll i=1; i<V.size(); ++i) ans=(ans*pot(V.size()-i, V[i]-V[i-1]-1))%MOD;
int p=0;
rep(i, n) if(T[i]>=n) ++p;
if(p==n) ans=(ans*n)%MOD;
return ans;
}
Compilation message
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:62:15: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for(ll i=1; i<V.size(); ++i) ans=(ans*pot(V.size()-i, V[i]-V[i-1]-1))%MOD;
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
13 ms |
2180 KB |
Output is correct |
7 |
Correct |
7 ms |
588 KB |
Output is correct |
8 |
Correct |
21 ms |
3828 KB |
Output is correct |
9 |
Correct |
6 ms |
1356 KB |
Output is correct |
10 |
Correct |
28 ms |
4496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
11 ms |
2124 KB |
Output is correct |
7 |
Correct |
7 ms |
588 KB |
Output is correct |
8 |
Correct |
28 ms |
3992 KB |
Output is correct |
9 |
Correct |
7 ms |
1428 KB |
Output is correct |
10 |
Correct |
29 ms |
4428 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
15 ms |
2004 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
42 ms |
4652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
7 ms |
844 KB |
Output is correct |
12 |
Correct |
8 ms |
952 KB |
Output is correct |
13 |
Correct |
9 ms |
1228 KB |
Output is correct |
14 |
Correct |
7 ms |
844 KB |
Output is correct |
15 |
Correct |
16 ms |
2124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
37 ms |
3980 KB |
Output is correct |
10 |
Correct |
29 ms |
3284 KB |
Output is correct |
11 |
Correct |
11 ms |
1356 KB |
Output is correct |
12 |
Correct |
13 ms |
1612 KB |
Output is correct |
13 |
Correct |
3 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
45 ms |
3984 KB |
Output is correct |
10 |
Correct |
35 ms |
3380 KB |
Output is correct |
11 |
Correct |
10 ms |
1356 KB |
Output is correct |
12 |
Correct |
13 ms |
1596 KB |
Output is correct |
13 |
Correct |
3 ms |
556 KB |
Output is correct |
14 |
Correct |
47 ms |
4920 KB |
Output is correct |
15 |
Correct |
54 ms |
5956 KB |
Output is correct |
16 |
Correct |
9 ms |
1344 KB |
Output is correct |
17 |
Correct |
34 ms |
4036 KB |
Output is correct |
18 |
Correct |
19 ms |
2720 KB |
Output is correct |