이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "gondola.h"
#define maxn 100003
#define maxv 250001
using namespace std;
int idx[maxn];
int init[maxn];
void calcInit(int n, int inputSeq[], int minIdx) {
if(minIdx == -1)
for( int i = 0 ; i < n ; i++ )
init[i] = i+1;
else
for( int i = 0 ; i < n ; i++ ) {
int d = (i-minIdx+n) % n;
init[i] = inputSeq[minIdx]+d;
}
}
int valid(int n, int inputSeq[]) {
int minIdx = -1;
set<int> s;
for( int i = 0 ; i < n ; i++ ) {
if(s.find(inputSeq[i]) != s.end())
return 0;
s.insert(inputSeq[i]);
if(inputSeq[i] <= n) {
if(minIdx == -1 || inputSeq[i] < inputSeq[minIdx])
minIdx = i;
}
}
calcInit(n,inputSeq,minIdx);
if(minIdx == -1)
return 1;
for( int i = 0 ; i < n ; i++ )
if(inputSeq[i] <= n) {
if(init[i] != inputSeq[i])
return 0;
}
return 1;
}
int replacement(int n, int inputSeq[], int replacementSeq[]) {
if(!valid(n,inputSeq))
return 0;
int maxIdx = -1;
memset(idx,-1,sizeof(idx));
for( int i = 0 ; i < n ; i++ ) {
idx[inputSeq[i]] = i;
if(maxIdx == -1 || inputSeq[i] > inputSeq[maxIdx])
maxIdx = i;
}
int cnt = 0;
int curr = init[maxIdx];
int maxVal = inputSeq[maxIdx];
for( int i = n+1 ; i <= maxVal ; i++ ) {
if(idx[i] == -1)
replacementSeq[cnt++] = curr++;
else
replacementSeq[cnt++] = init[idx[i]];
}
return cnt;
}
int countReplacement(int n, int inputSeq[]) {
if(!valid(n,inputSeq))
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:69:1: warning: control reaches end of non-void function [-Wreturn-type]
69 | }
| ^
# | 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... |