이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "gondola.h"
#include <bits/stdc++.h>
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
const int INF = 1e9 + 7, M = 1e9 + 9;
int valid(int n, int a[]) {
int he = -1;
set<int> s;
for(int i = 0; i < n; i++) {
if(s.count(a[i]))
return 0;
s.insert(a[i]);
}
for(int i = 0; i < n; i++) if(a[i] <= n) {
int be = (i - a[i] + n) % n;
if(he != -1 && he != be)
return 0;
he = be;
}
return 1;
}
int replacement(int n, int a[], int b[]) {
assert(valid(n, a));
int sz = 0, mx = 0;
map<int, int> mp;
int pos = -1;
for(int i = 0; i < n; i++) {
mx = max(mx, a[i]);
if(a[i] >= n) {
mp[a[i]] = i;
} else {
pos = i;
}
}
if(pos == -1) {
for(int i = 0; i < n; i++)
a[i] = i + 1;
} else {
for(int i = pos + 1; i < n; i++) {
a[i] = (a[pos] + i - pos + n - 1) % n + 1;
}
for(int i = 0; i < pos; i++) {
a[i] = (a[pos] + i - pos + n - 1) % n + 1;
}
}
for(int i = n + 1; i <= mx; i++) {
if(mp.count(i)) {
b[sz++] = a[mp[i]];
a[mp[i]] = i;
} else {
b[sz++] = a[mp[mx]];
a[mp[mx]] = i;
}
}
return sz;
}
int qpow(int a, int b) {
if(b == 0) return 1;
ll t = qpow(a, b / 2);
t = t * t % M;
if(b & 1) t = t * a % M;
return t;
}
int countReplacement(int n, int a[]) {
if(!valid(n, a)) return 0;
int mx = 0;
vi aux;
for(int i = 0; i < n; i++) {
mx = max(mx, a[i]);
if(a[i] > n) {
aux.PB(a[i]);
}
}
aux.PB(n);
int ans = 1, cnt = 0;
sort(ALL(aux), greater<int>());
for(int i = 0; i + 1 < SZ(aux); i++) {
ans = 1LL * ans * qpow(i + 1, aux[i] - aux[i + 1] - 1) % M;
}
if(SZ(aux) == n) ans = 1LL * ans * n % M;
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:92:18: warning: unused variable 'cnt' [-Wunused-variable]
92 | int ans = 1, cnt = 0;
| ^~~
# | 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... |