답안 #106288

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
106288 2019-04-17T19:10:55 Z popovicirobert 곤돌라 (IOI14_gondola) C++14
100 / 100
91 ms 10300 KB
#include "gondola.h"
#include <bits/stdc++.h>

using namespace std;

const int MOD = (int) 1e9 + 9;
const int INF = (int) 1e9;

int valid(int n, int inputSeq[]) {
    int id = 0, pos;
    map <int, bool> mp;

    for(int i = 0; i < n; i++) {
        if(mp[inputSeq[i]] == 1) {
            return 0;
        }
        mp[inputSeq[i]] = 1;
        if(inputSeq[i] <= n) {
            id = inputSeq[i];
            pos = i;
        }
    }

    if(id != 0) {
        int cur = id;
        int i = pos;
        do {
            if(inputSeq[i] <= n && inputSeq[i] != cur) {
                return 0;
            }
            cur++;
            if(cur == n + 1) {
                cur = 1;
            }
            i = (i + 1) % n;
        }while(i != pos);
    }

    return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
    vector <int> positions;
    for(int i = 0; i < n; i++) {
        if(gondolaSeq[i] > n) {
            positions.push_back(i);
        }
    }

    sort(positions.begin(), positions.end(), [&](const int &a, const int &b) {

            return gondolaSeq[a] < gondolaSeq[b];

         });

    map <int, int> mp;
    int id = 0, pos, mx = 0;
    for(int i = 0; i < n; i++) {
        mp[gondolaSeq[i]] = i + 1;
        mx = max(mx, gondolaSeq[i]);
        if(gondolaSeq[i] <= n) {
            id = gondolaSeq[i];
            pos = i;
        }
    }

    vector <int> ord(n);
    iota(ord.begin(), ord.end(), 1);
    if(id != 0) {
        int i = pos;
        do {
            ord[i] = id;
            id++;
            if(id == n + 1) {
                id = 1;
            }
            i = (i + 1) % n;
        }while(i != pos);
    }

    pos = 0;
    int sz = 0;
    for(int i = n + 1; i <= mx; i++) {
        replacementSeq[sz++] = ord[positions[pos]];
        ord[positions[pos]] = i;
        if(mp[i] > 0) {
            pos++;
        }
    }

    return sz;
}

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

inline int lgput(int a, int b) {
    int ans = 1;
    while(b > 0) {
        if(b & 1)
            ans = (1LL * ans * a) % MOD;
        b >>= 1;
        a = (1LL * a * a) % MOD;
    }
    return ans;
}

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

    vector <int> vals;
    int cnt = 0;

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

    sort(vals.begin(), vals.end());

    int ans = 1, last = n;

    for(auto it : vals) {
        ans = (1LL * ans * lgput(cnt, it - last - 1)) % MOD;
        last = it;
        cnt--;
    }

    if(vals.size() == n) {
        ans = (1LL * ans * n) % MOD;
    }

    return ans;
}

Compilation message

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:134:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(vals.size() == n) {
        ~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 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 2 ms 384 KB Output is correct
5 Correct 2 ms 256 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 3 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 22 ms 2432 KB Output is correct
7 Correct 14 ms 1152 KB Output is correct
8 Correct 31 ms 4344 KB Output is correct
9 Correct 10 ms 1664 KB Output is correct
10 Correct 41 ms 4984 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 412 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 2424 KB Output is correct
7 Correct 13 ms 1152 KB Output is correct
8 Correct 33 ms 4344 KB Output is correct
9 Correct 14 ms 1536 KB Output is correct
10 Correct 44 ms 4984 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 33 ms 2296 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 91 ms 5200 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 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 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 3 ms 356 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 4 ms 640 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 4 ms 640 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 3 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 3 ms 640 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 ms 640 KB Output is correct
11 Correct 29 ms 5112 KB Output is correct
12 Correct 37 ms 5692 KB Output is correct
13 Correct 62 ms 4984 KB Output is correct
14 Correct 34 ms 5112 KB Output is correct
15 Correct 77 ms 10300 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 256 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 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 256 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 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 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 384 KB Output is correct
9 Correct 71 ms 4472 KB Output is correct
10 Correct 43 ms 3832 KB Output is correct
11 Correct 16 ms 1664 KB Output is correct
12 Correct 23 ms 1920 KB Output is correct
13 Correct 6 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 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 384 KB Output is correct
9 Correct 60 ms 4600 KB Output is correct
10 Correct 40 ms 3812 KB Output is correct
11 Correct 15 ms 1664 KB Output is correct
12 Correct 20 ms 1920 KB Output is correct
13 Correct 5 ms 640 KB Output is correct
14 Correct 71 ms 5368 KB Output is correct
15 Correct 78 ms 6036 KB Output is correct
16 Correct 12 ms 1408 KB Output is correct
17 Correct 46 ms 4216 KB Output is correct
18 Correct 25 ms 2552 KB Output is correct