답안 #730235

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
730235 2023-04-25T12:43:44 Z becaido 곤돌라 (IOI14_gondola) C++17
100 / 100
32 ms 5348 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;

const int MAX = 2.5e5 + 5;
bitset<MAX> is;
int valid(int n, int a[]) {
    int shift = -1;
    for (int i = 0; i < n; i++) {
        if (a[i] <= n) {
            if (shift == -1) shift = (a[i] - 1 - i + n) % n;
            else if ((a[i] - 1 - i + n) % n != shift) return 0;
        }
        if (is[a[i]]) return 0;
        is[a[i]] = 1;
    }
    return 1;
}

int p[MAX];
int replacement(int n, int a[], int b[]) {
    int mx = *max_element(a, a + n);
    fill(p + 1, p + mx + 1, -1);
    int shift = -1;
    for (int i = 0; i < n; i++) {
        p[a[i]] = i;
        if (a[i] <= n && shift == -1) shift = (a[i] - 1 - i + n) % n;
    }
    if (shift == -1) shift = 0;
    for (int i = 1; i <= n; i++) p[i] = (i - 1 - shift + n) % n;
    for (int i = n + 1; i <= mx; i++) if (p[i] == -1) p[i] = p[mx];
    for (int i = 1; i <= n; i++) a[p[i]] = i;
    int sz = 0;
    for (int i = n + 1; i <= mx; i++) b[sz++] = a[p[i]], a[p[i]] = i;
    return sz;
}

const int MOD = 1e9 + 9;
inline int power(int d, int up) {
    int re = 1;
    while (up) {
        if (up & 1) re = 1ll * re * d % MOD;
        d = 1ll * d * d % MOD;
        up >>= 1;
    }
    return re;
}
int countReplacement(int n, int a[]) {
    int shift = -1;
    unordered_set<int> us;
    for (int i = 0; i < n; i++) {
        if (us.count(a[i])) return 0;
        if (a[i] <= n) {
            if (shift == -1) shift = (a[i] - 1 - i + n) % n;
            else if ((a[i] - 1 - i + n) % n != shift) return 0;
        }
        us.insert(a[i]);
    }
    int ans = (shift == -1 ? n : 1), cnt = 0;
    sort(a, a + n);
    for (int i = 0; i < n; i++) if (a[i] > n) {
        if (i == 0 || a[i - 1] <= n) {
            cnt = n - i;
            ans = 1ll * ans * power(cnt, a[i] - n - 1) % MOD;
        } else {
            ans = 1ll * ans * power(cnt, a[i] - a[i - 1] - 1) % MOD;
        }
        cnt--;
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 8 ms 604 KB Output is correct
8 Correct 10 ms 484 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 9 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 8 ms 596 KB Output is correct
8 Correct 11 ms 596 KB Output is correct
9 Correct 4 ms 340 KB Output is correct
10 Correct 9 ms 604 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 4 ms 468 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 8 ms 608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 9 ms 920 KB Output is correct
12 Correct 10 ms 1032 KB Output is correct
13 Correct 12 ms 1528 KB Output is correct
14 Correct 9 ms 920 KB Output is correct
15 Correct 19 ms 2832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 23 ms 3556 KB Output is correct
10 Correct 21 ms 3044 KB Output is correct
11 Correct 7 ms 1492 KB Output is correct
12 Correct 8 ms 1584 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 22 ms 3504 KB Output is correct
10 Correct 19 ms 3044 KB Output is correct
11 Correct 8 ms 1516 KB Output is correct
12 Correct 8 ms 1576 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 32 ms 3876 KB Output is correct
15 Correct 32 ms 5348 KB Output is correct
16 Correct 5 ms 980 KB Output is correct
17 Correct 26 ms 3220 KB Output is correct
18 Correct 12 ms 1840 KB Output is correct