답안 #1032896

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1032896 2024-07-24T10:31:04 Z vjudge1 곤돌라 (IOI14_gondola) C++17
75 / 100
29 ms 5736 KB
#include "gondola.h"

#include<bits/stdc++.h>
using namespace std;

int valid(int n, int inputSeq[])
{
    int ind[n+1];
    for(int i=0;i<=n;i++)ind[i]=-1;
    unordered_set<int>seen;
    for(int i=0;i<n;i++){
        if(seen.count(inputSeq[i]))return 0;
        seen.insert(inputSeq[i]);
        if(inputSeq[i]<=n){
            ind[inputSeq[i]]=i;
        }
    }
    int val=-1,beg;
    for(int i=1;i<=n;i++){
        if(ind[i]!=-1){
            val=i;
            beg=ind[i];
            break;
        }
    }
    if(val==-1)return 1;
    for(int j=(beg+1)%n;j!=beg;j=(j+1)%n){
        val++;
        if(inputSeq[j]==val)continue;
        if(inputSeq[j]<=n)return 0;
    }
    return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
    int*a=gondolaSeq,*b=replacementSeq;
    int ind[n+1];
    for(int i=0;i<=n;i++)ind[i]=-1;
    for(int i=0;i<n;i++){
        if(a[i]<=n){
            ind[a[i]]=i;
        }
    }
    int val=1,beg=0;
    for(int i=1;i<=n;i++){
        if(ind[i]!=-1){
            val=i;
            beg=ind[i];
            break;
        }
    }
    int begval[n];
    begval[beg]=val;
    for(int j=(beg+1)%n;j!=beg;j=(j+1)%n){
        val++;
        if(n<val)val-=n;
        begval[j]=val;
    }
    int place=0;
    int cur=n+1;
    int p[n];
    for(int i=0;i<n;i++){
        p[i]=i;
    }
    sort(p,p+n,[&](int i,int j)->bool {
        return a[i]<a[j];
    });
    for(int i=0;i<n;i++){
        int pp=p[i];
        while(begval[pp]<a[pp]){
            b[place++]=begval[pp];
            begval[pp]=cur++;
        }
    }
    return place;
}

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

const int mod=1e9+9;

using lint=int64_t;

int mul(lint i,lint j){
    return i*j%mod;
}

int countReplacement(int n, int inputSeq[])
{
    int*a=inputSeq;
    if(!valid(n,a))return 0;
    int ind[n+1];
    for(int i=0;i<=n;i++)ind[i]=-1;
    for(int i=0;i<n;i++){
        if(a[i]<=n){
            ind[a[i]]=i;
        }
    }
    int val=1,beg=0;
    for(int i=1;i<=n;i++){
        if(ind[i]!=-1){
            val=i;
            beg=ind[i];
            break;
        }
    }
    int begval[n];
    begval[beg]=val;
    for(int j=(beg+1)%n;j!=beg;j=(j+1)%n){
        val++;
        if(n<val)val-=n;
        begval[j]=val;
    }
    int place=0;
    int cur=n+1;
    int p[n];
    for(int i=0;i<n;i++){
        p[i]=i;
    }
    sort(p,p+n,[&](int i,int j)->bool {
        return a[i]<a[j];
    });
    int ans=1;
    int haveblock=n;
    for(int i=0;i<n;i++){
        int pp=p[i];
        while(begval[pp]<a[pp]){
            begval[pp]=cur++;
            if(begval[pp]<a[pp]){
                ans=mul(ans,haveblock);
            }
        }
        haveblock--;
    }
    return ans;
}

Compilation message

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:117:9: warning: unused variable 'place' [-Wunused-variable]
  117 |     int place=0;
      |         ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 600 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 4 ms 2132 KB Output is correct
7 Correct 6 ms 1116 KB Output is correct
8 Correct 12 ms 3692 KB Output is correct
9 Correct 3 ms 1628 KB Output is correct
10 Correct 10 ms 4304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 2168 KB Output is correct
7 Correct 5 ms 1116 KB Output is correct
8 Correct 12 ms 3692 KB Output is correct
9 Correct 3 ms 1628 KB Output is correct
10 Correct 12 ms 4144 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 6 ms 2068 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 16 ms 5736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 380 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 10 ms 1628 KB Output is correct
12 Correct 9 ms 1624 KB Output is correct
13 Correct 9 ms 1628 KB Output is correct
14 Correct 7 ms 1632 KB Output is correct
15 Correct 12 ms 2444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 440 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 440 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 21 ms 4460 KB Output is correct
10 Correct 21 ms 3688 KB Output is correct
11 Correct 8 ms 1864 KB Output is correct
12 Correct 8 ms 1976 KB Output is correct
13 Incorrect 4 ms 860 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 29 ms 4344 KB Output is correct
10 Correct 17 ms 3688 KB Output is correct
11 Correct 7 ms 1884 KB Output is correct
12 Correct 7 ms 1972 KB Output is correct
13 Incorrect 3 ms 860 KB Output isn't correct
14 Halted 0 ms 0 KB -