답안 #102413

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
102413 2019-03-24T19:12:33 Z naoai 곤돌라 (IOI14_gondola) C++14
100 / 100
39 ms 2580 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 - pst + 1)});
                assert(ord.back().second <= n);
            }
        }
    }

    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;
    }

    if (ord.size() == n + 1) {
        ans = ans * n % mod;
    }

    return ans;
}

Compilation message

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:109:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (ord.size() == n + 1) {
         ~~~~~~~~~~~^~~~~~~~
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 356 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 9 ms 768 KB Output is correct
7 Correct 18 ms 1404 KB Output is correct
8 Correct 13 ms 1152 KB Output is correct
9 Correct 9 ms 640 KB Output is correct
10 Correct 19 ms 1280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 39 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
6 Correct 10 ms 768 KB Output is correct
7 Correct 19 ms 1280 KB Output is correct
8 Correct 21 ms 1144 KB Output is correct
9 Correct 6 ms 640 KB Output is correct
10 Correct 19 ms 1280 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 9 ms 768 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 19 ms 1408 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 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 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 3 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 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 384 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 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 300 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 11 ms 1280 KB Output is correct
12 Correct 12 ms 1408 KB Output is correct
13 Correct 14 ms 1404 KB Output is correct
14 Correct 11 ms 1248 KB Output is correct
15 Correct 23 ms 2272 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
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 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 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 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 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 256 KB Output is correct
9 Correct 21 ms 1152 KB Output is correct
10 Correct 17 ms 1024 KB Output is correct
11 Correct 12 ms 720 KB Output is correct
12 Correct 10 ms 680 KB Output is correct
13 Correct 4 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 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 21 ms 1152 KB Output is correct
10 Correct 17 ms 1056 KB Output is correct
11 Correct 8 ms 640 KB Output is correct
12 Correct 10 ms 680 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 31 ms 2416 KB Output is correct
15 Correct 32 ms 2580 KB Output is correct
16 Correct 8 ms 768 KB Output is correct
17 Correct 21 ms 1676 KB Output is correct
18 Correct 13 ms 1256 KB Output is correct