답안 #469599

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
469599 2021-09-01T12:12:30 Z Soumya1 곤돌라 (IOI14_gondola) C++17
100 / 100
68 ms 5904 KB
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 9;
int valid(int n, int a[]) {
  bool ok = true;
  map<int, bool> mp;
  for (int i = 0; i < n; i++) {
    ok &= (!mp[a[i]]);
    mp[a[i]] = true;
  }
  int pos = -1, val = -1;
  for (int i = 0; i < n; i++) {
    if (a[i] <= n) {
      val = a[i];
      pos = i;
      break;
    }
  }
  val++;
  if (val > n) val = 1;
  for (int i = pos + 1; i < n; i++) {
    if (a[i] <= n) {
      ok &= (a[i] == val);
    }
    val++;
    if (val > n) val = 1;
  }
  for (int i = 0; i < pos; i++) {
    if (a[i] <= n) {
      ok &= (a[i] == val);
    }
    val++;
    if (val > n) val = 1;
  }
  return (int) ok;
}
int replacement(int n, int a[], int ans[]) {
  int pos = -1, val = -1;
  for (int i = 0; i < n; i++) {
    if (a[i] <= n) {
      pos = i;
      val = a[i];
      break;
    }
  }
  vector<pair<int, int>> v;
  for (int i = 0; i < n; i++) {
    if (a[i] > n) v.push_back({a[i], i});
  }
  if (pos != -1) {
    for (int i = pos; i < n; i++) {
      a[i] = val++;
      if (val > n) val = 1;
    }
    for (int i = 0; i < pos; i++) {
      a[i] = val++;
      if (val > n) val = 1;
    }
  } else {
    for (int i = 0; i < n; i++) a[i] = i + 1;
  }
  int ptr = 0;
  sort(v.begin(), v.end());
  int cur = n + 1;
  for (int i = 0; i < v.size(); i++) {
    while (cur <= v[i].first) {
      ans[ptr++] = a[v[i].second];
      a[v[i].second] = cur++;
    }
  }
  return ptr;
}
int bigmod(int a, int b) {
  a %= mod;
  int res = 1;
  while (b > 0) {
    if (b & 1) res = (1LL * res * a) % mod;
    a = (1LL * a * a) % mod, b >>= 1;
  }
  return res;
}
int countReplacement(int n, int a[]) {
  if (!valid(n, a)) return 0;
  int ans = 1;
  sort(a, a + n);
  int last = n;
  for (int i = 0; i < n; i++) {
    if (a[i] > n) {
      if (i == 0) ans = (1LL * ans * n) % mod;
      ans = (1LL * ans * bigmod(n - i, a[i] - last - 1)) % mod;
      last = a[i];
    }
  }
  return ans;
}

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:66:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |   for (int i = 0; i < v.size(); i++) {
      |                   ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 14 ms 2180 KB Output is correct
7 Correct 37 ms 3640 KB Output is correct
8 Correct 30 ms 3856 KB Output is correct
9 Correct 9 ms 1344 KB Output is correct
10 Correct 40 ms 4428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 16 ms 2124 KB Output is correct
7 Correct 39 ms 3672 KB Output is correct
8 Correct 29 ms 3912 KB Output is correct
9 Correct 9 ms 1408 KB Output is correct
10 Correct 38 ms 4420 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 19 ms 1996 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 47 ms 4556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 216 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 9 ms 588 KB Output is correct
12 Correct 10 ms 588 KB Output is correct
13 Correct 16 ms 1276 KB Output is correct
14 Correct 10 ms 536 KB Output is correct
15 Correct 23 ms 2216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 48 ms 4400 KB Output is correct
10 Correct 41 ms 3780 KB Output is correct
11 Correct 14 ms 1596 KB Output is correct
12 Correct 17 ms 1740 KB Output is correct
13 Correct 4 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 224 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 47 ms 4420 KB Output is correct
10 Correct 37 ms 3756 KB Output is correct
11 Correct 15 ms 1640 KB Output is correct
12 Correct 17 ms 1816 KB Output is correct
13 Correct 4 ms 588 KB Output is correct
14 Correct 61 ms 5280 KB Output is correct
15 Correct 68 ms 5904 KB Output is correct
16 Correct 11 ms 1276 KB Output is correct
17 Correct 47 ms 4164 KB Output is correct
18 Correct 23 ms 2396 KB Output is correct