답안 #272750

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
272750 2020-08-18T15:04:22 Z toonewbie 곤돌라 (IOI14_gondola) C++17
100 / 100
59 ms 6008 KB
#include "gondola.h"
#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second

const int N = 100005;
const int MOD = 1000000009;

int valid(int n, int A[]) {
    set <int> S(A, A + n);
    if (S.size() != n) return 0;
    for (int i = 0, k = -MOD; i < n; i++) {
        if (A[i] <= n) {
            if (k == -MOD) 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 = -MOD, ptr = 0;
    vector <int> B(N);
    for (int i = 0; i < n; i++) {
        if (A[i] <= n) {
            k = (A[i] - i - 1 + n) % n;
        }
    }
    vector <pair <int, int>> v;
    for(int i = 0; i < n; i++) {
        if (k == -MOD) B[i] = A[i];
        else B[i] = A[(i - k + n) % n];
        if (B[i] > n) v.push_back({B[i], i + 1});
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < v.size(); i++) {
        while (ptr + n < v[i].F) {
            ret[ptr++] = v[i].S;
            v[i].S = ptr + n;
        }
    }
    return ptr;
}

int modpow(int a, int b) {
    int ret = 1;
    for (; b; b >>= 1) {
        if (b & 1) ret = 1LL * ret * a % MOD;
        a = 1LL * a * a % MOD;
    }
    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.push_back(A[i]);
    sort (v.begin(), v.end());
    int ans = 1;
    for (int i = 0; i < v.size(); i++) {
        int b = v.size() - i;
        int p = v[i] - (i ? v[i - 1] + 1 : n + 1);
        ans = 1LL * ans * modpow(b, p) % MOD;
    }
    if (v.size() == n) ans = 1LL * ans * n % MOD;
    return ans;
}

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:14:18: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   14 |     if (S.size() != n) return 0;
      |                  ^
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:39:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     for (int i = 0; i < v.size(); i++) {
      |                     ~~^~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:63:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |     for (int i = 0; i < v.size(); i++) {
      |                     ~~^~~~~~~~~~
gondola.cpp:68:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   68 |     if (v.size() == n) ans = 1LL * ans * n % MOD;
      |         ~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 10 ms 2432 KB Output is correct
7 Correct 32 ms 4216 KB Output is correct
8 Correct 24 ms 4352 KB Output is correct
9 Correct 6 ms 1536 KB Output is correct
10 Correct 22 ms 5076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 416 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 12 ms 2432 KB Output is correct
7 Correct 32 ms 4224 KB Output is correct
8 Correct 25 ms 4352 KB Output is correct
9 Correct 6 ms 1664 KB Output is correct
10 Correct 27 ms 4992 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 21 ms 2296 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 48 ms 5248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 768 KB Output is correct
2 Correct 1 ms 768 KB Output is correct
3 Correct 1 ms 768 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 1 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 768 KB Output is correct
2 Correct 1 ms 768 KB Output is correct
3 Correct 1 ms 768 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 1 ms 768 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 1 ms 768 KB Output is correct
8 Correct 2 ms 768 KB Output is correct
9 Correct 1 ms 800 KB Output is correct
10 Correct 2 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 768 KB Output is correct
2 Correct 1 ms 768 KB Output is correct
3 Correct 1 ms 768 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 1 ms 768 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 1 ms 768 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 1 ms 768 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Correct 11 ms 1536 KB Output is correct
12 Correct 13 ms 1664 KB Output is correct
13 Correct 17 ms 1660 KB Output is correct
14 Correct 11 ms 1536 KB Output is correct
15 Correct 25 ms 2416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 48 ms 4600 KB Output is correct
10 Correct 32 ms 3832 KB Output is correct
11 Correct 12 ms 1664 KB Output is correct
12 Correct 15 ms 1920 KB Output is correct
13 Correct 5 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 42 ms 4632 KB Output is correct
10 Correct 32 ms 3832 KB Output is correct
11 Correct 12 ms 1664 KB Output is correct
12 Correct 15 ms 1920 KB Output is correct
13 Correct 4 ms 640 KB Output is correct
14 Correct 51 ms 5368 KB Output is correct
15 Correct 59 ms 6008 KB Output is correct
16 Correct 11 ms 1408 KB Output is correct
17 Correct 40 ms 4216 KB Output is correct
18 Correct 24 ms 2552 KB Output is correct