제출 #102772

#제출 시각아이디문제언어결과실행 시간메모리
102772wxh010910곤돌라 (IOI14_gondola)C++17
65 / 100
38 ms2048 KiB
#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;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...