답안 #775601

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
775601 2023-07-06T15:02:56 Z alvingogo 곤돌라 (IOI14_gondola) C++14
100 / 100
43 ms 6012 KB
#include "gondola.h"
#include <bits/stdc++.h>
#define fs first
#define sc second
using namespace std;

int valid(int n, int is[])
{
    set<int> s;
    int x=-1;
    for(int i=0;i<n;i++){
        if(is[i]<=n){
            x=i;
        }  
        if(s.find(is[i])!=s.end()){
            return 0;
        }
        s.insert(is[i]);
    }
    if(x==-1){
        return 1;
    }
    for(int i=x,cnt=0;cnt<n;i=(i+1)%n,cnt++){
        if(is[i]<=n && (is[i]-is[x]+n)%n!=(i-x+n)%n){
            return 0;
        }
    }
    return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
    int x=-1;
    for(int i=0;i<n;i++){
        if(gondolaSeq[i]<=n){
            x=i;
        }  
    }
    vector<pair<int,int> > g;
    if(x==-1){
        x=0;
        for(int i=0;i<n;i++){
            g.push_back({gondolaSeq[i],i+1});
        }
    }
    else{
        for(int i=x,cnt=0,z=gondolaSeq[x];cnt<n;i=(i+1)%n,cnt++,z=(z+1)%n+(n*(z==n-1))){
            if(gondolaSeq[i]>n){
                g.push_back({gondolaSeq[i],z});
            }
        }
    }
    
    sort(g.begin(),g.end());
    int nw=n+1,f=0;
    for(auto y:g){
        replacementSeq[f]=y.sc;
        f++;
        nw++;
        for(;nw<=y.fs;f++,nw++){
            replacementSeq[f]=nw-1;
        }
    }
    return f;
}

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

const int mod=1e9+9;
int mul(int x,int y){
    return 1ll*x*y%mod;
}
int po(int x,int y){
    int z=1;
    while(y){
        if(y&1){
            z=mul(z,x);
        }
        x=mul(x,x);
        y>>=1;
    }
    return z;
}
int countReplacement(int n, int is[])
{
    if(!valid(n,is)){
        return 0;
    }
    int x=-1;
    for(int i=0;i<n;i++){
        if(is[i]<=n){
            x=i;
        }  
    }
    vector<pair<int,int> > g;
    int ans=1;
    if(x==-1){
        x=0;
        for(int i=0;i<n;i++){
            g.push_back({is[i],i+1});
        }
        ans=n;
    }
    else{
        for(int i=x,cnt=0,z=is[x];cnt<n;i=(i+1)%n,cnt++,z=(z+1)%n+(n*(z==n-1))){
            if(is[i]>n){
                g.push_back({is[i],z});
            }
        }
    }
    
    sort(g.begin(),g.end());
    int p=n,q=g.size();
    for(auto h:g){
        ans=mul(ans,po(q,h.fs-p-1));
        p=h.fs;
        q--;
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 10 ms 2360 KB Output is correct
7 Correct 9 ms 1108 KB Output is correct
8 Correct 20 ms 4232 KB Output is correct
9 Correct 6 ms 1472 KB Output is correct
10 Correct 24 ms 4920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 11 ms 2324 KB Output is correct
7 Correct 6 ms 1108 KB Output is correct
8 Correct 20 ms 4256 KB Output is correct
9 Correct 7 ms 1476 KB Output is correct
10 Correct 25 ms 4924 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 12 ms 2256 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 32 ms 5168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 304 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 7 ms 1004 KB Output is correct
12 Correct 8 ms 1068 KB Output is correct
13 Correct 11 ms 1380 KB Output is correct
14 Correct 7 ms 1056 KB Output is correct
15 Correct 15 ms 2252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 304 KB Output is correct
3 Correct 0 ms 304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 304 KB Output is correct
9 Correct 33 ms 4428 KB Output is correct
10 Correct 26 ms 3720 KB Output is correct
11 Correct 12 ms 1592 KB Output is correct
12 Correct 12 ms 1840 KB Output is correct
13 Correct 3 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 32 ms 4464 KB Output is correct
10 Correct 27 ms 3776 KB Output is correct
11 Correct 9 ms 1492 KB Output is correct
12 Correct 15 ms 1868 KB Output is correct
13 Correct 3 ms 576 KB Output is correct
14 Correct 40 ms 5320 KB Output is correct
15 Correct 43 ms 6012 KB Output is correct
16 Correct 8 ms 1292 KB Output is correct
17 Correct 30 ms 4044 KB Output is correct
18 Correct 16 ms 2740 KB Output is correct