답안 #67262

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
67262 2018-08-13T18:20:49 Z theknife2001 곤돌라 (IOI14_gondola) C++17
75 / 100
24 ms 2988 KB
#include "gondola.h"
#include <bits/stdc++.h>

using namespace std;
const int N=250055;
int a[N];
int b[N];
priority_queue < int > pq;

int valid(int n, int inputSeq[])
{

    int j=0,x=1e9;
    for(int i=0;i<n;i++)
    {
        a[inputSeq[i]]++;
        if(x>inputSeq[i])
        {
            x=inputSeq[i];
            j=i;
        }
        if(a[inputSeq[i]]>1)
            return 0;
    }
    x++;
    for(int i=j+1;i<n;i++)
    {
        if(inputSeq[i]<=n)
        {
            if(inputSeq[i]==x)
            {
                x++;
                continue ;
            }
            return 0;
        }
        if(a[x]==0)
            x++;
        else
            return 0;
    }
    for(int i=0;i<j;i++)
    {
        if(inputSeq[i]<=n)
        {
            if(inputSeq[i]==x)
            {
                x++;
                continue ;
            }
            return 0;
        }
        if(a[x]==0)
            x++;
        else
            return 0;
    }
    return 1;

}



int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
    bool q=0;
    for(int i=0;i<n;i++)
    {
        a[gondolaSeq[i]]=i+1;
        if(!q&&gondolaSeq[i]<=n)
        {
            q=1;
            int x=gondolaSeq[i];
            for(int j=i;j<n;j++)
            {
                b[j]=x;
                x++;
                if(x>n)
                    x=1;
            }
            for(int j=0;j<i;j++)
            {
                b[j]=x++;
                if(x>n)
                    x=1;
            }
        }
    }
    if(!q)
        for(int i=0;i<n;i++)
            b[i]=i+1;
    int x=n+1;
    int j=0;
    for(int i=n+1;i<N;i++)
    {
        if(!a[i])
            continue ;
        a[i]--;
        while(b[a[i]]!=i)
        {
            replacementSeq[j++]=b[a[i]];
            b[a[i]]=x;
            x++;
        }
    }
    return j;
}

int m=1e9+9;


long long pow(long long x, int i)
{
    if(i%2)
        return (pow(x,i-1)*x)%m;
    if(i==0)
        return 1;
    long long y=pow(x,i/2)%m;
    return (y*y)%m;
}


int countReplacement(int n, int inputSeq[])
{
    if(!valid(n,inputSeq))
        return 0;
    bool q=0;
    memset(a,0,sizeof a);
    for(int i=0;i<n;i++)
    {
        a[inputSeq[i]]=i+1;
        if(!q&&inputSeq[i]<=n)
        {
            q=1;
            int x=inputSeq[i];
            for(int j=i;j<n;j++)
            {
                b[j]=x;
                x++;
                if(x>n)
                    x=1;
            }
            for(int j=0;j<i;j++)
            {
                b[j]=x++;
                if(x>n)
                    x=1;
            }
        }
    }
    if(!q)
        for(int i=0;i<n;i++)
            b[i]=i+1;
    int x=n+1;
    long long ans=1;
    long long cnt=0;
    for(int i=n+1;i<N;i++)
        if(a[i])
            cnt++;
    int last=n;
    for(int i=n+1;i<N;i++)
    {
        if(!a[i]||cnt==0)
            continue ;
        a[i]--;
        ans*=pow(cnt,(inputSeq[a[i]]-last)-1);
        ans%=m;
        last=inputSeq[a[i]];
        cnt--;
    }
    return ans;
}

Compilation message

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:154:9: warning: unused variable 'x' [-Wunused-variable]
     int x=n+1;
         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 2 ms 496 KB Output is correct
