답안 #102776

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
102776 2019-03-27T13:08:34 Z wxh010910 곤돌라 (IOI14_gondola) C++17
100 / 100
31 ms 2204 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 q = min_element(gondolaSeq, gondolaSeq + n) - gondolaSeq;
  if (gondolaSeq[q] <= n) {
    q = (q - (gondolaSeq[q] - 1) + n) % n;
  }
  int p = max_element(gondolaSeq, gondolaSeq + n) - gondolaSeq;
  int m = gondolaSeq[p];
  vector<int> pos(m + 1, -1);
  for (int i = 0; i < n; ++i) {
    pos[gondolaSeq[i]] = (i - q + n) % n + 1; 
  }
  for (int i = n + 1; i <= m; ++i) {
    if (pos[i] != -1) {
      replacementSeq[i - n - 1] = pos[i];
    } else {
      replacementSeq[i - n - 1] = pos[m];
      pos[m] = 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 2 ms 256 KB Output is correct
5 Correct 2 ms 256 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 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 10 ms 640 KB Output is correct
7 Correct 17 ms 1024 KB Output is correct
8 Correct 17 ms 896 KB Output is correct
9 Correct 6 ms 512 KB Output is correct
10 Correct 17 ms 1024 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 2 ms 384 KB Output is correct
6 Correct 9 ms 640 KB Output is correct
7 Correct 18 ms 1024 KB Output is correct
8 Correct 14 ms 896 KB Output is correct
9 Correct 7 ms 640 KB Output is correct
10 Correct 31 ms 1024 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 356 KB Output is correct
13 Correct 9 ms 640 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 19 ms 1024 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 412 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 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 3 ms 256 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 300 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 512 KB Output is correct
5 Correct 3 ms 356 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 13 ms 1408 KB Output is correct
12 Correct 14 ms 1536 KB Output is correct
13 Correct 14 ms 1408 KB Output is correct
14 Correct 12 ms 1408 KB Output is correct
15 Correct 21 ms 2204 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 3 ms 256 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 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 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 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 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 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 24 ms 896 KB Output is correct
10 Correct 22 ms 768 KB Output is correct
11 Correct 9 ms 512 KB Output is correct
12 Correct 12 ms 484 KB Output is correct
13 Correct 5 ms 512 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 256 KB Output is correct
4 Correct 2 ms 384 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 356 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 23 ms 896 KB Output is correct
10 Correct 19 ms 768 KB Output is correct
11 Correct 11 ms 512 KB Output is correct
12 Correct 10 ms 512 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 28 ms 1024 KB Output is correct
15 Correct 30 ms 1024 KB Output is correct
16 Correct 7 ms 384 KB Output is correct
17 Correct 29 ms 896 KB Output is correct
18 Correct 13 ms 640 KB Output is correct