이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "gondola.h"
#include<bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int MOD = 1e9 + 9;
int mult(ll x, ll y) {return x * y % MOD;}
int pot(int n, int k) {
int ret = 1, pot = n;
for(;k > 0;k >>= 1, pot = mult(pot, pot))
if(k & 1) ret = mult(ret, pot);
return ret;
}
int add(int x, int y) {x += y;if(x >= MOD) x -= MOD;return x;}
int valid(int n, int A[]) {
int pos = -1;
for(int i = 0;i < n;i++) A[i]--;
set<int> s;
for(int i = 0;i < n;i++) s.insert(A[i]);
if((int)s.size() != n) return 0;
for(int i = 0;i < n;i++)
if(A[i] < n) pos = i;
if(pos == -1) return 1;
for(int i = pos;i < pos + n;i++)
if(A[i % n] < n && A[i % n] != (A[pos] + (i - pos)) % n)
return 0;
return 1;
}
int replacement(int n, int A[], int R[]) {
int maxi = 0;
for(int i = 0;i < n;i++)
maxi = max(maxi, --A[i]);
vector<int> v(maxi + 1, -1);
for(int i = 0;i < n;i++)
v[A[i]] = i;
vector<int> poc;
for(int i = 0;i < n;i++) poc.pb(i);
int pos = -1;
for(int i = 0;i < n;i++)
if(A[i] < n) pos = i;
if(pos != -1)
for(int i = pos;i < pos + n;i++)
poc[i % n] = (A[pos] + (i - pos)) % n;
pos = -1;
for(int i = 0;i < n;i++)
if(A[i] == maxi) pos = i;
int idx = 0;
for(int i = n;i <= maxi;i++) {
if(v[i] != -1)
R[idx++] = poc[v[i]] + 1;
else R[idx++] = poc[pos] + 1, poc[pos] = i;
}
return idx;
}
int countReplacement(int n, int A[]) {
if(!valid(n, A)) return 0;
int flag = 0;
for(int i = 0;i < n;i++)
if(A[i] < n) flag = 1;
vector<int> v;
for(int i = 0;i < n;i++)
if(A[i] >= n) v.pb(A[i]);
sort(all(v));
int ans = 1;
int lst = n - 1, cnt = (int)v.size();
for(int i : v) {
ans = mult(ans, pot(cnt, i - lst - 1));
lst = i, cnt--;
}
if(flag == 0) ans = mult(ans, n);
return ans;
}
# | 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... |