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 "gondola.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 2;
int valid(int n, int inputSeq[])
{
vector <pair <int, int> > v;
for(int i = 0; i < n; i ++)
if(inputSeq[i] <= n)
v.push_back({inputSeq[i], i + 1});
sort(v.begin(), v.end());
for(int i = 1; i < v.size(); i ++){
int ab = v[i].first - v[i - 1].first, ds;
if(v[i].second > v[i - 1].second){
ds = v[i].second - v[i - 1].second;
} else {
ds = v[i].second + (n - v[i - 1].second);
}
if(ds != ab) return 0;
}
sort(inputSeq, inputSeq + n);
for(int i = 1; i < n; i ++){
if(inputSeq[i] == inputSeq[i - 1]) return 0;
}
return 1;
}
//----------------------
int used[N];
int replacement(int n, int gondolaSeq[], int rp[])
{
int pos = -1, mx = 0, sz = 0, id = 0;
vector <int> d, v, nm(n);
for(int i = 0; i < n; i ++){
mx = max(mx, gondolaSeq[i]);
used[gondolaSeq[i]] = 1;
if(gondolaSeq[i] > n)
d.push_back(i);
else
if(pos == -1) pos = gondolaSeq[i], id = i;
}
for(int i = n + 1; i <= mx; i ++){
if(!used[i])
v.push_back(i);
}
if(pos == -1){
rp[sz ++] = 1;
for(int i = 0; i < v.size(); i ++){
rp[sz ++] = v[i];
}
for(int i = 1; i < n; i ++){
rp[sz ++] = i + 1;
}
} else {
for(int i = 0; i < n; i ++){
nm[id] = pos;
pos ++;
id ++;
if(pos > n) pos = 1;
if(id >= n) id = 0;
}
for(int i = 0; i < d.size(); i ++){
int ps = nm[d[i]];
if(ps < 0 || ps > n) while(1){
}
if(!i){
rp[sz ++] = ps;
for(int j = 0; j < v.size(); j ++){
rp[sz ++] = v[j];
}
} else {
rp[sz ++] = ps;
}
}
}
return sz;
}
//----------------------
int countReplacement(int n, int inputSeq[])
{
return -3;
}
Compilation message (stderr)
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:14:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 1; i < v.size(); i ++){
~~^~~~~~~~~~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:52:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < v.size(); i ++){
~~^~~~~~~~~~
gondola.cpp:66:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < d.size(); i ++){
~~^~~~~~~~~~
gondola.cpp:73:42: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 0; j < v.size(); j ++){
~~^~~~~~~~~~
# | 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... |