#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb(e) push_back(e)
#define sv(a) sort(a.begin(),a.end())
#define sa(a,n) sort(a,a+n)
#define mp(a,b) make_pair(a,b)
#define vf first
#define vs second
#define ar array
#define all(x) x.begin(),x.end()
const int inf = 0x3f3f3f3f;
const int mod = 1000000009;
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
bool remender(ll a , ll b){return a%b;}
#include "gondola.h"
ll multi(ll x , ll y){
return (x*y)%mod;
}
ll power(ll x , ll y){
x %= mod;
ll res = 1;
while(y > 0){
if(y&1)res=multi(res,x);
y=y>>1;
x = multi(x,x);
}
return res;
}
int valid(int n, int arr[]){
for(int i = 0; i < n; i++){
if(arr[i] <= n){
int cur = arr[i];
int j = i + 1;
j %= n;
while(j != i){
cur = 1 + (cur % n);
if(cur != arr[j] && arr[j] <= n)return 0;
j++;
j %= n;
}
break;
}
}
map<int,int> m;
for(int i = 0; i < n; i++){
m[arr[i]]++;
if(m[arr[i]] == 2)return 0;
}
return 1;
}
int replacement(int n, int arr[], int res[]){
vector<pair<int,int>> v;
for(int i = 0; i < n; i++){
if(arr[i] > n)v.pb(mp(arr[i] , i));
}
int ini[n];
for(int i = 0; i < n; i++){
ini[i] = i + 1;
}
for(int i = 0; i < n; i++){
if(arr[i] <= n){
ini[i] = arr[i];
int j = i + 1;
j %= n;
int cur = 1 + arr[i] % n;
while(j != i){
ini[j] = cur;
cur = 1 + cur % n;
j++;
j %=n;
}
break;
}
}
int cur = 0;
int j = 0;
sv(v);
while(j < (int)v.size()){
while(cur + n + 1 < v[j].vf){
res[cur] = ini[v[j].vs];
ini[v[j].vs] = cur + n + 1;
cur++;
}
res[cur] = ini[v[j].vs];
ini[v[j].vs] = v[j].vf;
cur++;
j++;
}
return cur;
}
int countReplacement(int n, int arr[]){
if(valid(n , arr) == 0)return 0;
ll ans = 1;
vector<pair<ll,int>> v;
for(int i = 0; i < n; i++){
if(arr[i] > n)v.pb(mp(arr[i] , i));
}
sv(v);
ll last = n + 1;
int j = 0;
if(v.size() == n){
ans *= n;
}
while(j < (int)v.size()){
ll dif = v[j].vf - last;
ll rem = v.size() - j;
ans *= power(rem , dif);
ans %= mod;
last = v[j].vf + 1;
j++;
}
return ans;
}
Compilation message
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:109:14: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
109 | if(v.size() == n){
| ~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 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 |
# |
Verdict |
Execution time |
Memory |
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 |
2208 KB |
Output is correct |
7 |
Correct |
9 ms |
612 KB |
Output is correct |
8 |
Correct |
21 ms |
3808 KB |
Output is correct |
9 |
Correct |
6 ms |
1356 KB |
Output is correct |
10 |
Correct |
27 ms |
4420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
11 ms |
2160 KB |
Output is correct |
7 |
Correct |
8 ms |
588 KB |
Output is correct |
8 |
Correct |
23 ms |
3884 KB |
Output is correct |
9 |
Correct |
8 ms |
1356 KB |
Output is correct |
10 |
Correct |
32 ms |
4472 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
3 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
7 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 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 |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 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 |
1 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 |
9 ms |
972 KB |
Output is correct |
13 |
Correct |
12 ms |
1336 KB |
Output is correct |
14 |
Correct |
8 ms |
844 KB |
Output is correct |
15 |
Correct |
18 ms |
2244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
292 KB |
Output is correct |
4 |
Correct |
1 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 |
38 ms |
3980 KB |
Output is correct |
10 |
Correct |
31 ms |
4032 KB |
Output is correct |
11 |
Correct |
11 ms |
1720 KB |
Output is correct |
12 |
Correct |
15 ms |
2064 KB |
Output is correct |
13 |
Correct |
3 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
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 |
38 ms |
3940 KB |
Output is correct |
10 |
Correct |
35 ms |
4116 KB |
Output is correct |
11 |
Correct |
12 ms |
1684 KB |
Output is correct |
12 |
Correct |
14 ms |
2064 KB |
Output is correct |
13 |
Correct |
3 ms |
716 KB |
Output is correct |
14 |
Correct |
49 ms |
6596 KB |
Output is correct |
15 |
Correct |
55 ms |
7468 KB |
Output is correct |
16 |
Correct |
9 ms |
1612 KB |
Output is correct |
17 |
Correct |
41 ms |
5164 KB |
Output is correct |
18 |
Correct |
24 ms |
3484 KB |
Output is correct |