이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "gondola.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
int valid(int n, int inputSeq[])
{
int pos = -1;
for(int i = 0; i < n; i++){
if(inputSeq[i] == 1){
pos = i;
break;
}
}
bool seq = true;
int at = 1, lim = pos;
while(pos < n){
if(inputSeq[pos] == at){
pos++;
at++;
}
else{
seq = false;
break;
}
}
if(!seq) return 0;
pos = 0;
while(pos < lim){
if(inputSeq[pos] == at){
pos++;
at++;
}
else{
seq = false;
break;
}
}
if(!seq) return 0;
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
int pos = -1;
for(int i = 0; i < n; i++){
if(gondolaSeq[i] >= 1 && gondolaSeq[i] <= n){
pos = i;
break;
}
}
if(pos == -1){
vi arr(n);
for(int i = 0; i < n; i++) arr[i] = gondolaSeq[i];
sort(arr.begin(), arr.end());
int at = 1, j = 0, rez =0;
for(int i = 0; i < n; i++){
while(at < arr[i]){
replacementSeq[j++] = at++;
rez++;
}
at++;
}
return rez;
}
else{
bool done[n+1];
memset(done, false, sizeof done);
vector<pii> arr;
for(int i = 0; i < n; i++){
if(gondolaSeq[i] > n){
arr.pb(mp(gondolaSeq[i], i));
}
else if(gondolaSeq[i] >= 1 && gondolaSeq[i] <= n){
done[gondolaSeq[i]] = true;
}
}
int at = gondolaSeq[pos];
while(at <= n){
at++;
pos++;
pos %= n;
}
int put = 1, rez = 0, j = 0;
int need[n];
for(int i = pos; i < n; i++) need[i] = put++;
for(int i = 0; i < pos; i++) need[i] = put++;
sort(arr.begin(), arr.end());
map<int,int> seen;
for(int i = 0; i < n; i++) seen[gondolaSeq[i]] = i;
at = n+1;
for(int i = 0; i < (int)arr.size(); i++){
int kade = arr[i].second;
while(at < gondolaSeq[kade]){
if(seen[at] != 0){
replacementSeq[j++] = need[seen[at]];
done[need[seen[at]]]= true;
at++;
rez++;
}
else{
replacementSeq[j++] = at++;
rez++;
}
}
if(at == gondolaSeq[kade] && !done[need[kade]]){
rez++;
replacementSeq[j++] = need[kade];
done[need[kade]] = true;
}
}
if(!done[need[seen[at]]]){
replacementSeq[j++] = need[seen[at]];
rez++;
}
return rez;
}
}
//----------------------
int countReplacement(int n, int inputSeq[])
{
return -3;
}
# | 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... |