//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include "gondola.h"
//#include "grader.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%I64d", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%I64d\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
const double pi = acos(-1);
const int MOD = 1e9 + 9;
const int INF = 1e9 + 7;
const int MAXN = 3e5 + 5;
const double eps = 1e-9;
int arr[MAXN], nx[MAXN];
int valid(int n, int inputSeq[]) {
int ind = n;
for (int i = 0; i < n; i++)
if (inputSeq[i] <= n) {
ind = i;
break;
}
if (ind < n)
for (int j = 0; j < n; j++)
if (inputSeq[j] <= n && (inputSeq[ind] + j) % n != (inputSeq[j] + ind) % n)
return 0;
sort(inputSeq, inputSeq + n);
for (int i = 1; i < n; i++)
if (inputSeq[i] == inputSeq[i - 1])
return 0;
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
int ind = n;
for (int i = 0; i < n; i++)
arr[gondolaSeq[i]] = i + 1;
for (int i = 0; i < n; i++)
if (gondolaSeq[i] <= n) {
ind = i;
break;
}
for (int i = 0; i < n; i++)
if (ind == n)
nx[i] = i + 1;
else
nx[i] = (gondolaSeq[ind] + i - ind + n - 1) % n + 1;
int mx = 0;
for (int i = 0; i < n; i++)
mx = max(mx, gondolaSeq[i]);
for (int i = n + 1; i <= mx; i++) {
if (arr[i] != 0) {
replacementSeq[i - n - 1] = nx[arr[i] - 1];
nx[arr[i] - 1] = i;
} else {
replacementSeq[i - n - 1] = nx[arr[mx] - 1];
nx[arr[mx] - 1] = i;
}
}
return mx - n;
}
int pw(ll a, int b) {
ll ret = 1;
while (b > 0)
if (b & 1)
ret = (ret * a) % MOD, b--;
else
a = (a * a) % MOD, b /= 2;
return (int) ret;
}
int countReplacement(int n, int inputSeq[]) {
if (!valid(n, inputSeq))
return 0;
sort(inputSeq, inputSeq + n);
ll ret = 1;
for (int i = 0; i < n; i++) {
if (inputSeq[i] <= n)
continue;
int ex = n;
if (i > 0)
ex = max(ex, inputSeq[i - 1]);
ll val = pw(n - i, inputSeq[i] - ex - 1);
ret = (ret * val) % MOD;
}
return (int) ret;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
252 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
10 ms |
640 KB |
Output is correct |
7 |
Correct |
12 ms |
1152 KB |
Output is correct |
8 |
Correct |
20 ms |
1024 KB |
Output is correct |
9 |
Correct |
7 ms |
512 KB |
Output is correct |
10 |
Correct |
18 ms |
1152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
3 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
15 ms |
640 KB |
Output is correct |
7 |
Correct |
15 ms |
1280 KB |
Output is correct |
8 |
Correct |
18 ms |
1024 KB |
Output is correct |
9 |
Correct |
6 ms |
512 KB |
Output is correct |
10 |
Correct |
17 ms |
1152 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
7 ms |
768 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
13 ms |
1280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
512 KB |
Output is correct |
11 |
Correct |
13 ms |
1792 KB |
Output is correct |
12 |
Correct |
13 ms |
1920 KB |
Output is correct |
13 |
Correct |
15 ms |
1920 KB |
Output is correct |
14 |
Correct |
12 ms |
1792 KB |
Output is correct |
15 |
Correct |
23 ms |
2808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
372 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
19 ms |
1196 KB |
Output is correct |
10 |
Correct |
19 ms |
1024 KB |
Output is correct |
11 |
Correct |
7 ms |
640 KB |
Output is correct |
12 |
Correct |
8 ms |
640 KB |
Output is correct |
13 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
18 ms |
1152 KB |
Output is correct |
10 |
Correct |
16 ms |
1024 KB |
Output is correct |
11 |
Correct |
8 ms |
512 KB |
Output is correct |
12 |
Correct |
8 ms |
640 KB |
Output is correct |
13 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |