# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
706469 | Hacv16 | Gondola (IOI14_gondola) | C++17 | 65 ms | 5976 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 <bits/stdc++.h>
#include "gondola.h"
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 9;
const int INF = 0x3f3f3f3f;
ll fexp(ll b, ll e){
if(e == 0) return 1;
if(e % 2 == 0) return fexp((b * b) % MOD, e >> 1);
return (b * fexp(b, e - 1)) % MOD;
}
int valid(int n, int v[]){
set<int> s(v, v + n);
if((int) s.size() != n) return 0;
for(int i = 0; i < n; i++){
if(v[i] > n) continue;
int left = (v[i] == 1 ? n : v[i] - 1), right = (v[i] == n ? 1 : v[i] + 1);
int lefViz = (i == 0 ? v[n - 1] : v[i - 1]);
int rigViz = (i == n - 1 ? v[0] : v[i + 1]);
if((lefViz != left && lefViz <= n) || (rigViz != right && rigViz <= n)) return 0;
}
return 1;
}
int countReplacement(int n, int v[]){
if(!valid(n, v)) return 0;
set<ll> s;
for(int i = 0; i < n; i++)
if(v[i] > n) s.insert(v[i]);
ll ans = 1, cnt = s.size(), cur = n + 1;
for(auto x : s){
ll exp = x - cur;
ans = (ans * fexp(cnt, exp)) % MOD;
ans %= MOD; cur = x + 1; cnt--;
}
if(s.size() == n) ans = (n * ans) % MOD;
return (int) ans;
}
int replacement(int n, int v[], int answer[]){
vector<int> order(n);
vector<pair<int, int>> aux;
int mn = INF, mnidx = 0;
for(int i = 0; i < n; i++)
if(v[i] < mn){ mn = v[i]; mnidx = i; }
if(mn > n) mnidx = 0, mn = 1;
for(int i = 0; i < n; i++){
order[(i + mnidx) % n] = mn;
mn = (mn == n ? 1 : mn + 1);
}
for(int i = 0; i < n; i++)
if(v[i] > n) aux.push_back({v[i], order[i]});
sort(aux.begin(), aux.end());
int numOp = 0;
for(int i = 0, val = n; i < aux.size(); i++){
answer[numOp++] = aux[i].second; val++;
while(val < aux[i].first)
answer[numOp++] = val++;
}
return numOp;
}
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... |