# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
389367 | Pichon5 | Gondola (IOI14_gondola) | C++17 | 49 ms | 4748 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>
#define vi vector<int>
#define pb push_back
#define F first
#define S second
#define ll long long int
#pragma GCC optimize("O3")
using namespace std;
const ll M=1e9+7;
int valid(int n, int inputSeq[]){
set<int> seen;
for(int i = 0; i < n; i++){
if(seen.count(inputSeq[i])) return 0;
seen.insert(inputSeq[i]);
}
int pos = -1, st;
for(int i = 0; i < n; i++) if(inputSeq[i] <= n) pos = i, st = inputSeq[i];
if(pos == -1) return 1;
for(int j = 0; j < n; j++, pos++, pos %= n){
if(inputSeq[pos] > n) continue;
if(inputSeq[pos] != (st+j-1)%n+1) return 0;
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
int l = 0, last = n, pos = -1, st;
vector< pair<int, int> > q;
vector<int> p(n);
for(int i = 0; i < n; i++) if(gondolaSeq[i] <= n) pos = i, st = gondolaSeq[i];
if(pos == -1) for(int i = 0; i < n; i++) p[i] = i+1;
else for(int i = 0; i < n; i++, pos++, pos %= n) p[pos] = (st+i-1)%n+1;
for(int i = 0; i < n; i++) if(gondolaSeq[i] > n) q.push_back({gondolaSeq[i], i});
if(q.empty()) return 0;
sort(q.begin(), q.end());
for(auto &t : q){
replacementSeq[l++] = p[t.second];
last++;
while(last != t.first) replacementSeq[l++] = last++;
}
return l;
}
//----------------------
int countReplacement(int n, int inputSeq[]){
if(!valid(n, inputSeq)) return 0;
vector<int> a(250001);
ll s = 1, m = n;
for(int i = 0; i < n; i++) a[inputSeq[i]]++;
for(int i = 249999; i > n; i--) a[i] += a[i+1];
for(int i = n+1; i < 250000; i++){
if(!a[i]) break;
if(a[i] == a[i+1]) s *= a[i], s %= M;
}
for(int i = 0; i < n; i++) if(inputSeq[i] <= n) m = 1;
s *= m, s %= M;
return s;
}
//number of subtask
//n
//3 1 4
//5 1 2 3 4
//2 3 4 9 6 7 1
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... |