답안 #102989

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
102989 2019-03-28T11:01:10 Z alexpetrescu 곤돌라 (IOI14_gondola) C++14
75 / 100
40 ms 2404 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);
    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 (n + 1 == (int)r.size())
        for (int i = 1; i <= n; i++)
            ans = 1LL * ans * i % MOD;
    return ans;
}
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 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 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 10 ms 512 KB Output is correct
7 Correct 13 ms 640 KB Output is correct
8 Correct 15 ms 640 KB Output is correct
9 Correct 8 ms 384 KB Output is correct
10 Correct 19 ms 640 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 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 10 ms 624 KB Output is correct
7 Correct 13 ms 640 KB Output is correct
8 Correct 13 ms 640 KB Output is correct
9 Correct 9 ms 384 KB Output is correct
10 Correct 17 ms 640 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 8 ms 512 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 19 ms 640 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 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 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 1 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 3 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 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 3 ms 356 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 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 12 ms 640 KB Output is correct
13 Correct 16 ms 1296 KB Output is correct
14 Correct 11 ms 640 KB Output is correct
15 Correct 40 ms 2404 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 384 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 384 KB Output is correct
4 Correct 2 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 256 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 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 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 19 ms 1024 KB Output is correct
10 Correct 15 ms 896 KB Output is correct
11 Correct 12 ms 640 KB Output is correct
12 Correct 10 ms 640 KB Output is correct
13 Incorrect 5 ms 384 KB Output isn't 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 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 18 ms 1024 KB Output is correct
10 Correct 15 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 Incorrect 3 ms 384 KB Output isn't correct
14 Halted 0 ms 0 KB -