# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
469598 | Soumya1 | Gondola (IOI14_gondola) | C++17 | 47 ms | 4692 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int valid(int n, int a[]) {
bool ok = true;
map<int, bool> mp;
for (int i = 0; i < n; i++) {
ok &= (!mp[a[i]]);
mp[a[i]] = true;
}
int pos = -1, val = -1;
for (int i = 0; i < n; i++) {
if (a[i] <= n) {
val = a[i];
pos = i;
break;
}
}
val++;
if (val > n) val = 1;
for (int i = pos + 1; i < n; i++) {
if (a[i] <= n) {
ok &= (a[i] == val);
}
val++;
if (val > n) val = 1;
}
for (int i = 0; i < pos; i++) {
if (a[i] <= n) {
ok &= (a[i] == val);
}
val++;
if (val > n) val = 1;
}
return (int) ok;
}
int replacement(int n, int a[], int ans[]) {
int pos = -1, val = -1;
for (int i = 0; i < n; i++) {
if (a[i] <= n) {
pos = i;
val = a[i];
break;
}
}
vector<pair<int, int>> v;
for (int i = 0; i < n; i++) {
if (a[i] > n) v.push_back({a[i], i});
}
if (pos != -1) {
for (int i = pos; i < n; i++) {
a[i] = val++;
if (val > n) val = 1;
}
for (int i = 0; i < pos; i++) {
a[i] = val++;
if (val > n) val = 1;
}
} else {
for (int i = 0; i < n; i++) a[i] = i + 1;
}
int ptr = 0;
sort(v.begin(), v.end());
int cur = n + 1;
for (int i = 0; i < v.size(); i++) {
while (cur <= v[i].first) {
ans[ptr++] = a[v[i].second];
a[v[i].second] = cur++;
}
}
return ptr;
}
int bigmod(int a, int b) {
a %= mod;
int res = 1;
while (b > 0) {
if (b & 1) res = (1LL * res * a) % mod;
a = (1LL * a * a) % mod, b >>= 1;
}
return res;
}
int countReplacement(int n, int a[]) {
if (!valid(n, a)) return 0;
int ans = 1;
sort(a, a + n);
int last = n;
for (int i = 0; i < n; i++) {
if (a[i] > n) {
if (i == 0) ans = (1LL * ans * n) % mod;
ans = (1LL * ans * bigmod(n - i, a[i] - last - 1)) % mod;
last = a[i];
}
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |