답안 #253864

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
253864 2020-07-29T00:13:54 Z ChrisT 곤돌라 (IOI14_gondola) C++17
100 / 100
67 ms 6008 KB
#include<bits/stdc++.h>
using namespace std;
#include "gondola.h"
const int MOD = 1e9 + 9;
int valid (int n, int *a) {
  set<int> seen;
  for (int i = 0; i < n; i++) {
    if (seen.count(a[i])) return 0;
    seen.insert(a[i]);
  }
  for (int i = 0; i < n; i++) {
    if (a[i] <= n) {
      for (int j = (i+1)%n, cur = a[i]%n+1; j != i; j = (j + 1) % n, cur = cur % n + 1) {
        if (a[j] <= n && a[j] != cur) return 0;
      }
      return 1;
    }
  }
  return 1;
} 
int replacement (int n, int *a, int *ret) {
  vector<int> pos(250001,-1), cur(n); int mx = 0;
  for (int i = 0; i < n; i++) if (a[i] <= n) {
    cur[i] = a[i];
    for (int j = (i+1)%n, go = a[i]%n+1; j != i; j = (j + 1) % n, go = go % n + 1) cur[j] = go;
    break;
  }
  if (!cur[0]) for (int i = 0; i < n; i++) cur[i] = i+1;
  for (int i = 0; i < n; i++) {
    pos[a[i]] = i;
    if (a[i] > a[mx]) mx = i;
  }
  int pp = 0;
  for (int i = n+1; i <= a[mx]; i++) {
    if (~pos[i]) ret[pp++] = cur[pos[i]], cur[pos[i]] = i;
    else ret[pp++] = cur[mx], cur[mx] = i;
  }
  return pp;
}
int fpow (int base, int exp) {
  int res = 1;
  while (exp) {
    if (exp&1) res = 1LL * res * base % MOD;
    base = 1LL * base * base % MOD;
    exp >>= 1;
  }
  return res;
}
int countReplacement (int n, int *a) {
  if (!valid(n,a)) return 0;
  sort(a,a+n);
  int lst = n, ret = 1;
  for (int i = 0; i < n; i++) if (a[i] > n) {
    ret = ret * 1LL * fpow(n-i,a[i]-lst-1) % MOD;
    lst = a[i];
  }
  if(a[0]>n)ret=ret*1LL*n%MOD;
  return ret;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 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 0 ms 384 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 256 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 15 ms 2432 KB Output is correct
7 Correct 13 ms 1152 KB Output is correct
8 Correct 31 ms 4300 KB Output is correct
9 Correct 9 ms 1664 KB Output is correct
10 Correct 36 ms 4984 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 0 ms 384 KB Output is correct
6 Correct 14 ms 2432 KB Output is correct
7 Correct 13 ms 1152 KB Output is correct
8 Correct 28 ms 4352 KB Output is correct
9 Correct 9 ms 1664 KB Output is correct
10 Correct 35 ms 4984 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 21 ms 2304 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 49 ms 5240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1280 KB Output is correct
2 Correct 1 ms 1280 KB Output is correct
3 Correct 1 ms 1280 KB Output is correct
4 Correct 1 ms 1280 KB Output is correct
5 Correct 1 ms 1280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1280 KB Output is correct
2 Correct 1 ms 1280 KB Output is correct
3 Correct 1 ms 1280 KB Output is correct
4 Correct 1 ms 1280 KB Output is correct
5 Correct 1 ms 1280 KB Output is correct
6 Correct 1 ms 1280 KB Output is correct
7 Correct 1 ms 1280 KB Output is correct
8 Correct 1 ms 1280 KB Output is correct
9 Correct 1 ms 1280 KB Output is correct
10 Correct 2 ms 1280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1280 KB Output is correct
2 Correct 1 ms 1280 KB Output is correct
3 Correct 1 ms 1280 KB Output is correct
4 Correct 1 ms 1280 KB Output is correct
5 Correct 1 ms 1280 KB Output is correct
6 Correct 1 ms 1280 KB Output is correct
7 Correct 1 ms 1280 KB Output is correct
8 Correct 2 ms 1280 KB Output is correct
9 Correct 2 ms 1280 KB Output is correct
10 Correct 1 ms 1280 KB Output is correct
11 Correct 13 ms 2432 KB Output is correct
12 Correct 15 ms 2560 KB Output is correct
13 Correct 14 ms 2048 KB Output is correct
14 Correct 19 ms 2296 KB Output is correct
15 Correct 21 ms 2212 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 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 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 0 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 1 ms 384 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 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 0 ms 256 KB Output is correct
9 Correct 50 ms 4472 KB Output is correct
10 Correct 42 ms 3832 KB Output is correct
11 Correct 14 ms 1536 KB Output is correct
12 Correct 17 ms 1920 KB Output is correct
13 Correct 4 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 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 1 ms 384 KB Output is correct
7 Correct 1 ms 372 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 52 ms 4472 KB Output is correct
10 Correct 41 ms 3840 KB Output is correct
11 Correct 14 ms 1664 KB Output is correct
12 Correct 18 ms 1944 KB Output is correct
13 Correct 4 ms 640 KB Output is correct
14 Correct 60 ms 5368 KB Output is correct
15 Correct 67 ms 6008 KB Output is correct
16 Correct 11 ms 1408 KB Output is correct
17 Correct 45 ms 4224 KB Output is correct
18 Correct 25 ms 2432 KB Output is correct