이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
#include "gondola.h"
using namespace std;
int valid(int n, int inputSeq[]) {
int minpos = 0;
bool isUnbroken = false;
for(int i = 0;i < n;i++) {
if(inputSeq[i] <= n) {
isUnbroken = true;
if(inputSeq[minpos] > inputSeq[i]) {
minpos = i;
}
}
}
if(isUnbroken) {
for(int i = 0;i < n;i++) {
if(inputSeq[i] <= n) {
int distPos = (n + i - minpos) % n;
int distVal = inputSeq[i] - inputSeq[minpos];
if(distPos != distVal) {
return 0;
}
}
}
}
return 1;
}
int const NMAX = 1e5;
int const MMAX = 250000;
int arr[1 + NMAX];
int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
bool unmarked[1 + NMAX];
int pos[1 + MMAX];
int maxx = 0, minpos = 0;
bool isUnbroken = false;
for(int i = 1;i <= MMAX;i++) {
pos[i] = -1;
}
for(int i = 0;i < n;i++) {
if(gondolaSeq[i] <= n) {
unmarked[i] = false;
isUnbroken = true;
if(gondolaSeq[minpos] > gondolaSeq[i]) {
minpos = i;
}
} else {
unmarked[i] = true;
}
pos[gondolaSeq[i]] = i;
maxx = max(maxx, gondolaSeq[i]);
}
if(isUnbroken) {
for(int i = 0;i < n;i++) {
int dist = (n + i - minpos);
int val = (gondolaSeq[minpos] + dist) % n;
if(val == 0) {
val = n;
}
arr[i] = val;
}
}else {
for(int i = 0;i < n;i++) {
arr[i] = i + 1;
}
}
int dump = 0, index = 0;
for(int i = n+1;i <= maxx;i++) {
if(pos[i] == -1) {
while(unmarked[dump]) {
dump++;
}
replacementSeq[index] = arr[dump];
arr[dump] = i;
index++;
}else {
replacementSeq[index] = arr[pos[i]];
arr[pos[i]] = i;
index++;
}
}
return index;
}
int const MODULO = 1e9+9;
int logPow(int a, int b) {
if(b == 0) {
return 1;
} else if(b == 1) {
return a;
} else {
int mult = logPow(a, b/2);
mult = (1LL * mult * mult) % MODULO;
if(b % 2 == 1) {
return (1LL * mult * a) % MODULO;
} else {
return mult;
}
}
}
int countReplacement(int n, int inputSeq[]) {
if(!valid(n, inputSeq)) {
//cerr << "SUDOKU\n";
return 0;
}
vector <int> toMark;
int unmarked = n;
bool isUnbroken = false;
for(int i = 0;i < n;i++) {
if(inputSeq[i] <= n) {
unmarked--;
isUnbroken = true;
} else {
toMark.push_back(inputSeq[i]);
}
}
sort(toMark.begin(), toMark.end());
int prev = n, ans = 1;
for(int i = 0;i < toMark.size();i++) {
int dist = (toMark[i] - prev - 1);
//cerr << unmarked << ' ' << logPow(unmarked, dist) << '\n';
ans = (1LL * ans * logPow(unmarked, dist)) % MODULO;
unmarked--;
prev = toMark[i];
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:128:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
128 | for(int i = 0;i < toMark.size();i++) {
| ~~^~~~~~~~~~~~~~~
gondola.cpp:116:8: warning: variable 'isUnbroken' set but not used [-Wunused-but-set-variable]
116 | bool isUnbroken = false;
| ^~~~~~~~~~
# | 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... |