답안 #362513

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
362513 2021-02-03T13:00:19 Z Pety 곤돌라 (IOI14_gondola) C++14
100 / 100
58 ms 5100 KB
#include <bits/stdc++.h>
#include "gondola.h"

using namespace std;

const int mod = 1e9 + 9;

long long logpow (long long a, long long b) {
  long long p = 1;
  while (b) {
    if (b & 1)
      p = 1ll * p * a % mod;
    a = 1ll * a * a % mod;
    (b >>= 1);
  }
  return p;
}

int valid (int n, int inputSeq[]) {
  vector<int>f;
  int poz = 0;
  for (int i = 0; i < n; i++) {
    int next = (i + 1) % n;
    if (inputSeq[i] <= n) {
      poz = i;
    }
    if (inputSeq[i] <= n && inputSeq[next] <= n) {
      if (inputSeq[i] == n && inputSeq[next] != 1)
        return 0;
      else if (inputSeq[i] < n && inputSeq[next] != inputSeq[i] + 1)
        return 0;
    }
  }
  int val = inputSeq[poz];
  for (int i = 1; i <= n; i++) {
    if (inputSeq[poz] != val && inputSeq[poz] <= n)
      return 0;
    val = (val + 1) % n;
    if (!val) val = n;
    poz = (poz + 1) % n;
  }
  sort(inputSeq, inputSeq + n);
  for (int i = 0; i < n - 1; i++)
    if (inputSeq[i] == inputSeq[i + 1])
      return 0;
  return 1;
}

int replacement (int n, int inputSeq[], int replacementSeq[]) {
  vector<int>f, pozFinal, poz;
  f.resize(250002);
  pozFinal.resize(250002);
  poz.resize(250002);
  int mx = 0;
  int start = 0;
  for (int i = 0; i < n; i++) {
    f[inputSeq[i]] = 1;
    if (inputSeq[i] <= n)
      start = (i - inputSeq[i] + 1 + n) % n;
    pozFinal[inputSeq[i]] = i;
    mx = max(mx, inputSeq[i]);
  }
  set<int>s;
  for (int i = 1; i <= n; i++) {
    inputSeq[start] = i;
    poz[i] = start;
    start = (start + 1) % n;
    if (!f[i])
      s.insert(i);
  }
  int l = 0;
  int next = n + 1;
  for (int i = 1; i <= mx - n; i++) {
    if (f[next]) {
      replacementSeq[i - 1] = inputSeq[pozFinal[next]];
      s.erase(replacementSeq[i - 1]);
    }
    else {
      replacementSeq[i - 1] = *s.begin();
      s.erase(replacementSeq[i - 1]);
      s.insert(next);
      inputSeq[poz[replacementSeq[i - 1]]] = next;
      poz[next] = poz[replacementSeq[i - 1]];
    }
    next++;
  }
  return mx - n;
}

int countReplacement (int n, int inputSeq[]) {
  if (!valid(n, inputSeq))
    return 0;
  int mx = 0;
  bool meh = 0;
  vector<int> fixat;
  int saiz = n;
  for (int i = 0; i < n; i++) {
    if (inputSeq[i] <= n) {
      meh = 1;
      saiz--;
    }
    else
      fixat.push_back(inputSeq[i]);
  }
  sort(fixat.begin(), fixat.end());
  long long ans = 1;
  int last = n + 1;
  for (int i = 0; i < fixat.size(); i++) {
    ans = 1ll * ans * logpow(saiz, fixat[i] - last) % mod;
    saiz--;
    last = fixat[i] + 1;
  }
  return ((meh == 0) ? n : 1) * ans % mod;
}

/*int main ()
{
  int aux[] = {3, 4};
  cout << countReplacement(2, aux);
  return 0;
}*/


Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:71:7: warning: unused variable 'l' [-Wunused-variable]
   71 |   int l = 0;
      |       ^
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:108:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |   for (int i = 0; i < fixat.size(); i++) {
      |                   ~~^~~~~~~~~~~~~~
gondola.cpp:93:7: warning: unused variable 'mx' [-Wunused-variable]
   93 |   int mx = 0;
      |       ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 8 ms 492 KB Output is correct
7 Correct 11 ms 620 KB Output is correct
8 Correct 13 ms 620 KB Output is correct
9 Correct 5 ms 364 KB Output is correct
10 Correct 18 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 8 ms 492 KB Output is correct
7 Correct 11 ms 620 KB Output is correct
8 Correct 13 ms 620 KB Output is correct
9 Correct 5 ms 364 KB Output is correct
10 Correct 19 ms 620 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 5 ms 492 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 12 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3308 KB Output is correct
2 Correct 2 ms 3308 KB Output is correct
3 Correct 2 ms 3328 KB Output is correct
4 Correct 2 ms 3308 KB Output is correct
5 Correct 2 ms 3308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3308 KB Output is correct
2 Correct 2 ms 3308 KB Output is correct
3 Correct 2 ms 3308 KB Output is correct
4 Correct 2 ms 3308 KB Output is correct
5 Correct 2 ms 3308 KB Output is correct
6 Correct 2 ms 3308 KB Output is correct
7 Correct 3 ms 3308 KB Output is correct
8 Correct 3 ms 3308 KB Output is correct
9 Correct 3 ms 3308 KB Output is correct
10 Correct 3 ms 3308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3308 KB Output is correct
2 Correct 2 ms 3200 KB Output is correct
3 Correct 2 ms 3308 KB Output is correct
4 Correct 1 ms 3308 KB Output is correct
5 Correct 2 ms 3308 KB Output is correct
6 Correct 2 ms 3308 KB Output is correct
7 Correct 3 ms 3308 KB Output is correct
8 Correct 5 ms 3308 KB Output is correct
9 Correct 3 ms 3308 KB Output is correct
10 Correct 3 ms 3308 KB Output is correct
11 Correct 12 ms 3564 KB Output is correct
12 Correct 14 ms 3564 KB Output is correct
13 Correct 36 ms 5100 KB Output is correct
14 Correct 12 ms 3564 KB Output is correct
15 Correct 58 ms 4844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 18 ms 1004 KB Output is correct
10 Correct 15 ms 1004 KB Output is correct
11 Correct 6 ms 620 KB Output is correct
12 Correct 7 ms 620 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 18 ms 1004 KB Output is correct
10 Correct 15 ms 1004 KB Output is correct
11 Correct 6 ms 620 KB Output is correct
12 Correct 7 ms 620 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 23 ms 1256 KB Output is correct
15 Correct 34 ms 2280 KB Output is correct
16 Correct 5 ms 748 KB Output is correct
17 Correct 17 ms 1644 KB Output is correct
18 Correct 10 ms 1260 KB Output is correct