답안 #8527

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
8527 2014-09-16T05:12:40 Z gs14004 곤돌라 (IOI14_gondola) C++
90 / 100
24 ms 3848 KB
#include <cstdio>
#include <algorithm>
#include <queue>
#include <utility>
#include <set>
#include "gondola.h"

using namespace std;
typedef pair<int,int> pi;

int valid(int n, int inputSeq[]){
    int v[250005]={};
    for (int i=0; i<n; i++) {
        if(v[inputSeq[i]]) return 0;
        v[inputSeq[i]] = 1;
    }
    int piv = -1;
    for (int i=0; i<n; i++) {
        if(inputSeq[i] <= n){
            if(piv == -1){
                piv = i;
            }
            else{
                int res = i + (inputSeq[piv] - piv) + n;
                res %= n;
                if(res == 0) res = n;
                if(inputSeq[i] != res) return 0;
            }
        }
    }
    return 1;
}

priority_queue<pi,vector<pi>,greater<pi> > pq, pq2;
set<int> mp;

int replacement(int n, int gondolaSeq[], int replacementSeq[]){
    int piv = 0, piv2 = n+1, piv3 = 0;
    for (int i=0; i<n; i++) {
        if(gondolaSeq[i] <= n){
            piv = gondolaSeq[i] - i - 1+ n;
            piv %= n;
        }
    }
    int newSeq[100005] = {};
    for (int i=0; i<n; i++) {
        newSeq[i] = gondolaSeq[(i + n - piv)%n];
        if(newSeq[i] > n) pq.push(pi(newSeq[i],i+1));
    }
    while (!pq.empty()) {
        pi x = pq.top();
        pq.pop();
        replacementSeq[piv3++] = x.second;
        for (int i=piv2; i<x.first; i++) {
            replacementSeq[piv3++] = i;
        }
        piv2 = x.first + 1;
    }
    return piv3;
}

int pow(int x, int time){
    int mod = 1e9 + 9;
    long long res = 1, piv = x;
    while (time) {
        if(time&1) res *= piv;
        piv *= piv;
        res %= mod;
        piv %= mod;
        time >>= 1;
    }
    return (int)res;
}

