# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
500764 | InternetPerson10 | Gondola (IOI14_gondola) | C++17 | 1064 ms | 2704 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;
typedef long long ll;
const ll MOD = 1000000009;
int valid(int n, int inputSeq[]) {
vector<int> nums(n);
for(int i = 0; i < n; i++) {
nums[i] = inputSeq[i];
}
sort(nums.begin(), nums.end());
int mi = nums[n-1];
for(int i = 0; i < n-1; i++) {
if(nums[i] == nums[i+1]) return 0;
mi = min(mi, nums[i]);
}
if(mi > n) return 1;
int k = 0;
for(int i = 0; i < n; i++) {
if(mi == inputSeq[i]) k = i;
}
k -= mi;
k += (n+1);
k %= n;
for(int i = 0; i < n; i++) {
nums[i] = inputSeq[(k+i)%n];
}
for(int i = 0; i < n; i++) {
if(nums[i] <= n && nums[i] != i+1) return 0;
}
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
vector<int> nums(n);
int mi = MOD;
for(int i = 0; i < n; i++) nums[i] = gondolaSeq[i];
for(int i = 0; i < n; i++) {
mi = min(mi, nums[i]);
}
ll k = 0;
for(int i = 0; i < n; i++) {
if(mi == gondolaSeq[i]) k = i;
}
k -= mi;
k += (n+1);
k += (ll)(mi) * (ll)(n);
k %= n;
for(int i = 0; i < n; i++) {
nums[i] = gondolaSeq[(k+i)%n];
}
vector<pair<int, int>> v;
for(int i = 0; i < n; i++) {
v.push_back({nums[i], i+1});
}
sort(v.begin(), v.end());
int g = 0;
for(int i = 0; i < v.size(); i++) {
while(v[i].second != v[i].first) {
replacementSeq[g] = v[i].second;
v[i].second = g+n+1;
g++;
}
}
return g;
}
int countReplacement(int n, int inputSeq[]) {
if(!valid(n, inputSeq)) return 0;
vector<int> nums(n);
int mi = MOD;
for(int i = 0; i < n; i++) nums[i] = inputSeq[i];
for(int i = 0; i < n; i++) {
mi = min(mi, nums[i]);
}
ll k = 0;
for(int i = 0; i < n; i++) {
if(mi == inputSeq[i]) k = i;
}
k -= mi;
k += (n+1);
k += (ll)(mi) * (ll)(n);
k %= n;
for(int i = 0; i < n; i++) {
nums[i] = inputSeq[(k+i)%n];
}
vector<pair<int, int>> v;
for(int i = 0; i < n; i++) {
v.push_back({nums[i], i+1});
}
sort(v.begin(), v.end());
ll ans = 1;
if(mi > n) ans = n;
int g = 0;
for(int i = 0; i < v.size(); i++) {
while(v[i].second != v[i].first) {
v[i].second = g+n+1;
g++;
if(v[i].second != v[i].first) ans *= (v.size() - i);
ans %= 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... |