답안 #316209

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
316209 2020-10-25T17:09:44 Z qpwoeirut 곤돌라 (IOI14_gondola) C++17
100 / 100
110 ms 6100 KB
#include <bits/stdc++.h>
#include "gondola.h"

using namespace std;

typedef long long ll;

const int MN = 250001;
const ll MOD = 1e9 + 9;

bool normalize(int n, int seq[]) {
    for (int i=0; i<n; ++i) {
        if (seq[i] <= n) {
            int val = seq[i];
            int idx = (n + i - val + 1) % n;
            rotate(seq, seq+idx, seq+n);
            return true;
        }
    }
    return false;
}

int valid(int n, int inputSeq[]) {
    normalize(n, inputSeq);
    //for (int i=0; i<n; ++i) { cerr << inputSeq[i] << ' '; } cerr << endl;

    set<int> seen;
    for (int i=0; i<n; ++i) {
        if (inputSeq[i] != i+1 && inputSeq[i] <= n) {
            return 0;
        }
        if (seen.count(inputSeq[i])) {
            return 0;
        }
        seen.insert(inputSeq[i]);
    }

    return 1;
}

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

bool seen[MN];
int pos[MN];
pair<int,int> process(int n, int seq[]) {
    int mxv = 0;
    int mxi = -1;
    for (int i=0; i<n; ++i) {
        pos[seq[i]] = i;
        seen[seq[i]] = true;
        if (mxv < seq[i]) {
            mxv = seq[i];
            mxi = i;
        }
    }
    return pair<int,int>(mxv, mxi);
}

int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
    fill(seen, seen+n, false);
    normalize(n, gondolaSeq);

    auto mx = process(n, gondolaSeq);
    int mxv = mx.first;
    int cur = mx.second + 1;

    int idx = 0;
    for (int i=n+1; i<=mxv; ++i) {
        if (!seen[i] || i == mxv) {
            replacementSeq[idx++] = cur;
            cur = i;
        } else {
            replacementSeq[idx++] = pos[i] + 1;
        }
    }

    return idx;
}

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

ll bpow(ll b, ll p) {
    b %= MOD;
    p %= MOD;
    ll ret = 1;
    while (p) {
        if (p & 1) {
            ret = (ret * b) % MOD;
        }
        p >>= 1;
        b = (b * b) % MOD;
    }
    return ret;
}
int countReplacement(int n, int inputSeq[]) {
    bool rotated = normalize(n, inputSeq);
    if (!valid(n, inputSeq)) {
        return 0;
    }

    set<int> nums;
    for (int i=0; i<n; ++i) {
        if (inputSeq[i] > n) {
            nums.insert(inputSeq[i]);
        }
    }

    ll ans = 1;
    ll prev = n+1;
    while (nums.size() > 0) {
        ll cur = *nums.begin();

        ll more = nums.size();
        ans = (ans * bpow(more, cur - prev)) % MOD;

        prev = cur + 1;

        nums.erase(nums.begin());
    }

    if (!rotated) {
        ans = (ans * (ll)n) % MOD;
    }

    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 20 ms 2168 KB Output is correct
7 Correct 13 ms 640 KB Output is correct
8 Correct 31 ms 3964 KB Output is correct
9 Correct 12 ms 1536 KB Output is correct
10 Correct 39 ms 4600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 16 ms 2304 KB Output is correct
7 Correct 13 ms 640 KB Output is correct
8 Correct 31 ms 3892 KB Output is correct
9 Correct 12 ms 1536 KB Output is correct
10 Correct 37 ms 4520 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 6 ms 512 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 23 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 21 ms 1024 KB Output is correct
12 Correct 14 ms 1152 KB Output is correct
13 Correct 15 ms 1664 KB Output is correct
14 Correct 12 ms 1024 KB Output is correct
15 Correct 32 ms 2808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 70 ms 4088 KB Output is correct
10 Correct 52 ms 3456 KB Output is correct
11 Correct 20 ms 1536 KB Output is correct
12 Correct 23 ms 1792 KB Output is correct
13 Correct 5 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 81 ms 4232 KB Output is correct
10 Correct 63 ms 3576 KB Output is correct
11 Correct 19 ms 1408 KB Output is correct
12 Correct 23 ms 1664 KB Output is correct
13 Correct 5 ms 640 KB Output is correct
14 Correct 96 ms 4632 KB Output is correct
15 Correct 110 ms 6100 KB Output is correct
16 Correct 15 ms 1408 KB Output is correct
17 Correct 67 ms 4216 KB Output is correct
18 Correct 33 ms 2552 KB Output is correct