#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;
int valid(int n, int a[]) {
int X, idx = -1;
for(int i = 0; i < n; i++) {
if(a[i] >= 1 && a[i] <= n) {
X = a[i], idx = i;
}
}
set<int> st(a, a + n);
if(st.size() != n) return 0;
if(idx == -1) return 1;
for(int i = 0; i < n; i++) {
if(a[i] >= 1 && a[i] <= n) {
if((X + i - idx + n) % n != a[i] % n)
return 0;
}
} return 1;
}
//----------------------
int replacement(int n, int a[], int res[]) {
int l = 0, idx = -1, X;
for(int i = 0; i < n; i++) {
if(1 <= a[i] && a[i] <= n)
idx = i, X = a[i];
}
int b[n];
if(idx == -1) {
for(int i = 0; i < n; i++) b[i] = i + 1;
} else {
for(int i = 0; i < n; i++) {
b[i] = (X + i - idx + n) % n;
if(b[i] == 0) b[i] = n;
}
}
vector<pair<int, int> > v;
for(int i = 0; i < n; i++) {
if(a[i] > n) {
v.emplace_back(a[i], b[i]);
}
}
sort(v.begin(), v.end());
for(int i = 0; i < v.size(); i++) {
while(l + n < v[i].first) {
res[l++] = v[i].second;
v[i].second = l + n;
}
} return l;
}
//----------------------
const int mod = 1e9 + 7;
long long Pow(int n, int p) {
if(!p) return 1;
else if(p & 1) return n * Pow(n, p - 1) % mod;
else {
long long v = Pow(n, p / 2);
return v * v % mod;
}
}
int countReplacement(int n, int a[]) {
if(!valid(n, a)) return 0;
long long ans = 1;
vector<int> v;
for(int i = 0; i < n; i++)
if(a[i] > n) v.push_back(a[i]);
sort(v.begin(), v.end());
for(int i = 0; i < v.size(); i++) {
int rem = v.size() - i;
int tot = v[i] - (i ? v[i - 1] + 1 : n + 1);
ans *= Pow(rem, tot);
ans %= mod;
}
if(v.size() == n)
ans = ans * n % mod;
return ans;
}
Compilation message
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:13:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(st.size() != n) return 0;
~~~~~~~~~~^~~~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:47:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < v.size(); i++) {
~~^~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:75:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < v.size(); i++) {
~~^~~~~~~~~~
gondola.cpp:81:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(v.size() == n)
~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
464 KB |
Output is correct |
3 |
Correct |
3 ms |
464 KB |
Output is correct |
4 |
Correct |
2 ms |
540 KB |
Output is correct |
5 |
Correct |
3 ms |
540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
540 KB |
Output is correct |
2 |
Correct |
2 ms |
540 KB |
Output is correct |
3 |
Correct |
2 ms |
544 KB |
Output is correct |
4 |
Correct |
3 ms |
620 KB |
Output is correct |
5 |
Correct |
3 ms |
620 KB |
Output is correct |
6 |
Correct |
21 ms |
2420 KB |
Output is correct |
7 |
Correct |
72 ms |
3948 KB |
Output is correct |
8 |
Correct |
30 ms |
4204 KB |
Output is correct |
9 |
Correct |
14 ms |
4204 KB |
Output is correct |
10 |
Correct |
30 ms |
4844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4844 KB |
Output is correct |
2 |
Correct |
3 ms |
4844 KB |
Output is correct |
3 |
Correct |
2 ms |
4844 KB |
Output is correct |
4 |
Correct |
3 ms |
4844 KB |
Output is correct |
5 |
Correct |
2 ms |
4844 KB |
Output is correct |
6 |
Correct |
15 ms |
4844 KB |
Output is correct |
7 |
Correct |
73 ms |
4844 KB |
Output is correct |
8 |
Correct |
42 ms |
4844 KB |
Output is correct |
9 |
Correct |
12 ms |
4844 KB |
Output is correct |
10 |
Correct |
38 ms |
4860 KB |
Output is correct |
11 |
Correct |
3 ms |
4860 KB |
Output is correct |
12 |
Correct |
2 ms |
4860 KB |
Output is correct |
13 |
Correct |
27 ms |
4860 KB |
Output is correct |
14 |
Correct |
2 ms |
4860 KB |
Output is correct |
15 |
Correct |
105 ms |
4988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4988 KB |
Output is correct |
2 |
Correct |
2 ms |
4988 KB |
Output is correct |
3 |
Correct |
3 ms |
4988 KB |
Output is correct |
4 |
Correct |
2 ms |
4988 KB |
Output is correct |
5 |
Correct |
3 ms |
4988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4988 KB |
Output is correct |
2 |
Correct |
2 ms |
4988 KB |
Output is correct |
3 |
Correct |
3 ms |
4988 KB |
Output is correct |
4 |
Correct |
1 ms |
4988 KB |
Output is correct |
5 |
Correct |
3 ms |
4988 KB |
Output is correct |
6 |
Correct |
3 ms |
4988 KB |
Output is correct |
7 |
Correct |
3 ms |
4988 KB |
Output is correct |
8 |
Correct |
3 ms |
4988 KB |
Output is correct |
9 |
Correct |
3 ms |
4988 KB |
Output is correct |
10 |
Correct |
4 ms |
4988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4988 KB |
Output is correct |
2 |
Correct |
2 ms |
4988 KB |
Output is correct |
3 |
Correct |
2 ms |
4988 KB |
Output is correct |
4 |
Correct |
2 ms |
4988 KB |
Output is correct |
5 |
Correct |
2 ms |
4988 KB |
Output is correct |
6 |
Correct |
3 ms |
4988 KB |
Output is correct |
7 |
Correct |
2 ms |
4988 KB |
Output is correct |
8 |
Correct |
3 ms |
4988 KB |
Output is correct |
9 |
Correct |
3 ms |
4988 KB |
Output is correct |
10 |
Correct |
3 ms |
4988 KB |
Output is correct |
11 |
Correct |
20 ms |
4988 KB |
Output is correct |
12 |
Correct |
17 ms |
4988 KB |
Output is correct |
13 |
Correct |
21 ms |
4988 KB |
Output is correct |
14 |
Correct |
20 ms |
4988 KB |
Output is correct |
15 |
Correct |
30 ms |
4988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4988 KB |
Output is correct |
2 |
Correct |
3 ms |
4988 KB |
Output is correct |
3 |
Correct |
2 ms |
4988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4988 KB |
Output is correct |
2 |
Correct |
3 ms |
4988 KB |
Output is correct |
3 |
Correct |
2 ms |
4988 KB |
Output is correct |
4 |
Correct |
3 ms |
4988 KB |
Output is correct |
5 |
Correct |
3 ms |
4988 KB |
Output is correct |
6 |
Correct |
3 ms |
4988 KB |
Output is correct |
7 |
Incorrect |
3 ms |
4988 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4988 KB |
Output is correct |
2 |
Correct |
3 ms |
4988 KB |
Output is correct |
3 |
Correct |
3 ms |
4988 KB |
Output is correct |
4 |
Correct |
3 ms |
4988 KB |
Output is correct |
5 |
Correct |
3 ms |
4988 KB |
Output is correct |
6 |
Correct |
3 ms |
4988 KB |
Output is correct |
7 |
Incorrect |
2 ms |
4988 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4988 KB |
Output is correct |
2 |
Correct |
3 ms |
4988 KB |
Output is correct |
3 |
Correct |
2 ms |
4988 KB |
Output is correct |
4 |
Correct |
2 ms |
4988 KB |
Output is correct |
5 |
Correct |
2 ms |
4988 KB |
Output is correct |
6 |
Correct |
2 ms |
4988 KB |
Output is correct |
7 |
Incorrect |
3 ms |
4988 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |