답안 #102996

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
102996 2019-03-28T12:17:21 Z alexpetrescu 곤돌라 (IOI14_gondola) C++14
100 / 100
42 ms 2304 KB
#include <vector>
#include <algorithm>

#include "gondola.h"

int valid(int n, int inputSeq[]) {
    int cat = 0;
    for (int i = 0; i < n; i++)
        if (inputSeq[i] <= n)
            cat = inputSeq[i] - i - 1;
    if (cat < 0)
        cat += n;
    for (int i = 0; i < n; i++)
        if (inputSeq[i] <= n && cat != inputSeq[i] - i - 1 && cat != inputSeq[i] - i - 1 + n)
            return 0;
    std::sort(inputSeq, inputSeq + n);
    if (inputSeq[0] <= 0)
        return 0;
    for (int i = 1; i < n; i++)
        if (inputSeq[i] == inputSeq[i - 1])
            return 0;
    return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
    int cat = 0;
    std::vector < std::pair < int, int > > q;
    for (int i = 0; i < n; i++)
        if (gondolaSeq[i] <= n)
            cat = gondolaSeq[i] - i - 1;
        else
            q.push_back({gondolaSeq[i], i});
    if (cat < 0)
        cat += n;
    int e = n + 1, ans = 0;
    std::sort(q.begin(), q.end());
    for (auto &x : q) {
        replacementSeq[ans++] = (x.second + cat) % n + 1;
        while (e < x.first) {
            replacementSeq[ans++] = e;
            e++;
        }
        e++;
    }
    return ans;
}

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

#define MOD 1000000009

inline int lgput(int a, int n) {
    int r = 1;
    while (n) {
        if (n % 2)
            r = 1LL * r * a % MOD;
        a = 1LL * a * a % MOD;
        n /= 2;
    }
    return r;
}

int countReplacement(int n, int inputSeq[]) {
    if (valid(n, inputSeq) == 0)
        return 0;

    std::vector < int > r(1, n);
    for (int i = 0; i < n; i++)
        if (inputSeq[i] > n)
            r.push_back(inputSeq[i]);
    std::sort(r.begin(), r.end());

    int ans = 1;
    for (int i = 1; i < (int)r.size(); i++)
        ans = 1LL * ans * lgput(r.size() - i, r[i] - r[i - 1] - 1) % MOD;
    if ((int)r.size() == n + 1)
        ans = 1LL * ans * n % MOD;
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 428 KB Output is correct
6 Correct 9 ms 512 KB Output is correct
7 Correct 15 ms 612 KB Output is correct
8 Correct 12 ms 640 KB Output is correct
9 Correct 10 ms 384 KB Output is correct
10 Correct 18 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 9 ms 512 KB Output is correct
7 Correct 13 ms 588 KB Output is correct
8 Correct 11 ms 640 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 24 ms 640 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 7 ms 384 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 15 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 256 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 11 ms 640 KB Output is correct
12 Correct 16 ms 640 KB Output is correct
13 Correct 21 ms 1296 KB Output is correct
14 Correct 10 ms 640 KB Output is correct
15 Correct 32 ms 2304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 22 ms 1024 KB Output is correct
10 Correct 19 ms 1024 KB Output is correct
11 Correct 7 ms 640 KB Output is correct
12 Correct 9 ms 640 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 3 ms 256 KB Output is correct
9 Correct 22 ms 1016 KB Output is correct
10 Correct 18 ms 1016 KB Output is correct
11 Correct 8 ms 640 KB Output is correct
12 Correct 12 ms 640 KB Output is correct
13 Correct 5 ms 380 KB Output is correct
14 Correct 28 ms 2036 KB Output is correct
15 Correct 42 ms 2164 KB Output is correct
16 Correct 9 ms 768 KB Output is correct
17 Correct 20 ms 1536 KB Output is correct
18 Correct 13 ms 1152 KB Output is correct