이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#ifdef ONPC
#define cerr cout
#include "t_debug.cpp"
#else
#define debug(...) 42
#endif
#define allit(a) (a).begin(), (a).end()
#define sz(a) ((int) (a).size())
#define cut(s) {cout << s << '\n'; return 0;}
#include "gondola.h"
using namespace std;
using ll = long long;
using vi = vector<int>;
namespace pd = __gnu_pbds;
template<typename K> using ordered_set = pd::tree<K, pd::null_type, less<K>, pd::rb_tree_tag, pd::tree_order_statistics_node_update>;
template<typename... T> using hash_table = pd::gp_hash_table<T...>;
const int INF = 1e9;
const ll INFL = 1e18;
const int N = 250000;
const int MOD = 1e9+9;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(RANDOM);
int valid(int n, int* a_) {
vi a(n);
for (int i = 0; i < n; i++) a[i] = a_[i];
set<int> unique = set<int>(a.begin(), a.end());
if (unique.size() != a.size()) return 0;
int start = 0;
for (int i = 0; i < n; i++) {
if (a[i] <= n) {
start = i - a[i] + 1;
if (start < 0) start += n;
break;
}
}
rotate(a.begin(), a.begin()+start, a.end());
for (int i = 0; i < n; i++) {
if (a[i] <= n && a[i] != i+1) return 0;
}
return 1;
}
int replacement(int n, int a_[], int b[]) {
vi a(n), orig(n);
int mxi = 0, start = 0;
for (int i = 0; i < n; i++) {
a[i] = a_[i];
if (a[i] > a[mxi]) mxi = i;
if (a[i] <= n) start = (i-a[i]+1 + n)%n;
orig[i] = i+1;
}
rotate(orig.begin(), orig.begin()+(n-start), orig.end());
int off = (n+1);
memset(b, -1, sizeof(int) * (a[mxi] - n));
for (int i = 0; i < n; i++) {
if (a[i] != orig[i]) b[a[i]-off] = orig[i];
}
int spare = orig[mxi];
for (int i = n+1; i <= a[mxi]; i++) {
if (b[i-off] == -1) {
b[i-off] = spare;
spare = i;
}
}
b[a[mxi]-off] = spare;
return a[mxi] - n;
}
ll modpow(ll a, ll b) {
ll res = 1;
while (b) {
if (b&1) res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
int countReplacement(int n, int inputSeq[]) {
if (!valid(n, inputSeq)) return 0;
vi a(n);
for (int i = 0; i < n; i++) a[i] = inputSeq[i];
sort(a.begin(), a.end());
ll res = 1;
int i = lower_bound(a.begin(), a.end(), n+1) - a.begin();
for (; i < n; i++) {
int remain = n - i;
int len = a[i] - 1 - max(n, i?a[i-1]:0);
res = res * modpow(remain, len) % MOD;
debug(a, i, remain,len, res);
}
if (a.front() > n) res = res * n % MOD;
return res;
}
컴파일 시 표준 에러 (stderr) 메시지
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:8:24: warning: statement has no effect [-Wunused-value]
8 | #define debug(...) 42
| ^~
gondola.cpp:100:9: note: in expansion of macro 'debug'
100 | debug(a, i, remain,len, res);
| ^~~~~
# | 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... |