답안 #102772

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
102772 2019-03-27T12:54:42 Z wxh010910 곤돌라 (IOI14_gondola) C++17
65 / 100
38 ms 2048 KB
#include <bits/stdc++.h>
#include "gondola.h"

using namespace std;

const int md = (int) 1e9 + 9;

inline int mul(int x, int y) {
  return (int) ((long long) x * y % md);
}

inline int power(int x, int y) {
  int res = 1;
  while (y) {
    if (y & 1) {
      res = mul(res, x);
    }
    x = mul(x, x);
    y >>= 1;
  }
  return res;
}

int valid(int n, int inputSeq[]) {
  vector<int> a(inputSeq, inputSeq + n);
  sort(a.begin(), a.end());
  if (unique(a.begin(), a.end()) != a.end()) {
    return 0;
  }
  int p = min_element(inputSeq, inputSeq + n) - inputSeq;
  for (int i = 0; i < n; ++i) {
    if (inputSeq[(p + i) % n] <= n && inputSeq[(p + i) % n] != inputSeq[p] + i) {
      return 0;
    }
  }
  return 1;
}

int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
  int p = max_element(gondolaSeq, gondolaSeq + n) - gondolaSeq;
  int m = gondolaSeq[p];
  vector<int> pos(m + 1, p);
  for (int i = 0; i < n; ++i) {
    pos[gondolaSeq[i]] = i;
  }
  for (int i = n + 1; i <= m; ++i) {
    replacementSeq[i - n - 1] = pos[i];
  }
  return m - n;
}

int countReplacement(int n, int inputSeq[]) {
  if (!valid(n, inputSeq)) {
    return 0;
  }
  sort(inputSeq, inputSeq + n);
  int ans = 1;
  if (inputSeq[0] > n) {
    ans = n;
  }
  for (int i = 0; i < n; ++i) {
    if (inputSeq[i] > n) {
      ans = mul(ans, power(n - i, inputSeq[i] - max(n, i ? inputSeq[i - 1] : n) - 1));
    }
  }
  return ans;
}
# 결과 실행 시간 메모리 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 3 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 2 ms 384 KB Output is correct
6 Correct 9 ms 768 KB Output is correct
7 Correct 18 ms 1536 KB Output is correct
8 Correct 12 ms 1280 KB Output is correct
9 Correct 7 ms 640 KB Output is correct
10 Correct 17 ms 1408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 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 384 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 12 ms 768 KB Output is correct
7 Correct 19 ms 1536 KB Output is correct
8 Correct 18 ms 1276 KB Output is correct
9 Correct 7 ms 640 KB Output is correct
10 Correct 20 ms 1408 KB Output is correct
11 Correct 15 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 11 ms 896 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 22 ms 1536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 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
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 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 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 32 ms 1400 KB Output is correct
10 Correct 20 ms 1272 KB Output is correct
11 Correct 8 ms 640 KB Output is correct
12 Correct 11 ms 768 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 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 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 2 ms 384 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 24 ms 1408 KB Output is correct
10 Correct 24 ms 1152 KB Output is correct
11 Correct 11 ms 684 KB Output is correct
12 Correct 12 ms 768 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 38 ms 1784 KB Output is correct
15 Correct 35 ms 2048 KB Output is correct
16 Correct 11 ms 632 KB Output is correct
17 Correct 23 ms 1408 KB Output is correct
18 Correct 14 ms 896 KB Output is correct