#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;
typedef long long ll;
ll mod = 1000000009LL;
ll expo(ll base, ll ex){
if(ex==0LL){
return 1LL;
}
if(ex==1LL){
return base;
}
if(ex%2LL==0LL){
ll now = expo(base,ex/2LL);
now *= now;
now %= mod;
return now;
}
else{
ll now = expo(base,ex-1LL) * base;
now %= mod;
return now;
}
}
int valid(int n, int inputSeq[])
{
set<int> ss;
for(int i = 0; i<n; i++){
ss.insert(inputSeq[i]);
}
if(ss.size()!=n){
return 0;
}
pair<int, int> first;
first.first = n+1;
first.second = -1;
for(int i = 0; i<n; i++){
if(inputSeq[i]<first.first){
first.first = inputSeq[i];
first.second = i;
}
}
if(first.second==-1){
return 1;
}
int pos = first.second;
for(int i = 0; i<n; i++){
if(inputSeq[i]<=n && i!=((first.second+inputSeq[i]-first.first)%n)){
return 0;
}
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
pair<int, int> first;
first.first = n+1;
first.second = -1;
for(int i = 0; i<n; i++){
if(gondolaSeq[i]<first.first){
first.first = gondolaSeq[i];
first.second = i;
}
}
if(first.second==-1){
first.first = 1;
first.second = 0;
}
int cur[n];
for(int i = 1; i<=n; i++){
int pos = (i-first.first+first.second+n+n)%n;
cur[pos] = i;
}
vector<pair<int, int> > final;
for(int i = 0; i<n; i++){
final.push_back(make_pair(gondolaSeq[i],i));
}
sort(final.begin(),final.end());
int point = n+1;
int p = 0;
for(int i = 0; i<n; i++){
while(point<=final[i].first){
replacementSeq[p++] = cur[final[i].second];
cur[final[i].second] = point++;
}
}
return p;
}
//----------------------
int countReplacement(int n, int inputSeq[])
{
if(valid(n,inputSeq)==0){
return 0;
}
pair<int, int> first;
first.first = n+1;
first.second = -1;
for(int i = 0; i<n; i++){
if(inputSeq[i]<first.first){
first.first = inputSeq[i];
first.second = i;
}
}
bool all = false;
if(first.second==-1){
all = true;
first.first = 1;
first.second = 0;
}
vector<int> li;
for(int i = 0; i<n; i++){
li.push_back(inputSeq[i]);
}
sort(li.begin(),li.end());
ll ans = 1LL;
for(int i = 0; i<li.size(); i++){
if(li[i]<=n){
continue;
}
int bef = n;
if(i>0){
bef = max(bef,li[i-1]);
}
int bet = li[i]-bef-1;
ll here = expo(li.size()-i,bet);
ans *= here;
ans %= mod;
}
if(all){
ans *= n;
ans %= mod;
}
return ans;
}
Compilation message
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:31:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(ss.size()!=n){
~~~~~~~~~^~~
gondola.cpp:46:6: warning: unused variable 'pos' [-Wunused-variable]
int pos = first.second;
^~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:121:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i<li.size(); i++){
~^~~~~~~~~~
# |
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 |
416 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
544 KB |
Output is correct |
2 |
Correct |
2 ms |
544 KB |
Output is correct |
3 |
Correct |
2 ms |
544 KB |
Output is correct |
4 |
Correct |
2 ms |
544 KB |
Output is correct |
5 |
Correct |
2 ms |
560 KB |
Output is correct |
6 |
Correct |
15 ms |
2352 KB |
Output is correct |
7 |
Correct |
37 ms |
4016 KB |
Output is correct |
8 |
Correct |
27 ms |
4144 KB |
Output is correct |
9 |
Correct |
10 ms |
4144 KB |
Output is correct |
10 |
Correct |
37 ms |
4844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4844 KB |
Output is correct |
2 |
Correct |
2 ms |
4844 KB |
Output is correct |
3 |
Correct |
2 ms |
4844 KB |
Output is correct |
4 |
Correct |
2 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 |
37 ms |
4844 KB |
Output is correct |
8 |
Correct |
27 ms |
4844 KB |
Output is correct |
9 |
Correct |
9 ms |
4844 KB |
Output is correct |
10 |
Correct |
39 ms |
4844 KB |
Output is correct |
11 |
Correct |
2 ms |
4844 KB |
Output is correct |
12 |
Correct |
2 ms |
4844 KB |
Output is correct |
13 |
Correct |
19 ms |
4844 KB |
Output is correct |
14 |
Correct |
2 ms |
4844 KB |
Output is correct |
15 |
Correct |
45 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 |
# |
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 |
2 ms |
4988 KB |
Output is correct |
7 |
Correct |
4 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 |
2 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 |
2 ms |
4988 KB |
Output is correct |
7 |
Correct |
3 ms |
4988 KB |
Output is correct |
8 |
Correct |
2 ms |
4988 KB |
Output is correct |
9 |
Correct |
2 ms |
4988 KB |
Output is correct |
10 |
Correct |
2 ms |
4988 KB |
Output is correct |
11 |
Correct |
17 ms |
4988 KB |
Output is correct |
12 |
Correct |
22 ms |
4988 KB |
Output is correct |
13 |
Correct |
21 ms |
4988 KB |
Output is correct |
14 |
Correct |
17 ms |
4988 KB |
Output is correct |
15 |
Correct |
24 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 |
# |
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 |
2 ms |
4988 KB |
Output is correct |
7 |
Correct |
2 ms |
4988 KB |
Output is correct |
8 |
Correct |
2 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 |
2 ms |
4988 KB |
Output is correct |
7 |
Correct |
2 ms |
4988 KB |
Output is correct |
8 |
Correct |
2 ms |
4988 KB |
Output is correct |
9 |
Correct |
50 ms |
4988 KB |
Output is correct |
10 |
Correct |
43 ms |
4988 KB |
Output is correct |
11 |
Correct |
15 ms |
4988 KB |
Output is correct |
12 |
Correct |
19 ms |
4988 KB |
Output is correct |
13 |
Correct |
6 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 |
2 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 |
50 ms |
6200 KB |
Output is correct |
10 |
Correct |
40 ms |
6200 KB |
Output is correct |
11 |
Correct |
22 ms |
6200 KB |
Output is correct |
12 |
Correct |
19 ms |
6200 KB |
Output is correct |
13 |
Correct |
6 ms |
6200 KB |
Output is correct |
14 |
Correct |
65 ms |
8340 KB |
Output is correct |
15 |
Correct |
104 ms |
9800 KB |
Output is correct |
16 |
Correct |
23 ms |
9800 KB |
Output is correct |
17 |
Correct |
46 ms |
9800 KB |
Output is correct |
18 |
Correct |
38 ms |
9800 KB |
Output is correct |