이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
int valid(int n, int inputSeq[]){
int mni = 0;
set<int> st;
for (int i = 0; i < n; ++i){
st.insert(inputSeq[i]);
if (inputSeq[i] < inputSeq[mni]) mni = i;
}
if (st.size() < n) return 0;
if (inputSeq[mni] > n) return 1;
int k = mni - 1, x = inputSeq[mni] - 1;
while (x > 0) {
if (k == -1) k = n-1;
if (inputSeq[k] != x && inputSeq[k] <= n) return 0;
inputSeq[k] = x;
k--, x--;
}
k = mni + 1, x = inputSeq[mni] + 1;
while (x <= n){
if (k == n) k = 0;
if (inputSeq[k] != x && inputSeq[k] <= n) return 0;
inputSeq[k] = x;
k++, x++;
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
int mni = 0, mxi = 0;
for (int i = 0; i < n; ++i){
if (gondolaSeq[i] < gondolaSeq[mni]) mni = i;
if (gondolaSeq[i] > gondolaSeq[mxi]) mxi = i;
}
if (gondolaSeq[mxi] <= n) return 0;
vector<int> v(n);
if (gondolaSeq[mni] <= n){
v[mni] = gondolaSeq[mni];
int k = mni - 1, x = gondolaSeq[mni] - 1;
while (x > 0) {
if (k == -1) k = n-1;
v[k] = x;
k--, x--;
}
k = mni + 1, x = gondolaSeq[mni] + 1;
while (x <= n){
if (k == n) k = 0;
v[k] = x;
k++, x++;
}
} else{
for (int i = 0; i < n; ++i) v[i] = i+1;
}
vector<pair<int, int>> arr;
for (int i = 0; i < n; ++i) {
if (gondolaSeq[i] <= n) continue;
arr.push_back({gondolaSeq[i], i});
}
sort(arr.begin(), arr.end());
int l = 0;
for (int i = 0; i < arr.size(); ++i){
int k;
if (i == 0) k = n+1;
else k = arr[i-1].first + 1;
while (k < arr[i].first) {
replacementSeq[l] = v[mxi];
v[mxi] = k;
l++, k++;
}
replacementSeq[l] = v[arr[i].second];
v[arr[i].second] = arr[i].first;
l++;
}
return l;
}
//----------------------
int binpow(int n, int p, int m){
if (p == 0) return 1;
else if (p % 2 == 0) {
int k = binpow(n, p / 2, m);
return int(1ll * k * k) % m;
} else{
int k = binpow(n, p-1, m);
return int(1ll * k * n) % m;
}
}
int countReplacement(int n, int inputSeq[]){
const int m = 1e9 + 9;
int ans = 1;
int mni = 0;
set<int> st;
for (int i = 0; i < n; ++i){
st.insert(inputSeq[i]);
if (inputSeq[i] < inputSeq[mni]) mni = i;
}
if (st.size() < n) return 0;
if (inputSeq[mni] > n) ans *= n;
int k = mni - 1, x = inputSeq[mni] - 1;
while (x > 0 && inputSeq[mni] <= n) {
if (k == -1) k = n-1;
if (inputSeq[k] != x && inputSeq[k] <= n) return 0;
k--, x--;
}
k = mni + 1, x = inputSeq[mni] + 1;
while (x <= n && inputSeq[mni] <= n){
if (k == n) k = 0;
if (inputSeq[k] != x && inputSeq[k] <= n) return 0;
k++, x++;
}
vector<pair<int, int>> arr;
for (int i = 0; i < n; ++i) {
if (inputSeq[i] <= n) continue;
arr.push_back({inputSeq[i], i});
}
sort(arr.begin(), arr.end());
for (int i = 0; i < arr.size(); ++i){
int kk;
if (i == 0) kk = n+1;
else kk = arr[i-1].first + 1;
ans = int(1ll * ans * binpow(arr.size() - i, arr[i].first - kk, m)) % m;
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:15:19: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
15 | if (st.size() < n) return 0;
| ~~~~~~~~~~^~~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:80:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | for (int i = 0; i < arr.size(); ++i){
| ~~^~~~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:124:19: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
124 | if (st.size() < n) return 0;
| ~~~~~~~~~~^~~
gondola.cpp:147:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
147 | for (int i = 0; i < arr.size(); ++i){
| ~~^~~~~~~~~~~~
# | 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... |