#include <bits/stdc++.h>
#include "gondola.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ii = pair<int, int>;
#define pb push_back
#define pp pop_back
#define ff first
#define ss second
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
const int MOD = 1e9 + 9;
bitset<1000000001> vis;
int valid(int n, int arr[]) {
for(int l = 0; l < n; l++) {
if(vis[arr[l]]) return 0;
vis[arr[l]] = 1;
}
int P = -1;
for(int l = 0; l < n; l++) {
if(arr[l] > n) continue;
int K = arr[l] - l + n * 2; K %= n;
if(P == -1) P = K;
if(K != P) return 0;
}
return 1;
}
//----------------------
int replacement(int n, int arr[], int replacementSeq[]) {
ii A[n]; int l = 0;
while(l < n && arr[l] > n) l++;
if(l == n) {
for(l = 0; l < n; l++)
A[l] = {arr[l], l + 1};
}
else {
int V = arr[l];
for(int i = 0; i < n; l = (l + 1) % n, i++) {
A[l] = {arr[l], V};
V = (V % n) + 1;
}
}
sort(A, A + n); int curr = n + 1; int res = 0;
for(auto E : A) {
int U = E.ff, V = E.ss;
while(U != V) {
replacementSeq[res++] = V;
V = curr; curr++;
}
}
return res;
}
//----------------------
ll pw(ll A, ll B) {
if(B == 0) return 1ll;
ll res = pw(A, B / 2); res = (res * res) % MOD;
if(B & 1) res = (res * A) % MOD;
return res;
}
int countReplacement(int n, int inputSeq[]) {
if(!valid(n, inputSeq)) return 0;
vector<int> arr;
for(int l = 0; l < n; l++) {
if(inputSeq[l] <= n) continue;
arr.pb(inputSeq[l]);
}
sort(arr.begin(), arr.end());
ll res = 1, p = n;
for(int l = 0; l < arr.size(); l++) {
res = (res * pw(ll(arr.size() - l), ll(arr[l] - p - 1))) % MOD;
p = arr[l];
}
return (res * ll(arr.size() == n ? n : 1)) % MOD;
}
Compilation message
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:83:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
83 | for(int l = 0; l < arr.size(); l++) {
| ~~^~~~~~~~~~~~
gondola.cpp:87:41: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
87 | return (res * ll(arr.size() == n ? n : 1)) % MOD;
| ~~~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
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 |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
5 ms |
596 KB |
Output is correct |
7 |
Correct |
13 ms |
1128 KB |
Output is correct |
8 |
Correct |
8 ms |
980 KB |
Output is correct |
9 |
Correct |
3 ms |
496 KB |
Output is correct |
10 |
Correct |
9 ms |
1108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
4 ms |
604 KB |
Output is correct |
7 |
Correct |
9 ms |
1116 KB |
Output is correct |
8 |
Correct |
12 ms |
968 KB |
Output is correct |
9 |
Correct |
3 ms |
452 KB |
Output is correct |
10 |
Correct |
13 ms |
1088 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
308 KB |
Output is correct |
13 |
Correct |
7 ms |
724 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
9 ms |
1108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
308 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
312 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
308 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 |
312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
308 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 |
308 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 |
312 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
16 ms |
1620 KB |
Output is correct |
12 |
Correct |
11 ms |
1876 KB |
Output is correct |
13 |
Correct |
14 ms |
1572 KB |
Output is correct |
14 |
Correct |
10 ms |
1604 KB |
Output is correct |
15 |
Correct |
18 ms |
2292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
312 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
308 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 |
312 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
15 ms |
1492 KB |
Output is correct |
10 |
Correct |
13 ms |
1340 KB |
Output is correct |
11 |
Correct |
6 ms |
708 KB |
Output is correct |
12 |
Correct |
6 ms |
816 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
16 ms |
1380 KB |
Output is correct |
10 |
Correct |
11 ms |
1256 KB |
Output is correct |
11 |
Correct |
7 ms |
708 KB |
Output is correct |
12 |
Correct |
6 ms |
812 KB |
Output is correct |
13 |
Correct |
2 ms |
360 KB |
Output is correct |
14 |
Correct |
24 ms |
2128 KB |
Output is correct |
15 |
Correct |
20 ms |
2384 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
14 ms |
1600 KB |
Output is correct |
18 |
Correct |
8 ms |
1236 KB |
Output is correct |