답안 #827603

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
827603 2023-08-16T15:16:54 Z bachhoangxuan 곤돌라 (IOI14_gondola) C++17
100 / 100
47 ms 6568 KB
#include "gondola.h"
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define fi first
#define se second
const int maxn = 250005;
const int mod=1e9+9;
int power(int a,int n){
    int res=1;
    while(n){
        if(n&1) res=1LL*res*a%mod;
        a=1LL*a*a%mod;n>>=1;
    }
    return res;
}

map<int,int> cnt;

int valid(int n, int p[])
{
    int del=-1;
    for(int i=0;i<n;i++){
        if(cnt[p[i]]) return 0;
        cnt[p[i]]++;
        if(p[i]<=n){
            int cur=(i-p[i]+n)%n;
            if(del==-1) del=cur;
            else if(del!=cur) return 0;
        }
    }
    return 1;
}

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

int replacement(int n, int p[], int res[])
{
    int del=0,sz=0;
    for(int i=0;i<n;i++) if(p[i]<=n) del=(i-p[i]+1+n)%n;
    deque<int> dq(n);
    for(int i=0;i<n;i++) dq[i]=p[i];
    while(del){
        del--;
        dq.push_back(dq.front());
        dq.pop_front();
    }
    vector<pii> pp;
    for(int i=0;i<n;i++) if(dq[i]>n) pp.push_back({dq[i],i});
    sort(pp.begin(),pp.end());
    int pre=n;
    for(auto &[x,id]:pp){
        res[sz++]=id+1;pre++;
        while(pre<x) res[sz++]=pre++;
    }
    return sz;
}

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

int countReplacement(int n, int p[])
{
    if(!valid(n,p)) return 0;
    vector<int> pp;
    int res=n,cnt=n;
    for(int i=0;i<n;i++){
        if(p[i]<=n) res=1,cnt--;
        else pp.push_back(p[i]);
    }
    int pre=n;
    sort(pp.begin(),pp.end());
    for(int x:pp){
        res=1LL*res*power(cnt,x-pre-1)%mod;
        pre=x;cnt--;
    }
    return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 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 304 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 2388 KB Output is correct
7 Correct 10 ms 940 KB Output is correct
8 Correct 19 ms 4184 KB Output is correct
9 Correct 6 ms 1604 KB Output is correct
10 Correct 23 ms 4736 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 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 10 ms 2388 KB Output is correct
7 Correct 7 ms 832 KB Output is correct
8 Correct 22 ms 4156 KB Output is correct
9 Correct 6 ms 1492 KB Output is correct
10 Correct 23 ms 4756 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 3 ms 596 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 7 ms 852 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 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 304 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 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 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 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 0 ms 212 KB Output is correct
7 Correct 0 ms 212 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 948 KB Output is correct
12 Correct 8 ms 980 KB Output is correct
13 Correct 11 ms 1444 KB Output is correct
14 Correct 7 ms 948 KB Output is correct
15 Correct 16 ms 2260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 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 212 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 2 ms 212 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 0 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 0 ms 304 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 34 ms 4824 KB Output is correct
10 Correct 25 ms 4180 KB Output is correct
11 Correct 10 ms 1736 KB Output is correct
12 Correct 13 ms 2012 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 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 312 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 33 ms 4884 KB Output is correct
10 Correct 27 ms 4048 KB Output is correct
11 Correct 11 ms 1812 KB Output is correct
12 Correct 12 ms 2108 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
14 Correct 41 ms 5900 KB Output is correct
15 Correct 47 ms 6568 KB Output is correct
16 Correct 7 ms 1520 KB Output is correct
17 Correct 36 ms 4584 KB Output is correct
18 Correct 19 ms 2796 KB Output is correct