Submission #810835

# Submission time Handle Problem Language Result Execution time Memory
810835 2023-08-06T16:18:08 Z abczz Boat (APIO16_boat) C++14
100 / 100
477 ms 460 KB
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#define ll long long

using namespace std;

const ll M = 1e9 + 7;
vector<array<ll, 3> > V;
vector <array<ll, 2> > U;
bool B[500];
ll dp[500], C[501];
ll n, a, b, s, z, p, f, cnt, tmp, cur, fact[501], inv[501];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cin >> n;
  fact[0] = fact[1] = inv[0] = inv[1] = 1;
  for (ll i=2; i<=n; ++i) {
    fact[i] = fact[i-1] * i;
    fact[i] %= M;
    inv[i] = (M-(((M/i) * inv[M%i])%M))%M;
  }
  for (int i=2; i<=n; ++i) {
    inv[i] *= inv[i-1];
    inv[i] %= M;
  }
  for (int i=0; i<n; ++i) {
    cin >> a >> b;
    V.push_back({a, i, 0});
    V.push_back({b+1, i, 1});
  }
  sort(V.begin(), V.end());
  for (int i=0; i+1<V.size(); ++i) {
    if (!V[i][2]) {
      B[V[i][1]] = 1;
    }
    else {
      B[V[i][1]] = 0;
    }
    z = V[i+1][0]-V[i][0];
    if (!z) continue;
    U.clear();
    s = 1;
    for (int j=0; j<n; ++j) {
      if (B[j]) U.push_back({j, s});
      s += dp[j];
      s %= M;
    }
    for (ll j=1; j<=U.size(); ++j) {
      if (j > 1 && z < 2) {
        C[j] = 0;
        continue;
      }
      if (j == 1) {
        C[j] = z;
        continue;
      }
      else if (j == 2) {
        C[j] = ((z * (z-1))/2) % M;
        continue;
      }
      C[j] = 0;
      p = (z * (z-1))%M;
      for (ll k=2; k<=min(j, z); ++k) {
        cur = 1;
        cur *= (((fact[j-2] * inv[j-k])%M) * inv[k-2])%M;
        cur *= (p * inv[k]) % M;
        cur %= M;
        C[j] += cur;
        C[j] %= M;
        p *= (z-k);
        p %= M;
      }
    }
    for (int j=0; j<U.size(); ++j) {
      for (int k=j; k<U.size(); ++k) {
        //cout << U[j][0] << " " << U[k][0] << ":" << U[j][1] << "*" << C[k-j+1] << endl;
        dp[U[k][0]] += ((U[j][1] * C[k-j+1]) % M);
        dp[U[k][0]] %= M;
      }
    }
    /*for (int j=0; j<n; ++j) {
      cout << dp[j] << " ";
    }
    cout << endl;*/
  }
  for (int i=0; i<n; ++i) {
    f += dp[i];
    f %= M;
  }
  cout << f << '\n';
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:35:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<long long int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |   for (int i=0; i+1<V.size(); ++i) {
      |                 ~~~^~~~~~~~~
boat.cpp:51:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     for (ll j=1; j<=U.size(); ++j) {
      |                  ~^~~~~~~~~~
boat.cpp:77:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |     for (int j=0; j<U.size(); ++j) {
      |                   ~^~~~~~~~~
boat.cpp:78:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |       for (int k=j; k<U.size(); ++k) {
      |                     ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 328 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 3 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 328 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 328 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 3 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 328 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 56 ms 368 KB Output is correct
22 Correct 54 ms 340 KB Output is correct
23 Correct 48 ms 328 KB Output is correct
24 Correct 54 ms 340 KB Output is correct
25 Correct 55 ms 340 KB Output is correct
26 Correct 124 ms 340 KB Output is correct
27 Correct 124 ms 340 KB Output is correct
28 Correct 120 ms 368 KB Output is correct
29 Correct 120 ms 372 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
33 Correct 2 ms 328 KB Output is correct
34 Correct 2 ms 340 KB Output is correct
35 Correct 3 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 2 ms 340 KB Output is correct
38 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 4 ms 340 KB Output is correct
7 Correct 5 ms 328 KB Output is correct
8 Correct 4 ms 340 KB Output is correct
9 Correct 4 ms 340 KB Output is correct
10 Correct 4 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 320 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 320 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 328 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 3 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 328 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 56 ms 368 KB Output is correct
22 Correct 54 ms 340 KB Output is correct
23 Correct 48 ms 328 KB Output is correct
24 Correct 54 ms 340 KB Output is correct
25 Correct 55 ms 340 KB Output is correct
26 Correct 124 ms 340 KB Output is correct
27 Correct 124 ms 340 KB Output is correct
28 Correct 120 ms 368 KB Output is correct
29 Correct 120 ms 372 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
33 Correct 2 ms 328 KB Output is correct
34 Correct 2 ms 340 KB Output is correct
35 Correct 3 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 2 ms 340 KB Output is correct
38 Correct 2 ms 340 KB Output is correct
39 Correct 2 ms 340 KB Output is correct
40 Correct 2 ms 340 KB Output is correct
41 Correct 2 ms 340 KB Output is correct
42 Correct 2 ms 340 KB Output is correct
43 Correct 2 ms 340 KB Output is correct
44 Correct 4 ms 340 KB Output is correct
45 Correct 5 ms 328 KB Output is correct
46 Correct 4 ms 340 KB Output is correct
47 Correct 4 ms 340 KB Output is correct
48 Correct 4 ms 340 KB Output is correct
49 Correct 2 ms 340 KB Output is correct
50 Correct 2 ms 320 KB Output is correct
51 Correct 2 ms 340 KB Output is correct
52 Correct 2 ms 320 KB Output is correct
53 Correct 2 ms 340 KB Output is correct
54 Correct 1 ms 320 KB Output is correct
55 Correct 1 ms 320 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 2 ms 340 KB Output is correct
59 Correct 208 ms 460 KB Output is correct
60 Correct 167 ms 372 KB Output is correct
61 Correct 158 ms 372 KB Output is correct
62 Correct 191 ms 376 KB Output is correct
63 Correct 181 ms 332 KB Output is correct
64 Correct 439 ms 376 KB Output is correct
65 Correct 458 ms 340 KB Output is correct
66 Correct 449 ms 372 KB Output is correct
67 Correct 477 ms 376 KB Output is correct
68 Correct 435 ms 376 KB Output is correct
69 Correct 163 ms 376 KB Output is correct
70 Correct 163 ms 340 KB Output is correct
71 Correct 161 ms 380 KB Output is correct
72 Correct 175 ms 372 KB Output is correct
73 Correct 173 ms 376 KB Output is correct
74 Correct 24 ms 396 KB Output is correct
75 Correct 23 ms 396 KB Output is correct
76 Correct 24 ms 392 KB Output is correct
77 Correct 25 ms 340 KB Output is correct
78 Correct 25 ms 340 KB Output is correct