이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define sep ' '
#define debug(x) cerr << #x << ": " << x << endl;
#define all(x) (x).begin(), (x).end()
const int MAXN = 1e6 + 10;
typedef long long ll;
typedef pair<ll, ll> pll;
int A[MAXN];
int valid(int n, int inputSeq[]) {
int s = -1;
set<int> tst;
for (int i = 0; i < n; i++) inputSeq[i]--;
for (int i = 0; i < n; i++) {
if (inputSeq[i] < n)
s = i;
tst.insert(inputSeq[i]);
}
if (int(tst.size()) < n) return 0;
if (s == -1) return 1;
int shift_val = (s - inputSeq[s] + n) % n;
for (int j = 0; j < n; j++)
A[j] = inputSeq[(j + shift_val) % n];
set<int> st;
for (int i = 0; i < n; i++) {
if (A[i] < n)
if (A[i] != i) return 0;
else
A[i] = i;
st.insert(A[i]);
}
return st.size() == n;
}
//----------------------
int replacement(int n, int inputSeq[], int res[]) {
for (int i = 0; i < n; i++) inputSeq[i]--;
int s = -1;
for (int i = 0; i < n; i++) {
if (inputSeq[i] < n)
s = i;
}
int shift_val = (s == -1 ? 0 : (s - inputSeq[s] + n) % n);
for (int j = 0; j < n; j++)
A[j] = inputSeq[(j + shift_val) % n];
set<int> st;
int mx = *max_element(A, A + n);
for (int i = 0; i <= mx; i++)
st.insert(i);
for (int i = 0; i < n; i++)
st.erase(A[i]);
set<pll> gond;
for (int i = 0; i < n; i++)
gond.insert({A[i], i});
int m = 0;
while (gond.rbegin() -> X >= n) {
auto [x, ind] = *prev(gond.end());
gond.erase(prev(gond.end()));
if (st.find(x - 1) != st.end()) {
A[ind] = x - 1;
st.erase(x - 1);
res[m++] = x - 1;
} else {
A[ind] = ind;
st.erase(ind);
res[m++] = ind;
}
gond.insert({A[ind], ind});
}
reverse(res, res + m);
for (int i = 0; i < m; i++)
res[i]++;
return m;
}
//----------------------
const ll MOD = 1e9 + 9;
inline ll poww(ll a, ll b) {
ll ans = 1;
while (b) {
if (b & 1) ans = ans * a % MOD;
b >>= 1;
a = a * a % MOD;
}
return ans;
}
int countReplacement(int n, int inputSeq[]) {
if (!valid(n, inputSeq)) return 0;
ll ans = n;
vector<ll> vec;
for (int i = 0; i < n; i++) {
if (inputSeq[i] > n) vec.push_back(inputSeq[i]);
else ans = 1;
}
sort(all(vec));
ll x = n + 1;
for (int i = 0; i < int(vec.size()); i++) {
ans = ans * poww(int(vec.size()) - i, vec[i] - x) % MOD;
x = vec[i] + 1;
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:39:6: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
39 | if (A[i] < n)
| ^
gondola.cpp:47:19: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
47 | return st.size() == n;
| ~~~~~~~~~~^~~~
# | 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... |