답안 #444225

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
444225 2021-07-13T11:45:29 Z FEDIKUS 곤돌라 (IOI14_gondola) C++17
100 / 100
93 ms 10392 KB
#include "gondola.h"

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int maxn=2.5e5+10;
set<int> imam;

int valid(int n, int inputSeq[]){
    int tren=-1;
    for(int i=0;i<n;i++){
        if(imam.find(inputSeq[i])!=imam.end()) return 0;
        imam.emplace(inputSeq[i]);
        if(inputSeq[i]>n){
            if(tren!=-1) tren++;
            if(tren>n) tren=1;
            continue;
        }
        if(tren==-1) tren=inputSeq[i];
        else{
            if(inputSeq[i]!=tren) return 0;
        }
        tren++;
        if(tren>n) tren=1;
    }
    return 1;
}

//----------------------

int treba[maxn];

int replacement(int n, int gondolaSeq[], int replacementSeq[]){
    int l=0;
    int tren=-1;
    int maxi=INT_MIN;
    int mini=INT_MAX;
    for(int i=0;i<n;i++) maxi=max(maxi,gondolaSeq[i]);
    for(int i=0;i<n;i++) mini=min(mini,gondolaSeq[i]);
    int gde=-1;
    if(mini>n) tren=1;
    for(int j=0;j<2*n;j++){
        int i=j%n;
        if(gondolaSeq[i]>n){
            if(tren!=-1){
                if(gondolaSeq[i]==maxi) gde=tren;
                treba[gondolaSeq[i]]=tren;
                tren++;
                if(tren>n) tren=1;
            }
            continue;
        }
        if(tren==-1) tren=gondolaSeq[i];
        tren++;
        if(tren>n) tren=1;
    }
    for(int i=n+1;i<=maxi;i++){
        if(treba[i]!=0){
            if(i==maxi) replacementSeq[l++]=gde;
            else replacementSeq[l++]=treba[i];
        }else{
            replacementSeq[l++]=gde;
            gde=i;
        }
    }
    return l;
}

//----------------------

const int mod=1e9+9;

int mul(int a,int b){
    if(ll(a)*ll(b)>=mod) return ll(a)*ll(b)%mod;
    return a*b;
}

int pwr(int a,int b){
    int ret=1;
    while(b){
        if(b&1) ret=mul(ret,a);
        b>>=1;
        a=mul(a,a);
    }
    return ret;
}

int countReplacement(int n, int inputSeq[]){
    int res=1;
    if(!valid(n,inputSeq)) return 0;
    int mini=INT_MAX;
    for(int i=0;i<n;i++) mini=min(mini,inputSeq[i]);
    int klk=0;
    set<int> koji;
    for(int i=0;i<n;i++){
        if(inputSeq[i]>n){
            klk++;
            koji.emplace(inputSeq[i]);
        }
    }
    int prosli=n;
    for(auto i:koji){
        res=mul(res,pwr(klk,i-prosli-1));
        klk--;
        prosli=i;
    }
    if(mini>n) res=mul(res,n);
    return res;
}
/*
9
4
1 2 7 6
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 17 ms 2124 KB Output is correct
7 Correct 11 ms 588 KB Output is correct
8 Correct 31 ms 3864 KB Output is correct
9 Correct 9 ms 1356 KB Output is correct
10 Correct 35 ms 4508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 14 ms 2136 KB Output is correct
7 Correct 12 ms 588 KB Output is correct
8 Correct 30 ms 3904 KB Output is correct
9 Correct 11 ms 1368 KB Output is correct
10 Correct 35 ms 4520 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 4 ms 332 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 10 ms 608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 10 ms 588 KB Output is correct
12 Correct 17 ms 656 KB Output is correct
13 Correct 13 ms 1416 KB Output is correct
14 Correct 11 ms 588 KB Output is correct
15 Correct 28 ms 2636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 57 ms 6720 KB Output is correct
10 Correct 44 ms 5396 KB Output is correct
11 Correct 16 ms 2444 KB Output is correct
12 Correct 24 ms 2952 KB Output is correct
13 Correct 4 ms 848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 59 ms 6716 KB Output is correct
10 Correct 46 ms 5308 KB Output is correct
11 Correct 16 ms 2364 KB Output is correct
12 Correct 20 ms 2948 KB Output is correct
13 Correct 4 ms 844 KB Output is correct
14 Correct 75 ms 9360 KB Output is correct
15 Correct 93 ms 10392 KB Output is correct
16 Correct 16 ms 2160 KB Output is correct
17 Correct 53 ms 7028 KB Output is correct
18 Correct 30 ms 4152 KB Output is correct