Submission #102983

# Submission time Handle Problem Language Result Execution time Memory
102983 2019-03-28T10:46:38 Z alexpetrescu Gondola (IOI14_gondola) C++14
75 / 100
54 ms 2288 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;
    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 2 ms 256 KB Output is correct
4 Correct 2 ms 300 KB Output is correct
5 Correct 2 ms 256 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 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 8 ms 512 KB Output is correct
7 Correct 13 ms 640 KB Output is correct
8 Correct 54 ms 632 KB Output is correct
9 Correct 10 ms 384 KB Output is correct
10 Correct 18 ms 640 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
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 8 ms 512 KB Output is correct
7 Correct 12 ms 640 KB Output is correct
8 Correct 12 ms 640 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 18 ms 640 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 7 ms 640 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 13 ms 1152 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 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 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 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 3 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
# 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
4 Correct 2 ms 256 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 2 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 12 ms 640 KB Output is correct
12 Correct 11 ms 640 KB Output is correct
13 Correct 26 ms 1288 KB Output is correct
14 Correct 13 ms 640 KB Output is correct
15 Correct 21 ms 2288 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 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 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 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 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 384 KB Output is correct
9 Correct 22 ms 1400 KB Output is correct
10 Correct 14 ms 1280 KB Output is correct
11 Correct 7 ms 768 KB Output is correct
12 Correct 9 ms 768 KB Output is correct
13 Incorrect 5 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 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 2 ms 256 KB Output is correct
9 Correct 23 ms 1400 KB Output is correct
10 Correct 15 ms 1280 KB Output is correct
11 Correct 9 ms 768 KB Output is correct
12 Correct 9 ms 868 KB Output is correct
13 Incorrect 4 ms 512 KB Output isn't correct
14 Halted 0 ms 0 KB -