Submission #385836

# Submission time Handle Problem Language Result Execution time Memory
385836 2021-04-05T05:42:30 Z ParsaAlizadeh Gondola (IOI14_gondola) C++17
100 / 100
126 ms 6124 KB
#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;

typedef long long ll;

int const N = 2.5e5 + 10;
int const MOD = 1e9 + 9;

constexpr ll pw(ll a, ll b, ll mod) {
    return (!b    ? 1 :
            b & 1 ? a * pw(a * a % mod, b / 2, mod) % mod :
                    pw(a * a % mod, b / 2, mod));
}

int valid(int n, int inputSeq[]) {
    int st = -1;
    map<int, bool> mark;
    for (int i = 0; i < n; i++) {
        if (inputSeq[i] <= n) {
            if (st == -1)
                st = (inputSeq[i] - 1) - i + n;
            else if (inputSeq[i] - 1 != (st + i) % n)
                return 0;
        }
        if (mark[inputSeq[i]])
            return 0;
        mark[inputSeq[i]] = true;
    }
    return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
    int st = 0, l = 0;
    for (int i = 0; i < n; i++) {
        if (gondolaSeq[i] <= n)
            st = (gondolaSeq[i] - 1) - i + n;
        l = max(l, gondolaSeq[i]);
    }
    vector<int> ind(l + 1, -1), tmp(n, 0);
    for (int i = 0; i < n; i++) {
        ind[gondolaSeq[i]] = i;
        tmp[i] = 1 + (st + i) % n;
    }
    int ptr = 0;
    for (int i = n + 1; i <= l; i++) {
        while (ptr < n && tmp[ptr] == gondolaSeq[ptr])
            ptr++;
        int j = (ind[i] != -1 ? ind[i] : ptr);
        replacementSeq[i - n - 1] = tmp[j];
        tmp[j] = i;
    }
    return l - n;
}

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

int countReplacement(int n, int inputSeq[]) {
    if (!valid(n, inputSeq))
        return 0;
    set<int> st;
    for (int i = 0; i < n; i++) 
        if (inputSeq[i] > n)
            st.insert(inputSeq[i]);
    int t = st.size(), last = n;
    ll ans = (t == n ? n : 1);
    for (int x : st) {
        ans = ans * pw(t, x - last - 1, MOD) % MOD;
        t--;
        last = x;
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 15 ms 2412 KB Output is correct
7 Correct 11 ms 1132 KB Output is correct
8 Correct 32 ms 4332 KB Output is correct
9 Correct 9 ms 1772 KB Output is correct
10 Correct 36 ms 4972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 17 ms 2412 KB Output is correct
7 Correct 15 ms 1132 KB Output is correct
8 Correct 32 ms 4332 KB Output is correct
9 Correct 9 ms 1644 KB Output is correct
10 Correct 35 ms 4972 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 5 ms 748 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 11 ms 1132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 368 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 3 ms 364 KB Output is correct
11 Correct 12 ms 1644 KB Output is correct
12 Correct 12 ms 1900 KB Output is correct
13 Correct 14 ms 1260 KB Output is correct
14 Correct 11 ms 1388 KB Output is correct
15 Correct 24 ms 2320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 65 ms 4204 KB Output is correct
10 Correct 50 ms 3492 KB Output is correct
11 Correct 19 ms 1644 KB Output is correct
12 Correct 24 ms 1900 KB Output is correct
13 Correct 6 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 65 ms 4204 KB Output is correct
10 Correct 48 ms 3564 KB Output is correct
11 Correct 19 ms 1644 KB Output is correct
12 Correct 25 ms 1900 KB Output is correct
13 Correct 6 ms 748 KB Output is correct
14 Correct 86 ms 5356 KB Output is correct
15 Correct 126 ms 6124 KB Output is correct
16 Correct 15 ms 1388 KB Output is correct
17 Correct 62 ms 4204 KB Output is correct
18 Correct 32 ms 2540 KB Output is correct