Submission #102409

# Submission time Handle Problem Language Result Execution time Memory
102409 2019-03-24T17:40:54 Z naoai Gondola (IOI14_gondola) C++14
40 / 100
36 ms 2232 KB
#include "gondola.h"
#include <bits/stdc++.h>

using namespace std;

int valid(int n, int inputSeq[]) {
    vector<int> v(2 * n);
    for (int i = 0; i < 2 * n; ++ i)
        v[i] = inputSeq[i % n];

    sort(inputSeq, inputSeq + n);
    for (int i = 1; i < n; ++ i) {
        if (inputSeq[i] == inputSeq[i - 1])
            return 0;
    }

    if (inputSeq[0] > n)
        return 1;

    int ind = 0;
    while (ind < n && v[ind] != inputSeq[0])
        ++ ind;
    for (int i = 0; i < n; ++ i) {
        if (v[ind + i] <= n && v[ind + i] != inputSeq[0] + i)
            return 0;
    }
    return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
    int mn = 0;
    for (int i = 0; i < n; ++ i) {
        if (gondolaSeq[i] < gondolaSeq[mn])
            mn = i;
    }

    vector<pair<int, int>> ord;
    vector<int> v(2 * n);
    v.resize(2 * n);
    for (int i = 0; i < 2 * n; ++ i)
        v[i] = gondolaSeq[i % n];

    int l = 0;
    for (int i = mn; i < mn + n; ++ i) {
        if (v[i] > n) {
            ord.push_back({v[i], i - mn + v[mn]});
        }
    }

    ord.push_back({n, -1});
    sort(ord.begin(), ord.end());
    for (int i = 1; i < (int)ord.size(); ++ i) {
        int val = ord[i].second;
        for (int j = ord[i - 1].first + 1; j <= ord[i].first; ++ j) {
            replacementSeq[l ++] = val;
            val = j;
        }
    }
    return l;
}

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

static const int mod = 1e9 + 9;

long long lgput (long long b, int p) {
    long long sol = 1;
    while (p > 0) {
        if (p & 1)
            sol = sol * b % mod;
        b = b * b % mod;
        p >>= 1;
    }
    return sol;
}

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

    long long ans = 1;
    int mn = 0;
    for (int i = 0; i < n; ++ i) {
        if (inputSeq[i] < inputSeq[mn])
            mn = i;
    }

    vector<int> v(2 * n);
    v.resize(2 * n);
    for (int i = 0; i < 2 * n; ++ i)
        v[i] = inputSeq[i % n];

    vector<int> ord;
    for (int i = mn; i < mn + n; ++ i) {
        if (v[i] > n) {
            ord.push_back(v[i]);
        }
    }

    ord.push_back(n);
    sort(ord.begin(), ord.end());

    for (int i = 1; i < (int)ord.size(); ++ i) {
        int cnt = ord[i] - 1 - ord[i - 1];
        ans = ans * lgput((int)ord.size() - i, cnt) % mod;
    }

    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 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
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 10 ms 1024 KB Output is correct
7 Correct 22 ms 1836 KB Output is correct
8 Correct 16 ms 1560 KB Output is correct
9 Correct 9 ms 768 KB Output is correct
10 Correct 20 ms 1792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 404 KB Output is correct
3 Correct 3 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 13 ms 1020 KB Output is correct
7 Correct 21 ms 1920 KB Output is correct
8 Correct 15 ms 1536 KB Output is correct
9 Correct 7 ms 768 KB Output is correct
10 Correct 21 ms 1792 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 12 ms 1024 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 22 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Incorrect 2 ms 256 KB Integer 3 violates the range [1, 2]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Incorrect 2 ms 256 KB Integer 3 violates the range [1, 2]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Incorrect 2 ms 384 KB Integer 3 violates the range [1, 2]
3 Halted 0 ms 0 KB -
# 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 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 3 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 408 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 3 ms 256 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 36 ms 2224 KB Output is correct
10 Correct 24 ms 1964 KB Output is correct
11 Correct 10 ms 976 KB Output is correct
12 Correct 11 ms 1064 KB Output is correct
13 Incorrect 5 ms 512 KB Output isn't 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 3 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 3 ms 384 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 27 ms 2232 KB Output is correct
10 Correct 22 ms 1952 KB Output is correct
11 Correct 11 ms 976 KB Output is correct
12 Correct 11 ms 1084 KB Output is correct
13 Incorrect 4 ms 512 KB Output isn't correct
14 Halted 0 ms 0 KB -