int countReplacement(int n, int inputSeq[]){
    if(!valid(n,inputSeq)) return 0;
    int piv = 0, piv2 = n, cnt = 0;
    long long mod = 1e9 + 9;
    long long res = 1;
    int exception = 1;
    for (int i=0; i<n; i++) {
        if(inputSeq[i] <= n){
            piv = inputSeq[i] - i - 1+ n;
            piv %= n;
            exception = 0;
        }
    }
    priority_queue<int,vector<int>,greater<int> > pq2;
    for (int i=0; i<n; i++) {
        if(inputSeq[i] > n) pq2.push(inputSeq[i]), cnt++;
    }
    if(exception) res = cnt;
    while (!pq2.empty()) {
        res *= pow(cnt,pq2.top() - piv2 - 1);
        piv2 = pq2.top();
        pq2.pop();
        cnt--;
        res %= mod;
    }
    return (int)res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3460 KB Output is correct
2 Correct 0 ms 3456 KB Output is correct
3 Correct 0 ms 3460 KB Output is correct
4 Correct 0 ms 3456 KB Output is correct
5 Correct 0 ms 3460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3464 KB Output is correct
2 Correct 0 ms 3460 KB Output is correct
3 Correct 0 ms 3460 KB Output is correct
4 Correct 0 ms 3456 KB Output is correct
5 Correct 0 ms 3460 KB Output is correct
6 Correct 4 ms 3460 KB Output is correct
7 Correct 12 ms 3464 KB Output is correct
8 Correct 8 ms 3460 KB Output is correct
9 Correct 4 ms 3456 KB Output is correct
10 Correct 8 ms 3460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3460 KB Output is correct
2 Correct 0 ms 3456 KB Output is correct
3 Correct 0 ms 3456 KB Output is correct
4 Correct 0 ms 3460 KB Output is correct
5 Correct 0 ms 3456 KB Output is correct
6 Correct 4 ms 3460 KB Output is correct
7 Correct 12 ms 3460 KB Output is correct
8 Correct 12 ms 3460 KB Output is correct
9 Correct 4 ms 3460 KB Output is correct
10 Correct 12 ms 3464 KB Output is correct
11 Correct 0 ms 3456 KB Output is correct
12 Correct 0 ms 3460 KB Output is correct
13 Correct 4 ms 3460 KB Output is correct
14 Correct 0 ms 3460 KB Output is correct
15 Correct 8 ms 3460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2608 KB Output is correct
2 Correct 0 ms 2608 KB Output is correct
3 Correct 0 ms 2608 KB Output is correct
4 Correct 0 ms 2608 KB Output is correct
5 Correct 0 ms 2608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2608 KB Output is correct
2 Correct 0 ms 2608 KB Output is correct
3 Correct 0 ms 2608 KB Output is correct
4 Correct 0 ms 2608 KB Output is correct
5 Correct 0 ms 2608 KB Output is correct
6 Correct 0 ms 2608 KB Output is correct
7 Correct 0 ms 2608 KB Output is correct
8 Correct 0 ms 2608 KB Output is correct
9 Correct 0 ms 2608 KB Output is correct
10 Correct 0 ms 2608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2608 KB Output is correct
2 Correct 0 ms 2608 KB Output is correct
3 Correct 0 ms 2608 KB Output is correct
4 Correct 0 ms 2608 KB Output is correct
5 Correct 0 ms 2608 KB Output is correct
6 Correct 0 ms 2608 KB Output is correct
7 Correct 0 ms 2608 KB Output is correct
8 Correct 0 ms 2608 KB Output is correct
9 Correct 0 ms 2608 KB Output is correct
10 Correct 0 ms 2608 KB Output is correct
11 Correct 12 ms 2608 KB Output is correct
12 Correct 16 ms 2608 KB Output is correct
13 Correct 20 ms 2996 KB Output is correct
14 Correct 12 ms 2608 KB Output is correct
15 Correct 20 ms 2996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3464 KB Output is correct
2 Correct 0 ms 3464 KB Output is correct
3 Correct 0 ms 3460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3460 KB Output is correct
2 Correct 0 ms 3460 KB Output is correct
3 Correct 0 ms 3464 KB Output is correct
4 Correct 0 ms 3464 KB Output is correct
5 Correct 0 ms 3460 KB Output is correct
6 Correct 0 ms 3456 KB Output is correct
7 Correct 0 ms 3460 KB Output is correct
8 Correct 0 ms 3456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3460 KB Output is correct
2 Correct 0 ms 3460 KB Output is correct
3 Correct 0 ms 3464 KB Output is correct
4 Correct 0 ms 3460 KB Output is correct
5 Correct 0 ms 3460 KB Output is correct
6 Correct 0 ms 3460 KB Output is correct
7 Correct 0 ms 3460 KB Output is correct
8 Correct 0 ms 3460 KB Output is correct
9 Correct 20 ms 3848 KB Output is correct
10 Correct 20 ms 3844 KB Output is correct
11 Correct 8 ms 3588 KB Output is correct
12 Correct 8 ms 3592 KB Output is correct
13 Correct 0 ms 3460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3460 KB Output is correct
2 Correct 0 ms 3460 KB Output is correct
3 Correct 0 ms 3464 KB Output is correct
4 Correct 0 ms 3456 KB Output is correct
5 Correct 0 ms 3460 KB Output is correct
6 Correct 0 ms 3456 KB Output is correct
7 Correct 0 ms 3456 KB Output is correct
8 Correct 0 ms 3464 KB Output is correct
9 Correct 24 ms 3844 KB Output is correct
10 Correct 16 ms 3848 KB Output is correct
11 Correct 8 ms 3584 KB Output is correct
12 Correct 8 ms 3588 KB Output is correct
13 Correct 0 ms 3456 KB Output is correct
14 Runtime error 16 ms 3452 KB SIGBUS Bus error
15 Halted 0 ms 0 KB -