#include "gondola.h"
#include <bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define em emplace
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
const int MAX = 101010;
const int INF = INT_MAX >> 1;
const ll LINF = LLONG_MAX >> 1;
const ll mod = 1e9+9;
int valid(int n, int arr[]) {
vector <bool> chk(250050);
int idx = -1;
for(int i = 0; i < n; i++) {
if(arr[i] <= n && idx == -1) {
idx = i;
}
else if(arr[i] <= n) {
int temp = arr[idx] + i - idx;
temp %= n;
if(temp == 0) temp = n;
if(temp != arr[i]) return 0;
}
}
sort(arr, arr+n);
for(int i = 1; i < n; i++) {
if(arr[i] == arr[i-1]) return 0;
}
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
int l = 0;
vector <int> ori(n, -1);
for(int i = 0; i < n; i++) {
l = max(gondolaSeq[i] - n, l);
if(gondolaSeq[i] <= n && ori[0] == -1) {
ori[i] = gondolaSeq[i];
for(int j = 1; j < n; j++) {
ori[(i+j)%n] = (ori[i] + j) % n;
if(ori[(i+j)%n] == 0) ori[(i+j)%n] = n;
}
}
}
if(ori[0] == -1) {
for(int i = 0; i < n; i++) ori[i] = i + 1;
}
vector <pii> temp;
for(int i = 0; i < n; i++) {
temp.eb(gondolaSeq[i], i);
}
sort(all(temp));
int idx = 0, last = n + 1;
for(int i = 0; i < n; i++) {
if(temp[i].fi > n) {
replacementSeq[idx++] = ori[temp[i].se];
while(last < temp[i].fi) {
replacementSeq[idx++] = last++;
}
last++;
}
}
return l;
}
ll mypow(ll a, ll b) {
ll ret = 1;
while(b) {
if(b & 1) ret = (ret * a) % mod;
b >>= 1;
a = (a * a) % mod;
}
return ret;
}
int countReplacement(int n, int inputSeq[]) {
if(!valid(n, inputSeq)) return 0;
ll ans = n;
for(int i = 0; i < n; i++) {
if(inputSeq[i] <= n) ans = 1;
}
sort(inputSeq, inputSeq+n);
int last = n;
for(int i = 0; i < n; i++) {
if(inputSeq[i] > n) {
ans = (ans * mypow(n - i, inputSeq[i] - last - 1)) % mod;
last = inputSeq[i];
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
10 ms |
632 KB |
Output is correct |
7 |
Correct |
14 ms |
888 KB |
Output is correct |
8 |
Correct |
14 ms |
760 KB |
Output is correct |
9 |
Correct |
7 ms |
504 KB |
Output is correct |
10 |
Correct |
19 ms |
764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
10 ms |
632 KB |
Output is correct |
7 |
Correct |
14 ms |
760 KB |
Output is correct |
8 |
Correct |
14 ms |
764 KB |
Output is correct |
9 |
Correct |
7 ms |
504 KB |
Output is correct |
10 |
Correct |
20 ms |
888 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
7 ms |
632 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
13 ms |
760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
368 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
3 ms |
380 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
18 ms |
2288 KB |
Output is correct |
12 |
Correct |
19 ms |
2288 KB |
Output is correct |
13 |
Correct |
18 ms |
1528 KB |
Output is correct |
14 |
Correct |
16 ms |
2160 KB |
Output is correct |
15 |
Correct |
24 ms |
2404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
632 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
380 KB |
Output is correct |
8 |
Correct |
2 ms |
508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
380 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
22 ms |
1144 KB |
Output is correct |
10 |
Correct |
17 ms |
1016 KB |
Output is correct |
11 |
Correct |
8 ms |
632 KB |
Output is correct |
12 |
Correct |
9 ms |
632 KB |
Output is correct |
13 |
Correct |
4 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
380 KB |
Output is correct |
9 |
Correct |
21 ms |
1164 KB |
Output is correct |
10 |
Correct |
17 ms |
1016 KB |
Output is correct |
11 |
Correct |
8 ms |
632 KB |
Output is correct |
12 |
Correct |
9 ms |
632 KB |
Output is correct |
13 |
Correct |
4 ms |
380 KB |
Output is correct |
14 |
Correct |
25 ms |
1528 KB |
Output is correct |
15 |
Correct |
29 ms |
1656 KB |
Output is correct |
16 |
Correct |
7 ms |
632 KB |
Output is correct |
17 |
Correct |
21 ms |
1276 KB |
Output is correct |
18 |
Correct |
12 ms |
888 KB |
Output is correct |