# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
469596 | Soumya1 | 곤돌라 (IOI14_gondola) | C++17 | 56 ms | 5068 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 pos = -1, val = -1;
for (int i = 0; i < n; i++) {
if (a[i] <= n) {
pos = i;
val = a[i];
break;
}
}
sort(a, a + n);
int ans = 1;
for (int i = 0; i < n; i++) {
if (a[i] > n) {
ans = (1LL * ans * bigmod(n - i, a[i] - max(a[i - 1], n) - 1)) % mod;
}
}
if (pos == -1) {
ans = (1LL * ans * n) % mod;
}
return ans;
}
Compilation message (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... |