# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
422422 | Andyvanh1 | Gondola (IOI14_gondola) | C++14 | 22 ms | 3016 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;
#define vt vector
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,x) for(int (i) = 0; (i) < (x); (i)++ )
typedef long long ll;
typedef long double ld;
typedef vt<int> vi;
typedef pair<int,int> pii;
int x[100005];
int valid(int n, int inputSeq[]){
int at = -1;
rep(i,n)x[i] = inputSeq[i];
sort(x,x+n);
for(int i = 1; i < n; i++){
if(x[i]==x[i-1])return 0;
}
for(int i = 0; i < n; i++){
if(inputSeq[i]>n){
inputSeq[i] = -1;
}else{
at = i;
}
}
if(at==-1)return 1;
bool bol = true;
for(int i = at; i < n; i++){
if(inputSeq[i]!=-1&&inputSeq[i]!=(inputSeq[at]+i-at-1)%n+1){
return 0;
}
}
for(int i = 0; i < at; i++){
if(inputSeq[i]!=-1&&inputSeq[i]!=(inputSeq[at]-at+i+n-1)%n+1){
return 0;
}
}
return 1;
}
bool taken[100005];
int cur[100005];
int matr[250010];
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
int Max = 0;
rep(i,n){
Max = max(Max,gondolaSeq[i]);
}
rep(i,Max+1){
matr[i] = -1;
}
int at = -1;
for(int i = 0; i < n; i++){
if(gondolaSeq[i]<=n){
at = i;
break;
}
}
if(at==-1){
rep(i,n){
cur[i] = i+1;
}
}else{
for(int i = 0; i < n; i++){
cur[i] = (gondolaSeq[at]-at+i+n-1)%n+1;
if(gondolaSeq[i] <= n)taken[i] = true;
}
}
for(int i = 0; i < n; i++){
matr[gondolaSeq[i]] = i;
}
for(int j = n+1; j <= Max; j++){
if(matr[j]!=-1){
replacementSeq[j-n-1] = cur[matr[j]];
cur[matr[j]] = j;
taken[matr[j]] = true;
}else{
for(int i = 0; i < n; i++){
if(taken[i]==false){
replacementSeq[j-n-1] = cur[i];
cur[i] = j;
break;
}
}
}
}
return Max-n;
}
int countReplacement(int n, int inputSeq[]){
int Max = 0;
rep(i,n){
Max = max(Max,inputSeq[i]);
}
rep(i,Max+1){
matr[i] = -1;
}
int at = -1;
for(int i = 0; i < n; i++){
if(inputSeq[i]<=n){
at = i;
break;
}
}
ll has = n;
if(at==-1){
rep(i,n){
cur[i] = i+1;
}
}else{
for(int i = 0; i < n; i++){
cur[i] = (inputSeq[at]-at+i+n-1)%n+1;
if(inputSeq[i] <= n){taken[i] = true;has--;}
}
}
for(int i = 0; i < n; i++){
matr[inputSeq[i]] = i;
}
ll ans = 1;
for(int j = n+1; j <= Max; j++){
if(matr[j]!=-1){
cur[matr[j]] = j;
taken[matr[j]] = true;
has--;
}else{
ans*=has;
ans%=1000000009;
}
}
return (at==-1? (int) (ans*n%1000000009) : (int)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... |