3 Correct 2 ms 496 KB Output is correct
4 Correct 2 ms 620 KB Output is correct
5 Correct 2 ms 620 KB Output is correct
6 Correct 7 ms 928 KB Output is correct
7 Correct 14 ms 1192 KB Output is correct
8 Correct 12 ms 1192 KB Output is correct
9 Correct 5 ms 1192 KB Output is correct
10 Correct 13 ms 1220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1220 KB Output is correct
2 Correct 2 ms 1220 KB Output is correct
3 Correct 2 ms 1220 KB Output is correct
4 Correct 2 ms 1220 KB Output is correct
5 Correct 2 ms 1220 KB Output is correct
6 Correct 7 ms 1220 KB Output is correct
7 Correct 14 ms 1248 KB Output is correct
8 Correct 11 ms 1248 KB Output is correct
9 Correct 6 ms 1248 KB Output is correct
10 Correct 13 ms 1252 KB Output is correct
11 Correct 2 ms 1252 KB Output is correct
12 Correct 2 ms 1252 KB Output is correct
13 Correct 8 ms 1508 KB Output is correct
14 Correct 2 ms 1508 KB Output is correct
15 Correct 15 ms 1508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1508 KB Output is correct
2 Correct 2 ms 1508 KB Output is correct
3 Correct 3 ms 1508 KB Output is correct
4 Correct 3 ms 1508 KB Output is correct
5 Correct 3 ms 1508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1508 KB Output is correct
2 Correct 2 ms 1508 KB Output is correct
3 Correct 3 ms 1508 KB Output is correct
4 Correct 2 ms 1508 KB Output is correct
5 Correct 2 ms 1508 KB Output is correct
6 Correct 2 ms 1508 KB Output is correct
7 Correct 3 ms 1508 KB Output is correct
8 Correct 3 ms 1508 KB Output is correct
9 Correct 3 ms 1508 KB Output is correct
10 Correct 3 ms 1508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1508 KB Output is correct
2 Correct 2 ms 1508 KB Output is correct
3 Correct 2 ms 1508 KB Output is correct
4 Correct 2 ms 1508 KB Output is correct
5 Correct 3 ms 1508 KB Output is correct
6 Correct 2 ms 1508 KB Output is correct
7 Correct 2 ms 1508 KB Output is correct
8 Correct 3 ms 1508 KB Output is correct
9 Correct 3 ms 1508 KB Output is correct
10 Correct 3 ms 1508 KB Output is correct
11 Correct 13 ms 1580 KB Output is correct
12 Correct 15 ms 1708 KB Output is correct
13 Correct 16 ms 1964 KB Output is correct
14 Correct 13 ms 1964 KB Output is correct
15 Correct 24 ms 2988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2988 KB Output is correct
2 Correct 4 ms 2988 KB Output is correct
3 Correct 3 ms 2988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2988 KB Output is correct
2 Correct 3 ms 2988 KB Output is correct
3 Correct 3 ms 2988 KB Output is correct
4 Correct 3 ms 2988 KB Output is correct
5 Correct 4 ms 2988 KB Output is correct
6 Correct 3 ms 2988 KB Output is correct
7 Correct 3 ms 2988 KB Output is correct
8 Correct 3 ms 2988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2988 KB Output is correct
2 Correct 3 ms 2988 KB Output is correct
3 Correct 3 ms 2988 KB Output is correct
4 Correct 3 ms 2988 KB Output is correct
5 Correct 4 ms 2988 KB Output is correct
6 Correct 3 ms 2988 KB Output is correct
7 Correct 4 ms 2988 KB Output is correct
8 Correct 3 ms 2988 KB Output is correct
9 Correct 19 ms 2988 KB Output is correct
10 Correct 15 ms 2988 KB Output is correct
11 Correct 11 ms 2988 KB Output is correct
12 Correct 10 ms 2988 KB Output is correct
13 Incorrect 3 ms 2988 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2988 KB Output is correct
2 Correct 3 ms 2988 KB Output is correct
3 Correct 3 ms 2988 KB Output is correct
4 Correct 4 ms 2988 KB Output is correct
5 Correct 3 ms 2988 KB Output is correct
6 Correct 3 ms 2988 KB Output is correct
7 Correct 3 ms 2988 KB Output is correct
8 Correct 3 ms 2988 KB Output is correct
9 Correct 19 ms 2988 KB Output is correct
10 Correct 16 ms 2988 KB Output is correct
11 Correct 9 ms 2988 KB Output is correct
12 Correct 10 ms 2988 KB Output is correct
13 Incorrect 4 ms 2988 KB Output isn't correct
14 Halted 0 ms 0 KB -