This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;
int valid(int N, int inputSeq[])
{
int ind = -1, x = -1;
for(int i = 0; i < N; i++) {
if(inputSeq[i] <= N) {
ind = i;
x = inputSeq[i];
break;
}
}
for(int i = ind + 1; i < N; i++) {
if(inputSeq[i] <= N && (x + i - ind - 1) % N + 1 != inputSeq[i])
return 0;
}
set<int> s;
for(int 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[])
{
int cont = 0;
vector<int> seq;
vector<pair<int, int>> s;
vector<int> v;
for(int i=0; i<N; i++)
if(gondolaSeq[i] <= N)
v.push_back(gondolaSeq[i]);
sort(v.begin(), v.end());
if(!v.empty()){
deque<int> q;
for(int i=0; i<N; i++) q.push_back(gondolaSeq[i]);
while(q.front() != v.front()){
q.push_front(q.back());
q.pop_back();
}
for(int 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(int i=0; i<N; i++) seq.push_back(gondolaSeq[i]);
}
for(int 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;
int nxt = N+1;
for(auto i : s){
int to = i.second;
while(nxt <= i.first){
replacementSeq[cont++] = to;
to = nxt;
nxt++;
}
}
return cont;
}
//----------------------
const int MOD = 1e9+9;
int countReplacement(int N, int gondolaSeq[])
{
if(valid(N, gondolaSeq) == 0) return 0;
int cont = 0;
vector<int> seq;
vector<int> s;
vector<int> v;
for(int i=0; i<N; i++)
if(gondolaSeq[i] <= N)
v.push_back(gondolaSeq[i]);
sort(v.begin(), v.end());
if(!v.empty()){
deque<int> q;
for(int i=0; i<N; i++) q.push_back(gondolaSeq[i]);
while(q.front() != v.front()){
q.push_front(q.back());
q.pop_back();
}
for(int 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(int i=0; i<N; i++) seq.push_back(gondolaSeq[i]);
}
for(int i=0; i<N; i++){
if(seq[i] >= N)
s.push_back(seq[i]);
}
sort(s.begin(), s.end());
if(s.empty()) return 0;
int curr = N+1, pos = 0;
int ans = 1;
while(curr < s.back()){
if(curr == s[pos]){
curr++;
pos++;
continue;
}
ans = (ans * (s.size() - pos)) % MOD;
curr++;
}
if(s.size() == N) ans = (ans * N) % MOD;
return ans;
}
Compilation message (stderr)
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:147:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(s.size() == N) ans = (ans * N) % MOD;
~~~~~~~~~^~~~
gondola.cpp:94:9: warning: unused variable 'cont' [-Wunused-variable]
int cont = 0;
^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |