답안 #102412

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
102412 2019-03-24T18:12:50 Z naoai 곤돌라 (IOI14_gondola) C++14
55 / 100
28 ms 2412 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];

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

    int l = 0;
    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;

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

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

    long long ans = 1;
    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;
}

# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 Grader output
1 Correct 3 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 3 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 11 ms 768 KB Output is correct
7 Correct 19 ms 1408 KB Output is correct
8 Correct 12 ms 1152 KB Output is correct
9 Correct 6 ms 640 KB Output is correct
10 Correct 19 ms 1280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 284 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 768 KB Output is correct
7 Correct 18 ms 1408 KB Output is correct
8 Correct 14 ms 1280 KB Output is correct
9 Correct 7 ms 640 KB Output is correct
10 Correct 20 ms 1280 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 10 ms 768 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 20 ms 1408 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 3 ms 384 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 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
# 결과 실행 시간 메모리 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 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 12 ms 1788 KB Output is correct
12 Correct 15 ms 1920 KB Output is correct
13 Correct 24 ms 1660 KB Output is correct
14 Correct 13 ms 1792 KB Output is correct
15 Incorrect 28 ms 2412 KB Integer 28577 violates the range [1, 16843]
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 356 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 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 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 256 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 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 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 2 ms 432 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 26 ms 1152 KB Output is correct
10 Correct 20 ms 1056 KB Output is correct
11 Correct 9 ms 640 KB Output is correct
12 Correct 14 ms 680 KB Output is correct
13 Incorrect 4 ms 384 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 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 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 256 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 23 ms 1280 KB Output is correct
10 Correct 20 ms 1056 KB Output is correct
11 Correct 9 ms 720 KB Output is correct
12 Correct 10 ms 680 KB Output is correct
13 Incorrect 4 ms 384 KB Output isn't correct
14 Halted 0 ms 0 KB -