#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;
int MOD = 1e9 + 7;
long long fast_power(long long base, long long power) {
long long result = 1;
while (power > 0) {
if (power % 2 == 1) {
result = (result * base) % MOD;
}
base = (base * base) % MOD;
power = power / 2;
}
return result;
}
int valid(int n, int inputSeq[]) {
bool first = false;
int fx = 0;
for (int i = 0; i < n; i++) {
int x = inputSeq[i];
if (x > n) {
fx++;
if (i) {
if (inputSeq[i - 1] == n) {
inputSeq[i] = 1;
} else {
inputSeq[i] = inputSeq[i - 1] + 1;
}
} else {
first = true;
}
}
}
if (fx == n) {
return 1;
}
if (first) {
if (inputSeq[1] == 1) {
inputSeq[0] = n;
} else {
inputSeq[0] = inputSeq[1] - 1;
}
}
for (int i = 0; i < n; i++) {
if (inputSeq[i] != 1) {
if (i) {
if (inputSeq[i] != inputSeq[i - 1] + 1) {
return 0;
}
} else {
if (inputSeq[i] != inputSeq[n - 1] + 1) {
return 0;
}
}
} else {
if (i) {
if (inputSeq[i - 1] != n) {
return 0;
}
} else {
if (inputSeq[n - 1] != n) {
return 0;
}
}
}
}
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
int ar[250005];
memset(ar, 0, sizeof ar);
int mx = 0;
for (int i = 0; i < n; i++) {
int x = gondolaSeq[i];
mx = max(mx, x);
ar[x] = 1;
}
int cnt = 0;
for (int i = 1; i <= mx; i++) {
if (ar[i] == 0) {
replacementSeq[cnt] = i;
cnt++;
}
}
return cnt;
}
int countReplacement(int n, int inputSeq[]) {
int mx = 0;
long long ret = 1;
vector<int> flex;
flex.push_back(-1);
int fx = 0;
for (int i = 0; i < n; i++) {
int x = inputSeq[i];
mx = max(mx, x);
if (x > n) {
fx++;
flex.push_back(x - n);
}
}
int val = valid(n, inputSeq);
if (val) {
if (mx == n) {
return 1;
}
} else {
return 0;
}
if (fx == n) {
return fx;
}
int mul = flex.size() -1 ;
sort(flex.begin(), flex.end());
for (int i = 1; i < flex.size(); i++) {
int x = flex[i - 1] + 1;
ret *= fast_power(mul, ((flex[i] - x) - 1));
ret %= MOD;
}
return ret % MOD;
}
Compilation message
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:119:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i < flex.size(); i++) {
~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
408 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 |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
7 ms |
768 KB |
Output is correct |
7 |
Correct |
15 ms |
1280 KB |
Output is correct |
8 |
Correct |
13 ms |
1024 KB |
Output is correct |
9 |
Correct |
6 ms |
512 KB |
Output is correct |
10 |
Correct |
14 ms |
1152 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 |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
10 ms |
640 KB |
Output is correct |
7 |
Correct |
13 ms |
1152 KB |
Output is correct |
8 |
Correct |
11 ms |
1024 KB |
Output is correct |
9 |
Correct |
5 ms |
512 KB |
Output is correct |
10 |
Correct |
10 ms |
1152 KB |
Output is correct |
11 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1280 KB |
Output is correct |
2 |
Correct |
4 ms |
1280 KB |
Output is correct |
3 |
Correct |
3 ms |
1280 KB |
Output is correct |
4 |
Correct |
3 ms |
1280 KB |
Output is correct |
5 |
Correct |
3 ms |
1280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1280 KB |
Output is correct |
2 |
Correct |
3 ms |
1280 KB |
Output is correct |
3 |
Correct |
3 ms |
1280 KB |
Output is correct |
4 |
Correct |
4 ms |
1280 KB |
Output is correct |
5 |
Correct |
3 ms |
1280 KB |
Output is correct |
6 |
Correct |
4 ms |
1280 KB |
Output is correct |
7 |
Incorrect |
4 ms |
1280 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1280 KB |
Output is correct |
2 |
Correct |
4 ms |
1280 KB |
Output is correct |
3 |
Correct |
3 ms |
1280 KB |
Output is correct |
4 |
Correct |
4 ms |
1280 KB |
Output is correct |
5 |
Correct |
4 ms |
1280 KB |
Output is correct |
6 |
Correct |
3 ms |
1280 KB |
Output is correct |
7 |
Incorrect |
3 ms |
1280 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 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 |
256 KB |
Output is correct |
5 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
3 ms |
412 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
256 KB |
Output is correct |
5 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |