Submission #102995

# Submission time Handle Problem Language Result Execution time Memory
102995 2019-03-28T12:13:32 Z alexpetrescu Gondola (IOI14_gondola) C++14
75 / 100
24 ms 2544 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;
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 ms 256 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 256 KB Output is correct
6 Correct 14 ms 640 KB Output is correct
7 Correct 12 ms 896 KB Output is correct
8 Correct 19 ms 768 KB Output is correct
9 Correct 10 ms 512 KB Output is correct
10 Correct 18 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 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
6 Correct 10 ms 640 KB Output is correct
7 Correct 13 ms 896 KB Output is correct
8 Correct 13 ms 768 KB Output is correct
9 Correct 8 ms 508 KB Output is correct
10 Correct 19 ms 768 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 8 ms 640 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 18 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory 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 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 3 ms 256 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 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 384 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 3 ms 384 KB Output is correct
11 Correct 12 ms 768 KB Output is correct
12 Correct 11 ms 896 KB Output is correct
13 Correct 17 ms 1424 KB Output is correct
14 Correct 13 ms 896 KB Output is correct
15 Correct 24 ms 2544 KB Output is correct
# Verdict Execution time Memory 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
# Verdict Execution time Memory 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 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 356 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 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 20 ms 1252 KB Output is correct
10 Correct 18 ms 1144 KB Output is correct
11 Correct 8 ms 768 KB Output is correct
12 Correct 9 ms 896 KB Output is correct
13 Incorrect 4 ms 384 KB Output isn't correct
# Verdict Execution time Memory 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 3 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 384 KB Output is correct
9 Correct 20 ms 1408 KB Output is correct
10 Correct 16 ms 1152 KB Output is correct
11 Correct 7 ms 768 KB Output is correct
12 Correct 12 ms 768 KB Output is correct
13 Incorrect 4 ms 384 KB Output isn't correct
14 Halted 0 ms 0 KB -