Submission #967922

# Submission time Handle Problem Language Result Execution time Memory
967922 2024-04-23T05:27:49 Z duckindog Boat (APIO16_boat) C++17
9 / 100
2000 ms 524288 KB
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 500 + 10,
          M = 1'000'000'000 + 7;
int n;
int a[N], b[N];
struct modint {
  int value;

  modint(int value = 0) : value(value) {}

  modint operator + (modint rhs) { return (rhs.value + value) % M; }
  modint operator - (modint rhs) { return (value - rhs.value + M) % M; }
  modint operator * (modint rhs) { return 1ll * value * rhs.value % M; }

  modint operator += (modint rhs) { value = (value + rhs.value) % M; return *this; }
  modint operator -= (modint rhs) { value = (value - rhs.value + M) % M; return *this; }
  modint operator *= (modint rhs) { value = 1ll * value * rhs.value % M; return *this; }

  friend ostream& operator << (ostream& os, modint rhs) {
    return os << rhs.value;
  }
} f[2][1'000'000 + 10];
 
int32_t main() { 
  cin.tie(0)->sync_with_stdio(0);
 
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i] >> b[i];
 
  vector<int> rrh;
  for (int i = 1; i <= n; ++i) {
    for (int j = a[i]; j <= b[i]; ++j) rrh.push_back(j);
  }
 
  sort(rrh.begin(), rrh.end());
  rrh.resize(unique(rrh.begin(), rrh.end()) - rrh.begin());
 
  f[0][0] = 1;
  for (int j = 1; j <= rrh.size(); ++j) f[0][j] = 1;
 
  for (int i = 1; i <= n; ++i) { 
    int id = i & 1, p = id ^ 1;
    for (int j = 0; j <= rrh.size(); ++j) f[id][j] = 0;
    
    int it = lower_bound(rrh.begin(), rrh.end(), a[i]) - rrh.begin() + 1;
    
    for (int j = 0; j <= rrh.size(); ++j) f[id][j] = f[p][j];
    for (int j = it; j <= b[i] - a[i] + it; ++j) f[id][j] = f[p][j - 1] + f[id][j];
    for (int j = 1; j <= rrh.size(); ++j) {
      f[id][j] = f[id][j] + f[id][j - 1] - f[p][j - 1];
    }
  }
  
  cout << f[n & 1][rrh.size()] - 1 << "\n";
}

Compilation message

boat.cpp: In function 'int32_t main()':
boat.cpp:42:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |   for (int j = 1; j <= rrh.size(); ++j) f[0][j] = 1;
      |                   ~~^~~~~~~~~~~~~
boat.cpp:46:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for (int j = 0; j <= rrh.size(); ++j) f[id][j] = 0;
      |                     ~~^~~~~~~~~~~~~
boat.cpp:50:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for (int j = 0; j <= rrh.size(); ++j) f[id][j] = f[p][j];
      |                     ~~^~~~~~~~~~~~~
boat.cpp:52:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for (int j = 1; j <= rrh.size(); ++j) {
      |                     ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8284 KB Output is correct
2 Correct 5 ms 8284 KB Output is correct
3 Correct 6 ms 8284 KB Output is correct
4 Correct 4 ms 8284 KB Output is correct
5 Correct 5 ms 8284 KB Output is correct
6 Correct 4 ms 8284 KB Output is correct
7 Correct 4 ms 8292 KB Output is correct
8 Correct 4 ms 8284 KB Output is correct
9 Correct 4 ms 8280 KB Output is correct
10 Correct 4 ms 8536 KB Output is correct
11 Correct 4 ms 8284 KB Output is correct
12 Correct 4 ms 8284 KB Output is correct
13 Correct 4 ms 8280 KB Output is correct
14 Correct 4 ms 8284 KB Output is correct
15 Correct 4 ms 8284 KB Output is correct
16 Correct 2 ms 8284 KB Output is correct
17 Correct 3 ms 8280 KB Output is correct
18 Correct 2 ms 8284 KB Output is correct
19 Correct 2 ms 8284 KB Output is correct
20 Correct 2 ms 8284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8284 KB Output is correct
2 Correct 5 ms 8284 KB Output is correct
3 Correct 6 ms 8284 KB Output is correct
4 Correct 4 ms 8284 KB Output is correct
5 Correct 5 ms 8284 KB Output is correct
6 Correct 4 ms 8284 KB Output is correct
7 Correct 4 ms 8292 KB Output is correct
8 Correct 4 ms 8284 KB Output is correct
9 Correct 4 ms 8280 KB Output is correct
10 Correct 4 ms 8536 KB Output is correct
11 Correct 4 ms 8284 KB Output is correct
12 Correct 4 ms 8284 KB Output is correct
13 Correct 4 ms 8280 KB Output is correct
14 Correct 4 ms 8284 KB Output is correct
15 Correct 4 ms 8284 KB Output is correct
16 Correct 2 ms 8284 KB Output is correct
17 Correct 3 ms 8280 KB Output is correct
18 Correct 2 ms 8284 KB Output is correct
19 Correct 2 ms 8284 KB Output is correct
20 Correct 2 ms 8284 KB Output is correct
21 Correct 53 ms 14036 KB Output is correct
22 Correct 54 ms 13264 KB Output is correct
23 Correct 52 ms 13012 KB Output is correct
24 Correct 53 ms 13264 KB Output is correct
25 Correct 54 ms 14032 KB Output is correct
26 Correct 51 ms 13008 KB Output is correct
27 Correct 52 ms 13008 KB Output is correct
28 Correct 50 ms 13012 KB Output is correct
29 Correct 51 ms 14548 KB Output is correct
30 Execution timed out 2009 ms 13264 KB Time limit exceeded
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 484 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8284 KB Output is correct
2 Correct 5 ms 8284 KB Output is correct
3 Correct 6 ms 8284 KB Output is correct
4 Correct 4 ms 8284 KB Output is correct
5 Correct 5 ms 8284 KB Output is correct
6 Correct 4 ms 8284 KB Output is correct
7 Correct 4 ms 8292 KB Output is correct
8 Correct 4 ms 8284 KB Output is correct
9 Correct 4 ms 8280 KB Output is correct
10 Correct 4 ms 8536 KB Output is correct
11 Correct 4 ms 8284 KB Output is correct
12 Correct 4 ms 8284 KB Output is correct
13 Correct 4 ms 8280 KB Output is correct
14 Correct 4 ms 8284 KB Output is correct
15 Correct 4 ms 8284 KB Output is correct
16 Correct 2 ms 8284 KB Output is correct
17 Correct 3 ms 8280 KB Output is correct
18 Correct 2 ms 8284 KB Output is correct
19 Correct 2 ms 8284 KB Output is correct
20 Correct 2 ms 8284 KB Output is correct
21 Correct 53 ms 14036 KB Output is correct
22 Correct 54 ms 13264 KB Output is correct
23 Correct 52 ms 13012 KB Output is correct
24 Correct 53 ms 13264 KB Output is correct
25 Correct 54 ms 14032 KB Output is correct
26 Correct 51 ms 13008 KB Output is correct
27 Correct 52 ms 13008 KB Output is correct
28 Correct 50 ms 13012 KB Output is correct
29 Correct 51 ms 14548 KB Output is correct
30 Execution timed out 2009 ms 13264 KB Time limit exceeded
31 Halted 0 ms 0 KB -