답안 #111208

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
111208 2019-05-14T06:58:02 Z IVIosab 곤돌라 (IOI14_gondola) C++17
100 / 100
127 ms 6640 KB
#include <bits/stdc++.h>
#include "gondola.h"

using namespace std;
int MOD = 1e9 + 9;

long long fast_power(long long base, long long power) {
    long long result = 1;
    while (power > 0) {
        if (power % 2 == 1) {
            result = (result * base) % MOD;
        }
        base = (base * base) % MOD;
        power = power / 2;
    }
    return result;
}



int valid(int n, int inputSeq[]) {
    map<int,int> mp;
    int fx = 0, ind = 0, val = 0;
    for (int i = 0; i < n; i++) {
        int x = inputSeq[i];
        if (mp[x] == 1) {
            return 0;
        }
        mp[x] = 1;
        if (x > n) {
            fx++;
        }
        if (x <= n) {
            ind = i;
            val = x;
        }
    }
    if (fx == n) {
        return 1;
    }
    for (int i = ind; i < ind + n; i++) {
        int x = inputSeq[i % n];
        if (x > n) {
            inputSeq[i % n] = val;
        } else {
            if (x != val) {
                return 0;
            }
        }
        val++;
        if (val > n) {
            val = 1;
        }
    }
    return 1;
}

int ar[250005];

int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
    int mx = 0;
    int ind = -1, val = 0;
    for (int i = 0; i < n; i++) {
        int x = gondolaSeq[i];
        mx = max(mx, x);
        if (x <= n) {
            val = x;
            ind = i;
        }
    }
    if (ind == -1) {
        ind = 0;
        val = 1;
    }
    for (int i = ind; i < ind + n; i++) {
        ar[i % n] = val;
        val++;
        if (val > n) {
            val = 1;
        }
    }
    int hg = n + 1;
    priority_queue<pair<int, int>> pq;
    for (int i = 0; i < n; i++) {
        if (gondolaSeq[i] > n)
            pq.push({(-1) * gondolaSeq[i], ar[i]});
    }
    int cnt = 0;
    while (!pq.empty()) {
        pair<int, int> pr = pq.top();
        pq.pop();
        replacementSeq[cnt] = pr.second;
        cnt++;
        for (hg; hg < pr.first * (-1); hg++) {
            replacementSeq[cnt] = hg;
            cnt++;
        }
        hg++;
    }
    return cnt;
}

int countReplacement(int n, int inputSeq[]) {
    long long ret = 1, fx = 0;
    vector<int> flex;
    flex.push_back(0);
    for (int i = 0; i < n; i++) {
        int x = inputSeq[i];
        if (x > n) {
            fx++;
            flex.push_back(x - n);
        }
    }
    int val = valid(n, inputSeq);
    if (val) {
        if (fx == 0) {
            return 1;
        }
    } else {
        return 0;
    }
    int mul = flex.size() - 1;
    sort(flex.begin(), flex.end());
    for (int i = 1; i < flex.size(); i++) {
        int x = flex[i - 1];
        ret *= fast_power(mul, ((flex[i] - x) - 1));
        ret %= MOD;
        mul--;
    }
    if (fx == n) {
        ret *= n;
        ret %= MOD;
    }
    return ret % MOD;
}

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:94:16: warning: statement has no effect [-Wunused-value]
         for (hg; hg < pr.first * (-1); hg++) {
                ^
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:124:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 1; i < flex.size(); i++) {
                     ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 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
6 Correct 17 ms 2304 KB Output is correct
7 Correct 15 ms 640 KB Output is correct
8 Correct 31 ms 3960 KB Output is correct
9 Correct 11 ms 1536 KB Output is correct
10 Correct 50 ms 4600 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 256 KB Output is correct
6 Correct 22 ms 2424 KB Output is correct
7 Correct 14 ms 640 KB Output is correct
8 Correct 33 ms 3960 KB Output is correct
9 Correct 13 ms 1536 KB Output is correct
10 Correct 43 ms 4600 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 27 ms 2176 KB Output is correct
14 Correct 2 ms 412 KB Output is correct
15 Correct 86 ms 4856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 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
# 결과 실행 시간 메모리 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 3 ms 384 KB Output is correct
5 Correct 3 ms 256 KB Output is correct
6 Correct 3 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 3 ms 256 KB Output is correct
2 Correct 3 ms 256 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 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 420 KB Output is correct
11 Correct 12 ms 896 KB Output is correct
12 Correct 12 ms 1024 KB Output is correct
13 Correct 18 ms 1424 KB Output is correct
14 Correct 10 ms 896 KB Output is correct
15 Correct 24 ms 2260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 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 2 ms 384 KB Output is correct
5 Correct 2 ms 256 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
# 결과 실행 시간 메모리 Grader output
1 Correct 3 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 2 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 58 ms 4340 KB Output is correct
10 Correct 58 ms 3572 KB Output is correct
11 Correct 25 ms 1528 KB Output is correct
12 Correct 24 ms 1792 KB Output is correct
13 Correct 8 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 256 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 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 512 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 55 ms 4336 KB Output is correct
10 Correct 55 ms 3632 KB Output is correct
11 Correct 17 ms 1536 KB Output is correct
12 Correct 19 ms 1792 KB Output is correct
13 Correct 6 ms 640 KB Output is correct
14 Correct 80 ms 4976 KB Output is correct
15 Correct 127 ms 6640 KB Output is correct
16 Correct 14 ms 1536 KB Output is correct
17 Correct 74 ms 4464 KB Output is correct
18 Correct 43 ms 2804 KB Output is correct