Submission #802710

# Submission time Handle Problem Language Result Execution time Memory
802710 2023-08-02T13:33:03 Z BERNARB01 Gondola (IOI14_gondola) C++17
75 / 100
22 ms 2272 KB
#include <bits/stdc++.h>
#include "gondola.h"

using namespace std;

#ifdef B01
#include "../deb.h"
#else
#define deb(...)
#endif

const int md = 1000000009;

inline int mul(int a, int b) {
  return (int) ((long long) a * b % md);
}

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

//----------------------

int replacement(int n, int p[], int res[]) {
  int mxi = (int) (max_element(p, p + n) - p);
  int m = p[mxi] - n;
  vector<int> a(n);
  int s = (int) (min_element(p, p + n) - p);
  if (p[s] <= n) {
    for (int i = 0; i < n; i++) {
      a[(i + p[s] - 1) % n] = p[(s + i) % n];
    }
  } else {
    for (int i = 0; i < n; i++) {
      a[i] = p[i];
    }
  }
  mxi = (int) (max_element(a.begin(), a.end()) - a.begin());
  vector<int> at(a[mxi] + 1, -1);
  for (int i = 0; i < n; i++) {
    if (a[i] > n) {
      at[a[i]] = i + 1;
    }
  }
  at[a[mxi]] = -1;
  mxi++;
  for (int i = 0; i < m; i++) {
    int v = n + i + 1;
    if (at[v] == -1) {
      res[i] = mxi;
      mxi = v;
    } else {
      res[i] = at[v];
    }
  }
  return m;
}

//----------------------

int countReplacement(int n, int p[]) {
  if (!valid(n, p)) {
    return 0;
  }
  int m = *max_element(p, p + n) - n;
  if (m == 0) {
    return 1;
  }
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    a[i] = p[i];
  }
  sort(a.begin(), a.end());
  int ans = 1;
  for (int i = 0; i < m; i++) {
    int v = n + i + 1;
    auto it = lower_bound(a.begin(), a.end(), v);
    if (*it == v) {
      continue;
    }
    assert(it == upper_bound(a.begin(), a.end(), v));
    ans = mul(ans, (int) (a.end() - it));
  }
  return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 304 KB Output is correct
6 Correct 6 ms 724 KB Output is correct
7 Correct 12 ms 1500 KB Output is correct
8 Correct 9 ms 1212 KB Output is correct
9 Correct 4 ms 576 KB Output is correct
10 Correct 12 ms 1376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 6 ms 724 KB Output is correct
7 Correct 12 ms 1492 KB Output is correct
8 Correct 9 ms 1292 KB Output is correct
9 Correct 4 ms 596 KB Output is correct
10 Correct 13 ms 1420 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 6 ms 724 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 14 ms 1476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 0 ms 304 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 284 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 304 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 8 ms 1620 KB Output is correct
12 Correct 10 ms 1876 KB Output is correct
13 Correct 9 ms 1492 KB Output is correct
14 Correct 10 ms 1668 KB Output is correct
15 Correct 16 ms 2272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 312 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 22 ms 1352 KB Output is correct
10 Correct 17 ms 1124 KB Output is correct
11 Correct 11 ms 640 KB Output is correct
12 Correct 10 ms 692 KB Output is correct
13 Incorrect 6 ms 340 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 1 ms 216 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 22 ms 1364 KB Output is correct
10 Correct 17 ms 1124 KB Output is correct
11 Correct 11 ms 596 KB Output is correct
12 Correct 10 ms 596 KB Output is correct
13 Incorrect 5 ms 340 KB Output isn't correct
14 Halted 0 ms 0 KB -