Submission #414168

# Submission time Handle Problem Language Result Execution time Memory
414168 2021-05-30T07:55:58 Z dxz05 Gondola (IOI14_gondola) C++14
100 / 100
57 ms 7060 KB
#include "gondola.h"
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 3e5 + 2e2;

int a[MAXN];

int valid(int n, int inputSeq[]){
    for (int i = 0; i < 3 * n; i++) a[i] = inputSeq[i % n];

    set<int> s;
    for (int i = 0; i < n; i++) s.insert(a[i]);

    if (s.size() != n) return 0;

    int ind = -1;
    for (int i = n; i < 2 * n; i++){
        if (a[i] <= n){
            ind = i;
            break;
        }
    }

    if (ind == -1) return 1;

    for (int i = ind - a[ind] + 1; i <= ind - a[ind] + n; i++){
        if (a[i] > n) continue;
        if (a[i] - a[ind] != i - ind) return 0;
    }

    return 1;
}

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

int orig[MAXN];

int replacement(int n, int gondolaSeq[], int replacementSeq[]){
    for (int i = 0; i < n; i++){
        a[i] = gondolaSeq[i];
        orig[i] = i + 1;
    }

    for (int i = 0; i < n; i++){
        if (a[i] <= n){
            int ind = 1;
            for (int j = i - a[i] + 1; j <= i - a[i] + n; j++){
                orig[(j + n) % n] = ind++;
            }

            break;
        }
    }

    set<pair<int, int>> s;
    for (int i = 0; i < n; i++){
        s.insert(make_pair(a[i], orig[i]));
    }
    int last = n;

    int sz = 0;

    while (!s.empty()){
        int cur = s.begin()->second, need = s.begin()->first;
        s.erase(s.begin());

        if (cur == need) continue;

        replacementSeq[sz++] = cur;
        last++;

        while (last < need){
            replacementSeq[sz++] = last;
            last++;
        }

    }

    return sz;
}

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

typedef long long ll;

ll powmod(ll n, ll k, ll m){
    if (k == 0) return 1;
    ll x = powmod(n, k / 2, m);
    x = x * x % m;
    if (k % 2) x = x * n % m;
    return x;
}

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

    for (int i = 0; i < n; i++){
        a[i + 1] = inputSeq[i];
    }

    sort(a + 1, a + n + 1);

    if (a[n] == n) return 1;

    long long ans = 1, MOD = 1e9 + 9;

    ans = 1;
    if (a[1] > n) ans = n;

    a[0] = 0;
    for (int i = n; i >= 1; i--){
        int r = a[i] - 1, l = max(n + 1, a[i - 1] + 1);
        if (l <= r){
            ans *= powmod(n - i + 1, r - l + 1, MOD);
            ans %= MOD;
        }
    }

    return ans;
}

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:16:18: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   16 |     if (s.size() != n) return 0;
      |         ~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 15 ms 2664 KB Output is correct
7 Correct 42 ms 4652 KB Output is correct
8 Correct 28 ms 4700 KB Output is correct
9 Correct 9 ms 1728 KB Output is correct
10 Correct 42 ms 5496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 14 ms 2636 KB Output is correct
7 Correct 31 ms 4648 KB Output is correct
8 Correct 27 ms 4720 KB Output is correct
9 Correct 9 ms 1620 KB Output is correct
10 Correct 31 ms 5452 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 15 ms 2444 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 38 ms 5592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 30 ms 4876 KB Output is correct
12 Correct 33 ms 5564 KB Output is correct
13 Correct 24 ms 3020 KB Output is correct
14 Correct 34 ms 4864 KB Output is correct
15 Correct 28 ms 3072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 40 ms 4764 KB Output is correct
10 Correct 32 ms 4024 KB Output is correct
11 Correct 12 ms 1696 KB Output is correct
12 Correct 14 ms 1996 KB Output is correct
13 Correct 4 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 43 ms 4812 KB Output is correct
10 Correct 32 ms 4060 KB Output is correct
11 Correct 11 ms 1612 KB Output is correct
12 Correct 14 ms 1996 KB Output is correct
13 Correct 4 ms 716 KB Output is correct
14 Correct 49 ms 5556 KB Output is correct
15 Correct 57 ms 7060 KB Output is correct
16 Correct 9 ms 1572 KB Output is correct
17 Correct 42 ms 4888 KB Output is correct
18 Correct 24 ms 2872 KB Output is correct