답안 #107958

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
107958 2019-04-26T10:31:13 Z PeppaPig 곤돌라 (IOI14_gondola) C++14
70 / 100
104 ms 6136 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;
    if(k == -M) iota(B, B+n, 1);
    else for(int i = 0; i < n; i++) {
        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;
}
# 결과 실행 시간 메모리 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 3 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 10 ms 2432 KB Output is correct
7 Correct 45 ms 4088 KB Output is correct
8 Correct 35 ms 4312 KB Output is correct
9 Correct 12 ms 1536 KB Output is correct
10 Correct 26 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 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 15 ms 2432 KB Output is correct
7 Correct 42 ms 4216 KB Output is correct
8 Correct 24 ms 4352 KB Output is correct
9 Correct 7 ms 1664 KB Output is correct
10 Correct 27 ms 4984 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 23 ms 2304 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 60 ms 5240 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 384 KB Output is correct
5 Correct 2 ms 384 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 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 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Incorrect 3 ms 384 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 284 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Incorrect 2 ms 256 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 256 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 512 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 432 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 256 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 59 ms 4600 KB Output is correct
10 Correct 43 ms 3832 KB Output is correct
11 Correct 15 ms 1664 KB Output is correct
12 Correct 21 ms 1920 KB Output is correct
13 Correct 6 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 3 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 3 ms 384 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 65 ms 4476 KB Output is correct
10 Correct 51 ms 3964 KB Output is correct
11 Correct 21 ms 1536 KB Output is correct
12 Correct 20 ms 1920 KB Output is correct
13 Correct 6 ms 768 KB Output is correct
14 Correct 96 ms 5340 KB Output is correct
15 Correct 104 ms 6136 KB Output is correct
16 Correct 17 ms 1408 KB Output is correct
17 Correct 61 ms 4216 KB Output is correct
18 Correct 27 ms 2552 KB Output is correct