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>
#define mk make_pair
#define pb push_back
#define fr first
#define sc second
using namespace std;
const int N = 2e6 + 5;
int u[N],mx;
int id;
int mn = 1e9 + 7;
vector <pair<int,int> > v;
int valid(int n, int inputSeq[])
{
for (int i = 0; i < n; i ++) {
if (inputSeq[i] < mn)
mn = inputSeq[i],id = i;
mx = max(mx,inputSeq[i]);
}
if (mx > n)
return 0;
int o = mn;
for (int i = id - 1; i >= 0; i --) {
mn --;
if (mn == 0) mn = n;
if (inputSeq[i] > n)
continue;
if (mn != inputSeq[i])
return 0;
}
mn = o;
for (int i = id + 1; i < n; i ++) {
mn ++;
if (mn == n + 1) mn = 1;
if (inputSeq[i] > n)
continue;
if (mn != inputSeq[i])
return 0;
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
for (int i = 0; i < n; i ++) {
if (gondolaSeq[i] < mn)
mn = gondolaSeq[i],id = i;
}
if (mn > n) {
int cn = 0;
for (int i = 0; i < n; i ++)
v.pb(mk(gondolaSeq[i],++cn));
}
else {
int o = mn;
for (int i = id; i >= 0; i --) {
if (gondolaSeq[i] > n) {
v.pb(mk(gondolaSeq[i],mn));
}
mn --;
if (mn == 0)
mn = n;
}
mn = o;
for (int i = id; i < n; i ++) {
if (gondolaSeq[i] > n) {
v.pb(mk(gondolaSeq[i],mn));
}
mn ++;
if (mn == n + 1)
mn = 1;
}
}
sort (v.begin(),v.end());
int last = n + 1;
int cnt = 0;
for (auto to : v) {
replacementSeq[cnt ++] = to.sc;
for (int i = last; i < to.fr; i ++) {
replacementSeq[cnt ++] = i;
}
last = to.fr + 1;
}
return (cnt);
}
//----------------------
vector <int> vec;
int countReplacement(int n, int inputSeq[])
{
int cn = 0;
for (int i = 0; i < n; i ++) {
if (mn > inputSeq[i])
mn = inputSeq[i],id = i;
if (inputSeq[i] > n)
cn ++,vec.pb(inputSeq[i]);
}
if (cn != 2) return 1;
sort (vec.begin(),vec.end());
if (vec[0] == n + 1 && vec[1] == n + 2) {
if (n == 2)
return 4;
return 2;
}
return 1;
}
Compilation message (stderr)
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:116:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if (n == 2)
^~
gondola.cpp:118:19: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
return 2;
^~~~~~
# | 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... |