답안 #16217

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
16217 2015-08-18T07:25:29 Z CodingBug 곤돌라 (IOI14_gondola) C++
100 / 100
89 ms 6936 KB
#include "gondola.h"
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <set>
#define LMT 1000000009
using namespace std;

int valid(int n, int inputSeq[])
{
    int i,p;
    set<int> ch;

    ch.clear();
    for(i=0;i<n;i++){
        if(ch.find(inputSeq[i])!=ch.end()) return 0;
        ch.insert(inputSeq[i]);
    }

    for(i=0;i<n;i++) if(inputSeq[i]<=n) break;
    p=inputSeq[i];
    for(;i<n;i++,p++) if(inputSeq[i]<=n && inputSeq[i]!=(p-1)%n+1) return 0;
    return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
    int i,p,l;
    vector<pair<int,int> > v;
    for(i=0;i<n;i++) if(gondolaSeq[i]>n) v.push_back(make_pair(gondolaSeq[i],i));
    sort(v.begin(),v.end());
    for(i=0;i<n;i++) if(gondolaSeq[i]<=n) break;
    if(i==n) gondolaSeq[i=0]=1;
    for(p=1;p<n;p++) gondolaSeq[(p+i)%n]=(gondolaSeq[i]+p-1)%n+1;
    for(i=n+1,p=0,l=0;p<v.size();i++){
        replacementSeq[l++]=gondolaSeq[v[p].second];
        gondolaSeq[v[p].second]=i;
        if(v[p].first==i) p++;
    }
    return l;
}

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

int mpow(int x,int y){
    if(!y) return 1;
    int k=mpow(x,y/2);
    if(y&1) return (long long)((long long)k*k%LMT)*x%LMT;
    else return (long long)k*k%LMT;
}

int countReplacement(int n, int inputSeq[])
{
    if(!valid(n,inputSeq)) return 0;
    int i,p,s=n;
    vector<int> v;
    for(i=0;i<n;i++) if(inputSeq[i]>n) v.push_back(inputSeq[i]);
    for(i=0;i<n;i++) if(inputSeq[i]<=n) s=1;
    v.push_back(n);
    sort(v.begin(),v.end());
    for(i=1;i<v.size();i++) s=(long long)s*mpow(((int)v.size()-i),(v[i]-v[i-1]-1))%LMT;
    return s;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2584 KB Output is correct
2 Correct 0 ms 2584 KB Output is correct
3 Correct 0 ms 2584 KB Output is correct
4 Correct 0 ms 2584 KB Output is correct
5 Correct 0 ms 2584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2584 KB Output is correct
2 Correct 0 ms 2584 KB Output is correct
3 Correct 0 ms 2584 KB Output is correct
4 Correct 0 ms 2584 KB Output is correct
5 Correct 0 ms 2584 KB Output is correct
6 Correct 20 ms 4300 KB Output is correct
7 Correct 7 ms 2584 KB Output is correct
8 Correct 33 ms 5884 KB Output is correct
9 Correct 10 ms 3640 KB Output is correct
10 Correct 56 ms 6412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2584 KB Output is correct
2 Correct 0 ms 2584 KB Output is correct
3 Correct 0 ms 2584 KB Output is correct
4 Correct 0 ms 2584 KB Output is correct
5 Correct 0 ms 2584 KB Output is correct
6 Correct 15 ms 4300 KB Output is correct
7 Correct 18 ms 2584 KB Output is correct
8 Correct 34 ms 5884 KB Output is correct
9 Correct 7 ms 3640 KB Output is correct
10 Correct 47 ms 6412 KB Output is correct
11 Correct 0 ms 2584 KB Output is correct
12 Correct 0 ms 2584 KB Output is correct
13 Correct 21 ms 4168 KB Output is correct
14 Correct 0 ms 2584 KB Output is correct
15 Correct 51 ms 6544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2584 KB Output is correct
2 Correct 0 ms 2584 KB Output is correct
3 Correct 0 ms 2584 KB Output is correct
4 Correct 0 ms 2584 KB Output is correct
5 Correct 0 ms 2584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2584 KB Output is correct
2 Correct 0 ms 2584 KB Output is correct
3 Correct 0 ms 2584 KB Output is correct
4 Correct 0 ms 2584 KB Output is correct
5 Correct 0 ms 2584 KB Output is correct
6 Correct 0 ms 2584 KB Output is correct
7 Correct 0 ms 2584 KB Output is correct
8 Correct 0 ms 2584 KB Output is correct
9 Correct 0 ms 2584 KB Output is correct
10 Correct 0 ms 2584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2584 KB Output is correct
2 Correct 0 ms 2584 KB Output is correct
3 Correct 0 ms 2584 KB Output is correct
4 Correct 0 ms 2584 KB Output is correct
5 Correct 0 ms 2584 KB Output is correct
6 Correct 0 ms 2584 KB Output is correct
7 Correct 0 ms 2584 KB Output is correct
8 Correct 0 ms 2584 KB Output is correct
9 Correct 1 ms 2584 KB Output is correct
10 Correct 0 ms 2584 KB Output is correct
11 Correct 10 ms 2584 KB Output is correct
12 Correct 13 ms 2584 KB Output is correct
13 Correct 19 ms 2972 KB Output is correct
14 Correct 0 ms 2584 KB Output is correct
15 Correct 22 ms 2972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2584 KB Output is correct
2 Correct 0 ms 2584 KB Output is correct
3 Correct 0 ms 2584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2584 KB Output is correct
2 Correct 0 ms 2584 KB Output is correct
3 Correct 0 ms 2584 KB Output is correct
4 Correct 0 ms 2584 KB Output is correct
5 Correct 0 ms 2584 KB Output is correct
6 Correct 0 ms 2584 KB Output is correct
7 Correct 0 ms 2584 KB Output is correct
8 Correct 0 ms 2584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2584 KB Output is correct
2 Correct 0 ms 2584 KB Output is correct
3 Correct 0 ms 2584 KB Output is correct
4 Correct 0 ms 2584 KB Output is correct
5 Correct 0 ms 2584 KB Output is correct
6 Correct 0 ms 2584 KB Output is correct
7 Correct 0 ms 2584 KB Output is correct
8 Correct 0 ms 2584 KB Output is correct
9 Correct 46 ms 6012 KB Output is correct
10 Correct 46 ms 5352 KB Output is correct
11 Correct 20 ms 3504 KB Output is correct
12 Correct 22 ms 3768 KB Output is correct
13 Correct 5 ms 2844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2584 KB Output is correct
2 Correct 0 ms 2584 KB Output is correct
3 Correct 0 ms 2584 KB Output is correct
4 Correct 0 ms 2584 KB Output is correct
5 Correct 0 ms 2584 KB Output is correct
6 Correct 0 ms 2584 KB Output is correct
7 Correct 0 ms 2584 KB Output is correct
8 Correct 0 ms 2584 KB Output is correct
9 Correct 63 ms 6012 KB Output is correct
10 Correct 52 ms 5352 KB Output is correct
11 Correct 18 ms 3504 KB Output is correct
12 Correct 17 ms 3768 KB Output is correct
13 Correct 3 ms 2844 KB Output is correct
14 Correct 72 ms 6408 KB Output is correct
15 Correct 89 ms 6936 KB Output is correct
16 Correct 10 ms 3372 KB Output is correct
17 Correct 53 ms 5484 KB Output is correct
18 Correct 25 ms 4164 KB Output is correct