#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
int valid(int n, int inputSeq[]) {
unordered_set<int> appeared;
int value=-1;
for (int i=0;i<n;i++){
if (appeared.find(inputSeq[i])!=appeared.end()) return 0;
appeared.insert(inputSeq[i]);
if (inputSeq[i]>n) continue;
if (value==-1) value=((inputSeq[i]-i)%n+n)%n;
if (value<0) value+=n;
else {
int curval=((inputSeq[i]-i)%n);
if (curval<0) curval+=n;
if (curval!=value) return 0;
}
}
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
int value=-1;
vector<pair<int,int> > arr;
int curnum=n+1,curpos=0;
for (int i=0;i<n;i++){
if (gondolaSeq[i]>n){
arr.push_back(make_pair(gondolaSeq[i],i));
}
else value=((gondolaSeq[i]-i)%n+n)%n;
}
sort(arr.begin(),arr.end());
for (int i=0;i<arr.size();i++){
int endd=arr[i].first;
int id=arr[i].second;
int realid;
if (value!=-1){
realid=(value+id)%n;
}
else realid=id+1;
if (realid==0) realid=n;
replacementSeq[curpos]=realid;
curpos++;
while (curnum<endd){
replacementSeq[curpos]=curnum;
curnum++;
curpos++;
}
curnum++;
}
return curpos;
}
long long m;
long long power(long long a,long long b){
long long ans=1;
a%=m;
while (b>0){
if (b%2==1) ans=(ans*a)%m;
b/=2;
a=(a*a)%m;
}
return ans;
}
int countReplacement(int n, int inputSeq[]) {
if (valid(n,inputSeq)==0) return 0;
m=1e9+9;
int value=-1;
vector<pair<int,int> > arr;
for (int i=0;i<n;i++){
if (inputSeq[i]>n){
arr.push_back(make_pair(inputSeq[i],i));
}
else value=((inputSeq[i]-i)%n+n)%n;
}
sort(arr.begin(),arr.end());
long long ans=1;
if (value==-1) ans=n;
int k=arr.size();
int prevval=n+1;
for (int i=0;i<arr.size();i++){
int curval=arr[i].first;
ans*=power(k-i,curval-prevval);
ans%=m;
prevval=curval+1;
}
return (int)ans;
}
Compilation message
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:32:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0;i<arr.size();i++){
~^~~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:80:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0;i<arr.size();i++){
~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
1 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
0 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
0 ms |
248 KB |
Output is correct |
5 |
Correct |
2 ms |
400 KB |
Output is correct |
6 |
Correct |
12 ms |
2332 KB |
Output is correct |
7 |
Correct |
14 ms |
1144 KB |
Output is correct |
8 |
Correct |
23 ms |
4104 KB |
Output is correct |
9 |
Correct |
8 ms |
1400 KB |
Output is correct |
10 |
Correct |
25 ms |
4616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
360 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
0 ms |
248 KB |
Output is correct |
6 |
Correct |
12 ms |
2216 KB |
Output is correct |
7 |
Correct |
14 ms |
1144 KB |
Output is correct |
8 |
Correct |
22 ms |
4108 KB |
Output is correct |
9 |
Correct |
8 ms |
1528 KB |
Output is correct |
10 |
Correct |
25 ms |
4612 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
248 KB |
Output is correct |
13 |
Correct |
7 ms |
632 KB |
Output is correct |
14 |
Correct |
2 ms |
424 KB |
Output is correct |
15 |
Correct |
14 ms |
1144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
0 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 |
252 KB |
Output is correct |
7 |
Correct |
2 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 |
380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
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 |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
12 ms |
1016 KB |
Output is correct |
12 |
Correct |
14 ms |
1144 KB |
Output is correct |
13 |
Correct |
18 ms |
1532 KB |
Output is correct |
14 |
Correct |
12 ms |
1128 KB |
Output is correct |
15 |
Correct |
23 ms |
2532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 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 |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
380 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 |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
44 ms |
4324 KB |
Output is correct |
10 |
Correct |
33 ms |
3880 KB |
Output is correct |
11 |
Correct |
14 ms |
1528 KB |
Output is correct |
12 |
Correct |
17 ms |
2040 KB |
Output is correct |
13 |
Correct |
5 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
404 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 |
252 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
39 ms |
4236 KB |
Output is correct |
10 |
Correct |
33 ms |
3880 KB |
Output is correct |
11 |
Correct |
14 ms |
1532 KB |
Output is correct |
12 |
Correct |
17 ms |
2040 KB |
Output is correct |
13 |
Correct |
5 ms |
760 KB |
Output is correct |
14 |
Correct |
49 ms |
4996 KB |
Output is correct |
15 |
Correct |
58 ms |
5380 KB |
Output is correct |
16 |
Correct |
11 ms |
1272 KB |
Output is correct |
17 |
Correct |
39 ms |
4104 KB |
Output is correct |
18 |
Correct |
22 ms |
2344 KB |
Output is correct |