#include <stdlib.h>
#include "gondola.h"
#include <bits/stdc++.h>
#define MOD 1000000009
#define ll long long
using namespace std;
long long pow(long long a,long long b){
if(b==1) return a;
long long c=1;
if(b%2==1) c=a;
long long d=pow(a,b/2);
return ((d*d)%MOD*c)%MOD;
}
int valid(int n, int a[])
{
int k[250000]={0};
int y[250000]={0},d=0;
for(int i=0;i<n;i++){
k[a[i]]++;
}
for(int i=0;i<n;i++){
if(k[a[i]]>1) return 0;
}
for(int i=0;i<n;i++){
if(a[i]<=n){
if(y[(a[i]-i+n)%n]==0) d++;
y[(a[i]-i+n)%n]++;
}
}
if(d<=1) return 1;
return 0;
}
//----------------------
int replacement(int n, int a[], int replacementSeq[])
{
int y[100000]={0};
for(int i=0;i<n;i++){
if(a[i]<=n){
y[(a[i]-i+n)%n]++;
}
}
int e=0;
for(int i=0;i<n;i++){
e=max(e,y[i]);
}
return n-e;
}
//----------------------
int countReplacement(int n, int a[])
{
unordered_map<ll,ll>k,y;
long long e=0;
long long d=0;
vector<long long>v;
for(int i=0;i<n;i++){
k[a[i]]++;
}
v.push_back((ll)n);
for(int i=0;i<n;i++){
if(k[a[i]]>1) return 0;
}
for(int i=0;i<n;i++){
if(a[i]<=n){
e++;
if(y[(a[i]-i+n)%n]==0) d++;
y[(a[i]-i+n)%n]++;
}
else v.push_back((ll)a[i]);
}
if(d>1) return 0;
if(d==1 && e==(ll)n) return 1;
sort(v.begin(),v.end());
e=(ll)n-e;
long long ans=1;
for(long long i=1;i<v.size();i++){
long long p=(ll)v[i]-(ll)v[i-1]-(ll)1;
if(p==(ll)0) continue;
ans=(ans*pow((ll)(e-i+1),p))%MOD;
}
if(e==(long long)n){
ans=(ans*(ll)n)%MOD;
}
return ans;
}
Compilation message
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:80:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | for(long long i=1;i<v.size();i++){
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2304 KB |
Output is correct |
2 |
Correct |
2 ms |
2304 KB |
Output is correct |
3 |
Correct |
2 ms |
2304 KB |
Output is correct |
4 |
Correct |
2 ms |
2304 KB |
Output is correct |
5 |
Correct |
2 ms |
2304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2304 KB |
Output is correct |
2 |
Correct |
2 ms |
2304 KB |
Output is correct |
3 |
Correct |
2 ms |
2304 KB |
Output is correct |
4 |
Correct |
2 ms |
2304 KB |
Output is correct |
5 |
Correct |
2 ms |
2304 KB |
Output is correct |
6 |
Correct |
7 ms |
2432 KB |
Output is correct |
7 |
Correct |
15 ms |
2560 KB |
Output is correct |
8 |
Correct |
12 ms |
2560 KB |
Output is correct |
9 |
Correct |
5 ms |
2304 KB |
Output is correct |
10 |
Correct |
14 ms |
2536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2304 KB |
Output is correct |
2 |
Correct |
2 ms |
2304 KB |
Output is correct |
3 |
Correct |
2 ms |
2336 KB |
Output is correct |
4 |
Correct |
1 ms |
2304 KB |
Output is correct |
5 |
Correct |
2 ms |
2304 KB |
Output is correct |
6 |
Correct |
8 ms |
2432 KB |
Output is correct |
7 |
Correct |
15 ms |
2560 KB |
Output is correct |
8 |
Correct |
12 ms |
2560 KB |
Output is correct |
9 |
Correct |
6 ms |
2304 KB |
Output is correct |
10 |
Correct |
14 ms |
2560 KB |
Output is correct |
11 |
Correct |
2 ms |
2432 KB |
Output is correct |
12 |
Correct |
2 ms |
2304 KB |
Output is correct |
13 |
Correct |
9 ms |
2432 KB |
Output is correct |
14 |
Correct |
2 ms |
2304 KB |
Output is correct |
15 |
Correct |
17 ms |
2560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
768 KB |
Integer 0 violates the range [1, 76] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
768 KB |
Integer 0 violates the range [1, 76] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
768 KB |
Integer 0 violates the range [1, 76] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
384 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 |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
256 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
288 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
33 ms |
4892 KB |
Output is correct |
10 |
Correct |
27 ms |
3724 KB |
Output is correct |
11 |
Correct |
10 ms |
1792 KB |
Output is correct |
12 |
Correct |
12 ms |
1920 KB |
Output is correct |
13 |
Correct |
3 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
384 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 |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
33 ms |
4864 KB |
Output is correct |
10 |
Correct |
27 ms |
3724 KB |
Output is correct |
11 |
Correct |
10 ms |
1792 KB |
Output is correct |
12 |
Correct |
12 ms |
1920 KB |
Output is correct |
13 |
Correct |
3 ms |
768 KB |
Output is correct |
14 |
Correct |
42 ms |
5788 KB |
Output is correct |
15 |
Correct |
49 ms |
7204 KB |
Output is correct |
16 |
Correct |
9 ms |
1792 KB |
Output is correct |
17 |
Correct |
32 ms |
5148 KB |
Output is correct |
18 |
Correct |
18 ms |
3212 KB |
Output is correct |