Submission #107963

# Submission time Handle Problem Language Result Execution time Memory
107963 2019-04-26T10:53:21 Z PeppaPig Gondola (IOI14_gondola) C++14
100 / 100
92 ms 5112 KB
#include "gondola.h"
#include <bits/stdc++.h>

#define long long long
#define pii pair<int, int>
#define x first
#define y second

using namespace std;

const int N = 1e5+5;
const int M = 1e9+9;

int valid(int n, int A[]) {
    set<int> S(A, A + n);
    if((int)S.size() != n) return 0;
    for(int i = 0, k = -M; i < n; i++) if(A[i] <= n) {
        if(k == -M) k = (A[i] - i - 1 + n) % n;
        else if(k != (A[i] - i - 1 + n) % n) return 0;
    }
    return 1;
}

int replacement(int n, int A[], int ret[]) {
    int k = -M, ptr = 0, B[N];
    for(int i = 0; i < n; i++) if(A[i] <= n) k = (A[i] - i - 1 + n) % n;

    vector<pii> v;
    for(int i = 0; i < n; i++) {
        if(k == -M) B[i] = A[i];
        else B[i] = A[(i - k + n) % n];
        if(B[i] > n) v.emplace_back(B[i], i+1);
    }
    sort(v.begin(), v.end());
    for(int i = 0; i < (int)v.size(); i++) while(ptr + n < v[i].x) {
        ret[ptr++] = v[i].y;
        v[i].y = ptr + n;
    }
    return ptr;
}

long modpow(long a, long b) {
    long ret = 1;
    for( ; b; b >>= 1) {
        if(b & 1) ret = (ret * a) % M;
        a = (a * a) % M;
    }
    return ret;
}

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

    vector<int> v;
    for(int i = 0; i < n; i++) if(A[i] > n) v.emplace_back(A[i]);
    sort(v.begin(), v.end());

    long ans = 1;
    for(int i = 0; i < (int)v.size(); i++) {
        int b = v.size() - i;
        int p = v[i] - (i ? v[i-1] + 1 : n + 1);
        ans = (ans * modpow(b, p)) % M;
    }
    if((int)v.size() == n) ans = (ans * n) % M;

    return ans;
}
# Verdict Execution time Memory 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 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 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 2 ms 384 KB Output is correct
6 Correct 13 ms 2304 KB Output is correct
7 Correct 54 ms 3708 KB Output is correct
8 Correct 26 ms 3968 KB Output is correct
9 Correct 8 ms 1536 KB Output is correct
10 Correct 25 ms 4608 KB Output is correct
# Verdict Execution time Memory 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 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 15 ms 2176 KB Output is correct
7 Correct 35 ms 3704 KB Output is correct
8 Correct 23 ms 3968 KB Output is correct
9 Correct 7 ms 1536 KB Output is correct
10 Correct 23 ms 4608 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 4 ms 256 KB Output is correct
13 Correct 21 ms 2268 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 73 ms 4728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 380 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory 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 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 256 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 15 ms 1152 KB Output is correct
12 Correct 15 ms 1152 KB Output is correct
13 Correct 18 ms 1552 KB Output is correct
14 Correct 12 ms 1144 KB Output is correct
15 Correct 20 ms 2424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory 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 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 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 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 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 2 ms 256 KB Output is correct
9 Correct 51 ms 4092 KB Output is correct
10 Correct 44 ms 3468 KB Output is correct
11 Correct 14 ms 1408 KB Output is correct
12 Correct 19 ms 1792 KB Output is correct
13 Correct 5 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 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 2 ms 256 KB Output is correct
9 Correct 55 ms 4020 KB Output is correct
10 Correct 34 ms 3456 KB Output is correct
11 Correct 13 ms 1408 KB Output is correct
12 Correct 16 ms 1664 KB Output is correct
13 Correct 6 ms 640 KB Output is correct
14 Correct 90 ms 4576 KB Output is correct
15 Correct 92 ms 5112 KB Output is correct
16 Correct 14 ms 1280 KB Output is correct
17 Correct 47 ms 3664 KB Output is correct
18 Correct 27 ms 2176 KB Output is correct