# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
250730 | ant101 | Gondola (IOI14_gondola) | C++14 | 0 ms | 0 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 <iostream>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <assert.h>
#include <limits>
#include <cstdio>
#include <complex>
#include "gondola.h"
#define optimizar_io ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
int n, t;
long long int G[100002];
set<int> vis;
int valid() {
for (int i = 1; i <= n; i++) {
if (vis.find(G[i]) != vis.end())
return 0;
vis.insert(G[i]);
}
int start = 0;
for (int i = 1; i <= n; i++) {
if (G[i] <= n) {
start = i;
break;
}
}
if (!start)
return 1;
int pos = start, next = G[start];
for (int i = 1; i <= n; i++) {
if (G[pos] <= n) {
if (G[pos] != next)
return 0;
}
pos++;
if (pos > n)
pos = 1;
next++;
if (next > n)
next = 1;
}
return 1;
}
int R, rep[250002];
pair<int, int> X[100002];
int last;
void replacement() {
int start = 1;
for (int i = 1; i <= n; i++) {
if (G[i] <= n) {
start = i;
break;
}
}
int pos = start;
int next = G[start] <= n ? G[start] : 1;
for (int i = 1; i <= n; i++) {
X[i] = make_pair(G[pos], next);
pos++;
if (pos > n)
pos = 1;
next++;
if (next > n)
next = 1;
}
sort(X + 1, X + n + 1);
last = n;
for (int i = 1; i <= n; i++) {
while(X[i].second != X[i].first) {
rep[++R] = X[i].second;
X[i].second = ++last;
}
}
}
long long int mod = 1000000009;
long long int A[100002], C;
long long int pow(long long int a, long long int x) {
if (x == 0 || a == 1)
return 1;
if (x % 2)
return (pow(a, x - 1) * a) % mod;
long long int h = pow(a, x/2);
return (h * h) % mod;
}
long long int countReplacement() {
if (!valid())
return 0;
for (int i = 1; i <= n; i++)
if (G[i] > n)
A[++C] = G[i];
sort(A + 1, A + C + 1);
long long int ret = C == n ? n : 1;
A[0] = (long long int)(n);
for (long long int i = 1; i <= C; i++ ) {
ret *= pow(C - i + 1, A[i] - A[i - 1] - 1);
ret %= mod;
}
return ret;
}