이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include "gondola.h"
//#include "grader.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%I64d", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%I64d\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
const double pi = acos(-1);
const int MOD = 1e9 + 9;
const int INF = 1e9 + 7;
const int MAXN = 3e5 + 5;
const double eps = 1e-9;
int arr[MAXN], nx[MAXN];
int valid(int n, int inputSeq[]) {
int ind = n;
for (int i = 0; i < n; i++)
if (inputSeq[i] <= n) {
ind = i;
break;
}
if (ind < n)
for (int j = 0; j < n; j++)
if (inputSeq[j] <= n && (inputSeq[ind] + j) % n != (inputSeq[j] + ind) % n)
return 0;
sort(inputSeq, inputSeq + n);
for (int i = 1; i < n; i++)
if (inputSeq[i] == inputSeq[i - 1])
return 0;
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
int ind = n;
for (int i = 0; i < n; i++)
arr[gondolaSeq[i]] = i + 1;
for (int i = 0; i < n; i++)
if (gondolaSeq[i] <= n) {
ind = i;
break;
}
for (int i = 0; i < n; i++)
if (ind == n)
nx[i] = i + 1;
else
nx[i] = (gondolaSeq[ind] + i - ind + n - 1) % n + 1;
int mx = 0;
for (int i = 0; i < n; i++)
mx = max(mx, gondolaSeq[i]);
for (int i = n + 1; i <= mx; i++) {
if (arr[i] != 0) {
replacementSeq[i - n - 1] = nx[arr[i] - 1];
nx[arr[i] - 1] = i;
} else {
replacementSeq[i - n - 1] = nx[arr[mx] - 1];
nx[arr[mx] - 1] = i;
}
}
return mx - n;
}
int pw(ll a, int b) {
ll ret = 1;
while (b > 0)
if (b & 1)
ret = (ret * a) % MOD, b--;
else
a = (a * a) % MOD, b /= 2;
return (int) ret;
}
int countReplacement(int n, int inputSeq[]) {
if (!valid(n, inputSeq))
return 0;
sort(inputSeq, inputSeq + n);
ll ret = 1;
for (int i = 0; i < n; i++) {
if (inputSeq[i] <= n)
continue;
int ex = n;
if (i > 0)
ex = max(ex, inputSeq[i - 1]);
ll val = pw(n - i, inputSeq[i] - ex - 1);
ret = (ret * val) % MOD;
}
if (inputSeq[0] > n)
ret = (ret * n) % MOD;
return (int) ret;
}
# | 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... |