#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;
int valid(int n, int inputSeq[]){
vector<int> a;
int mn = 1e6;
set<int> val;
for (int i = 0; i < n; i++){
mn = min(mn, inputSeq[i]);
val.insert(inputSeq[i]);
}
for (int i = 0; i < n; i++){
if (inputSeq[i] == mn) a.push_back(mn);
else if (!a.empty()){
a.push_back(inputSeq[i]);
}
}
for (int i = 0; i < n; i++){
if (inputSeq[i] == mn) break;
a.push_back(inputSeq[i]);
}
int cnt = a[0];
int f = 1;
for (int i = 0; i < n; i++){
if (cnt == a[i] || a[i] >= n + 1) {
cnt++;
continue;
}
f = 0;
}
if ((int)(val.size()) != n) f = 0;
return f;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
vector<int> a;
int mn = 1e6;
for (int i = 0; i < n; i++){
mn = min(mn, gondolaSeq[i]);
}
for (int i = 0; i < n; i++){
if (gondolaSeq[i] == mn) a.push_back(mn);
else if (!a.empty()){
a.push_back(gondolaSeq[i]);
}
}
for (int i = 0; i < n; i++){
if (gondolaSeq[i] == mn) break;
a.push_back(gondolaSeq[i]);
}
int cnt = a[0];
if (a[0] >= n + 1) cnt = 1;
set<pair<int, int>> repla;
for (int i = 0; i < n; i++){
if (cnt == n + 1) cnt = 1;
if (cnt == a[i]) {
cnt++;
continue;
}else{
repla.insert({a[i], cnt});
cnt++;
}
}
int l = 0;
int cur = n + 1;
for (auto x : repla){
//cout << x.first << ' ' << x.second << endl;
replacementSeq[l] = x.second;
l++;
while(cur < x.first){
replacementSeq[l] = cur;
l++;
cur++;
}
cur++;
}
return l;
}
const long long MOD = 1e9 + 9;
long long binpow(long long a, long long b){
if(!b) return 1;
else if(b % 2 == 0){
long long x = binpow(a, b / 2);
return (x * x) % MOD;
}else{
long long x = binpow(a, b / 2);
x = (x * x) % MOD;
return (x * a) % MOD;
}
}
int countReplacement(int n, int inputSeq[]){
vector<long long> a;
int mn = 1e9;
for (int i = 0; i < n; i++){
mn = min(mn, inputSeq[i]);
}
for (int i = 0; i < n; i++){
if (inputSeq[i] == mn) a.push_back(mn);
else if (!a.empty()){
a.push_back(inputSeq[i]);
}
}
for (int i = 0; i < n; i++){
if (inputSeq[i] == mn) break;
a.push_back(inputSeq[i]);
}
long long cnt = a[0];
long long ans = 1;
if (a[0] >= n + 1) {
cnt = 1;
ans *= n;
}
if (valid(n, inputSeq) == 0){
return 0;
}
set<pair<long long, long long>> repla;
for (int i = 0; i < n; i++){
if (cnt == n + 1) cnt = 1;
if (cnt == a[i]) {
cnt++;
continue;
}else{
repla.insert({a[i], cnt});
cnt++;
}
}
long long tama = repla.size();
long long cur = n + 1;
tama %= MOD;
for (auto x : repla){
long long d = x.first - cur;
ans *= (binpow(tama, d) % MOD);
ans %= MOD;
cur = x.first + 1;
tama--;
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
8 ms |
2908 KB |
Output is correct |
7 |
Correct |
21 ms |
4940 KB |
Output is correct |
8 |
Correct |
14 ms |
5036 KB |
Output is correct |
9 |
Correct |
6 ms |
1884 KB |
Output is correct |
10 |
Correct |
18 ms |
5596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
8 ms |
2908 KB |
Output is correct |
7 |
Correct |
22 ms |
4828 KB |
Output is correct |
8 |
Correct |
14 ms |
5076 KB |
Output is correct |
9 |
Correct |
5 ms |
1884 KB |
Output is correct |
10 |
Correct |
18 ms |
5620 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
10 ms |
2652 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
28 ms |
5840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
444 KB |
Output is correct |
5 |
Correct |
0 ms |
436 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
5 ms |
1752 KB |
Output is correct |
12 |
Correct |
7 ms |
1748 KB |
Output is correct |
13 |
Correct |
14 ms |
2896 KB |
Output is correct |
14 |
Correct |
6 ms |
1752 KB |
Output is correct |
15 |
Correct |
15 ms |
3096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
41 ms |
5840 KB |
Output is correct |
10 |
Correct |
31 ms |
4820 KB |
Output is correct |
11 |
Correct |
12 ms |
2176 KB |
Output is correct |
12 |
Correct |
15 ms |
2408 KB |
Output is correct |
13 |
Correct |
3 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
352 KB |
Output is correct |
6 |
Correct |
0 ms |
352 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
38 ms |
5912 KB |
Output is correct |
10 |
Correct |
29 ms |
4820 KB |
Output is correct |
11 |
Correct |
12 ms |
2176 KB |
Output is correct |
12 |
Correct |
14 ms |
2364 KB |
Output is correct |
13 |
Correct |
3 ms |
968 KB |
Output is correct |
14 |
Correct |
60 ms |
7316 KB |
Output is correct |
15 |
Correct |
61 ms |
8148 KB |
Output is correct |
16 |
Correct |
9 ms |
1752 KB |
Output is correct |
17 |
Correct |
39 ms |
5560 KB |
Output is correct |
18 |
Correct |
20 ms |
3284 KB |
Output is correct |