#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;
int valid(int N, int inputSeq[])
{
long long ind = -1, x = -1;
for(long long i = 0; i < N; i++) {
if(inputSeq[i] <= N) {
ind = i;
x = inputSeq[i];
break;
}
}
for(long long i = ind + 1; i < N; i++) {
if(inputSeq[i] <= N && (x + i - ind - 1) % N + 1 != inputSeq[i])
return 0;
}
set<long long> s;
for(long long i=0; i<N; i++) s.insert(inputSeq[i]);
if(s.size() != N) return 0;
return 1;
}
//----------------------
int replacement(int N, int gondolaSeq[], int replacementSeq[])
{
long long cont = 0;
vector<long long> seq;
vector<pair<long long, long long>> s;
vector<long long> v;
for(long long i=0; i<N; i++)
if(gondolaSeq[i] <= N)
v.push_back(gondolaSeq[i]);
sort(v.begin(), v.end());
if(!v.empty()){
deque<long long> q;
for(long long i=0; i<N; i++) q.push_back(gondolaSeq[i]);
while(q.front() != v.front()){
q.push_front(q.back());
q.pop_back();
}
for(long long i=1; i<v.front(); i++){
q.push_front(q.back());
q.pop_back();
}
while(!q.empty()){
seq.push_back(q.front());
q.pop_front();
}
}
else{
for(long long i=0; i<N; i++) seq.push_back(gondolaSeq[i]);
}
for(long long i=0; i<N; i++){
if(seq[i] >= N)
s.push_back({seq[i], i+1});
}
sort(s.begin(), s.end());
if(s.empty()) return 0;
long long nxt = N+1;
for(auto i : s){
long long to = i.second;
while(nxt <= i.first){
replacementSeq[cont++] = to;
to = nxt;
nxt++;
}
}
return cont;
}
//----------------------
const long long MOD = 1e9+9;
long long power(long long b, long long e){
long long res = 1;
for(long long i=0; i<e; i++) res = (1LL * res*b)%MOD;
return res % MOD;
}
int countReplacement(int N, int gondolaSeq[])
{
if(valid(N, gondolaSeq) == 0) return 0;
long long maxi = *max_element(gondolaSeq, gondolaSeq+N);
vector<long long> v;
for(long long i=0; i<N; i++) if(gondolaSeq[i] > N) v.push_back(gondolaSeq[i]);
sort(v.begin(), v.end());
long long curr = N;
long long ans = 1;
for(long long i=0; i<v.size(); i++){
ans = (1LL * ans * (long long)power(v.size() - i, v[i] - curr - 1)) % MOD;
curr = v[i];
}
return ans;
}
Compilation message
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:23:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(s.size() != N) return 0;
~~~~~~~~~^~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:107:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(long long i=0; i<v.size(); i++){
~^~~~~~~~~
gondola.cpp:100:15: warning: unused variable 'maxi' [-Wunused-variable]
long long maxi = *max_element(gondolaSeq, gondolaSeq+N);
^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 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 |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 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 |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
15 ms |
2432 KB |
Output is correct |
7 |
Correct |
12 ms |
640 KB |
Output is correct |
8 |
Correct |
24 ms |
3968 KB |
Output is correct |
9 |
Correct |
9 ms |
1536 KB |
Output is correct |
10 |
Correct |
33 ms |
4600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
13 ms |
2176 KB |
Output is correct |
7 |
Correct |
12 ms |
768 KB |
Output is correct |
8 |
Correct |
24 ms |
3968 KB |
Output is correct |
9 |
Correct |
10 ms |
1536 KB |
Output is correct |
10 |
Correct |
30 ms |
4600 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
8 ms |
512 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
12 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 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 |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 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 |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
460 KB |
Output is correct |
11 |
Correct |
16 ms |
3444 KB |
Output is correct |
12 |
Correct |
19 ms |
3700 KB |
Output is correct |
13 |
Correct |
22 ms |
1720 KB |
Output is correct |
14 |
Correct |
15 ms |
3444 KB |
Output is correct |
15 |
Correct |
21 ms |
2380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
256 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 |
Correct |
2 ms |
256 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 |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
46 ms |
4088 KB |
Output is correct |
10 |
Correct |
41 ms |
3456 KB |
Output is correct |
11 |
Correct |
16 ms |
1408 KB |
Output is correct |
12 |
Correct |
20 ms |
1792 KB |
Output is correct |
13 |
Incorrect |
7 ms |
640 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 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 |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
3 ms |
256 KB |
Output is correct |
9 |
Correct |
54 ms |
4088 KB |
Output is correct |
10 |
Correct |
37 ms |
3448 KB |
Output is correct |
11 |
Correct |
16 ms |
1536 KB |
Output is correct |
12 |
Correct |
18 ms |
1664 KB |
Output is correct |
13 |
Incorrect |
7 ms |
640 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |