Submission #501870

# Submission time Handle Problem Language Result Execution time Memory
501870 2022-01-04T17:46:42 Z 600Mihnea Fish (IOI08_fish) C++17
70 / 100
3000 ms 42436 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct Fish {
  int sz;
  int tp;
};

bool operator < (Fish a, Fish b) {
  return a.sz < b.sz;
}

const int N = (int) 5e5 + 7;
int n, k, mod;
Fish a[N];
vector<int> aux[N], oftp[N];

int caneat(int f, int s) {
  int low = 0, high = (int) oftp[s].size() - 1, sol = 0;
  while (low <= high) {
    int mid = (low + high) / 2;
    if (a[oftp[f].back()].sz >= 2 * a[oftp[s][mid]].sz) {
      sol = mid + 1;
      low = mid + 1;
    } else {
      high = mid - 1;
    }
  }
  return sol;
}

int aux_order[N];

bool cmp(int i, int j) {
  return aux[i].back() < aux[j].back();
}

int main() {
  ios::sync_with_stdio(0); cin.tie(0);

  cin >> n >> k >> mod;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].sz >> a[i].tp;
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    aux[a[i].tp].push_back(i);
  }
  n = k;
  for (int i = 1; i <= n; i++) {
    aux_order[i] = i;
  }

  sort(aux_order + 1, aux_order + n + 1, cmp);
  for (int i = 1; i <= n; i++) oftp[i] = aux[aux_order[i]];
  for (int i = 1; i <= n; i++) aux[i] = oftp[i];


/**

0 0 0
1 0 1
1 1 1

type 1 can eat :
type 2 can eat : 1 3
type 3 can eat : 1 2 3


**/
  int print = 0;
  for (int i = n; i >= 1; i--) {
    /**

    count all new representations that can be eaten by the fish i
    aka all representations that can be eaten by fish i and not by a fish bigger than him
    let's look at what restrictions the other fish impose on fish j
    only the bigger fish than him impose restrictions
    **/

    int full = 1, semi = caneat(i, i);
    for (int j = i + 1; j <= n; j++) {
      if (caneat(j, i) >= caneat(i, i) + 1) {
        /// I can eat only 0 j
        continue;
      }
      /// I can eat 0 j (available always)
      /// I can eat any amount of fish j if I ...
      full = full * (ll) (caneat(i, j) + 1) % mod;
    ///  assert(caneat(j, i) == caneat(i, i));
    }
    int sol = 1;
    for (int j = 1; j < i; j++) {
      sol = sol * (ll) (caneat(i, j) + 1) % mod;
    }
    full = full * (ll) sol % mod;
    semi = semi * (ll) sol % mod;

    print = (print + full) % mod;
    print = (print + semi) % mod;
  }
  cout << print << "\n";

  return 0;
}

/**
**/
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23756 KB Output is correct
2 Correct 13 ms 23796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23720 KB Output is correct
2 Correct 139 ms 33292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 28676 KB Output is correct
2 Correct 77 ms 31652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 23884 KB Output is correct
2 Correct 30 ms 23952 KB Output is correct
3 Correct 44 ms 24000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 201 ms 30672 KB Output is correct
2 Correct 401 ms 39216 KB Output is correct
3 Correct 405 ms 40048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 211 ms 33944 KB Output is correct
2 Correct 581 ms 39852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 440 ms 30720 KB Output is correct
2 Correct 2465 ms 34428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3014 ms 33680 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 3061 ms 34656 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 3068 ms 33432 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3061 ms 38952 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3096 ms 41860 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3019 ms 42436 KB Time limit exceeded
2 Halted 0 ms 0 KB -