Submission #699588

# Submission time Handle Problem Language Result Execution time Memory
699588 2023-02-17T12:58:13 Z Abrar_Al_Samit Boat (APIO16_boat) C++17
58 / 100
2000 ms 68908 KB
#include<bits/stdc++.h>
using namespace std;

const int nax = 503;
const int mod = 1e9 + 7;
const int cax = 1e6 + 3;
const long long sux = 1361;

vector<int>ind[nax*2];
int a[nax], b[nax];
int n, m;
int dp[nax*2][nax];
int inv[nax];
vector<int>imp;

int add(int a, int b) {
  a += b;
  if(a>=mod) a -= mod;
  return a;
}
int mul(int a, int b) {
  return (a * 1LL * b) % mod;
}
int quickpow(int a, int b) {
  int ret = 1;
  while(b) {
    if(b&1) ret = mul(ret, a);
    a = mul(a, a);
    b >>= 1;
  }
  return ret;
}

int get(int x) {
  int &ret = inv[x];
  if(ret==-1) {
    ret = quickpow(x, mod-2);
  }
  return ret;
}
vector<pair<long long,int>>table[cax];
int C(int n, int r) {
  long long H = n * sux + r;
  int H2 = H % cax;
  for(auto x : table[H2]) {
    if(x.first==H) return x.second;
  }


  int ret = 1;
  for(int i=n-r+1; i<=n; ++i) {
    ret = mul(ret, i);
  }
  for(int i=1; i<=r; ++i) {
    ret = mul(ret, get(i));
  }
  table[H2].emplace_back(H, ret);
  assert((int)table[H2].size()<=4);
  return ret;
}

vector<pair<long long,int>>andp[cax];
int get(int len, int op) {
  long long H = len * sux + op;
  int H2 = H % cax;
  for(auto x : andp[H2]) {
    if(x.first==H) return x.second;
  }

  int ret = 0;
  for(int take=0; take<=min(op, len-1); ++take) {
    ret = add(ret, mul(C(op, take), C(len, take+1)));
  }

  andp[H2].emplace_back(H, ret);
  assert((int)andp[H2].size()<=4);
  return ret;
}
int solve(int i, int prv) {
  if(i==m-1) return prv>0;
  int &ret = dp[i][prv];
  if(ret!=-1) return ret;
  ret = 0;

  ret = solve(i+1, prv);
  int len = imp[i+1]-imp[i];

  for(int mx=0, cur_op=0; mx<ind[i].size(); ++mx) {
    if(ind[i][mx]<=prv) continue;

    int cur = mul(solve(i+1, ind[i][mx]), get(len, cur_op));
    cur_op++;
    ret = add(ret, cur);
  }
  return ret;
}
void PlayGround() {
  cin>>n;
  set<int>pts;
  for(int i=1; i<=n; ++i) {
    cin>>a[i]>>b[i];
    pts.insert(a[i]);
    pts.insert(b[i]+1);
  }

  for(int x : pts) {
    imp.push_back(x);
  } 
  m = imp.size();
  for(int i=0; i<m; ++i) {
    for(int j=1; j<=n; ++j) {
      if(imp[i]>=a[j] && imp[i]<=b[j]) {
        ind[i].push_back(j);
      }
    }
  }
  memset(inv, -1, sizeof inv);
  memset(dp, -1, sizeof dp);
  cout<<solve(0, 0)<<'\n';


  // cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  PlayGround();
  return 0;
}

Compilation message

boat.cpp: In function 'int solve(int, int)':
boat.cpp:88:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |   for(int mx=0, cur_op=0; mx<ind[i].size(); ++mx) {
      |                           ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 32 ms 49472 KB Output is correct
2 Correct 28 ms 49356 KB Output is correct
3 Correct 29 ms 49344 KB Output is correct
4 Correct 31 ms 49376 KB Output is correct
5 Correct 29 ms 49452 KB Output is correct
6 Correct 29 ms 49476 KB Output is correct
7 Correct 31 ms 49360 KB Output is correct
8 Correct 30 ms 49428 KB Output is correct
9 Correct 28 ms 49368 KB Output is correct
10 Correct 29 ms 49468 KB Output is correct
11 Correct 29 ms 49384 KB Output is correct
12 Correct 30 ms 49448 KB Output is correct
13 Correct 30 ms 49364 KB Output is correct
14 Correct 28 ms 49476 KB Output is correct
15 Correct 28 ms 49396 KB Output is correct
16 Correct 26 ms 49260 KB Output is correct
17 Correct 26 ms 49236 KB Output is correct
18 Correct 26 ms 49236 KB Output is correct
19 Correct 31 ms 49228 KB Output is correct
20 Correct 29 ms 49332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 49472 KB Output is correct
2 Correct 28 ms 49356 KB Output is correct
3 Correct 29 ms 49344 KB Output is correct
4 Correct 31 ms 49376 KB Output is correct
5 Correct 29 ms 49452 KB Output is correct
6 Correct 29 ms 49476 KB Output is correct
7 Correct 31 ms 49360 KB Output is correct
8 Correct 30 ms 49428 KB Output is correct
9 Correct 28 ms 49368 KB Output is correct
10 Correct 29 ms 49468 KB Output is correct
11 Correct 29 ms 49384 KB Output is correct
12 Correct 30 ms 49448 KB Output is correct
13 Correct 30 ms 49364 KB Output is correct
14 Correct 28 ms 49476 KB Output is correct
15 Correct 28 ms 49396 KB Output is correct
16 Correct 26 ms 49260 KB Output is correct
17 Correct 26 ms 49236 KB Output is correct
18 Correct 26 ms 49236 KB Output is correct
19 Correct 31 ms 49228 KB Output is correct
20 Correct 29 ms 49332 KB Output is correct
21 Correct 315 ms 50764 KB Output is correct
22 Correct 308 ms 50932 KB Output is correct
23 Correct 289 ms 50544 KB Output is correct
24 Correct 289 ms 50636 KB Output is correct
25 Correct 305 ms 50660 KB Output is correct
26 Correct 568 ms 51356 KB Output is correct
27 Correct 579 ms 51140 KB Output is correct
28 Correct 564 ms 51280 KB Output is correct
29 Correct 570 ms 51320 KB Output is correct
30 Correct 38 ms 49484 KB Output is correct
31 Correct 35 ms 49492 KB Output is correct
32 Correct 32 ms 49468 KB Output is correct
33 Correct 35 ms 49480 KB Output is correct
34 Correct 32 ms 49504 KB Output is correct
35 Correct 32 ms 49432 KB Output is correct
36 Correct 30 ms 49380 KB Output is correct
37 Correct 31 ms 49468 KB Output is correct
38 Correct 39 ms 49508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 49752 KB Output is correct
2 Correct 30 ms 49620 KB Output is correct
3 Correct 30 ms 49720 KB Output is correct
4 Correct 30 ms 49756 KB Output is correct
5 Correct 35 ms 49748 KB Output is correct
6 Correct 40 ms 50044 KB Output is correct
7 Correct 40 ms 50108 KB Output is correct
8 Correct 40 ms 50016 KB Output is correct
9 Correct 47 ms 50088 KB Output is correct
10 Correct 42 ms 50132 KB Output is correct
11 Correct 35 ms 49808 KB Output is correct
12 Correct 30 ms 49708 KB Output is correct
13 Correct 32 ms 49776 KB Output is correct
14 Correct 35 ms 49728 KB Output is correct
15 Correct 32 ms 49832 KB Output is correct
16 Correct 29 ms 49484 KB Output is correct
17 Correct 27 ms 49424 KB Output is correct
18 Correct 28 ms 49504 KB Output is correct
19 Correct 27 ms 49532 KB Output is correct
20 Correct 28 ms 49492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 49472 KB Output is correct
2 Correct 28 ms 49356 KB Output is correct
3 Correct 29 ms 49344 KB Output is correct
4 Correct 31 ms 49376 KB Output is correct
5 Correct 29 ms 49452 KB Output is correct
6 Correct 29 ms 49476 KB Output is correct
7 Correct 31 ms 49360 KB Output is correct
8 Correct 30 ms 49428 KB Output is correct
9 Correct 28 ms 49368 KB Output is correct
10 Correct 29 ms 49468 KB Output is correct
11 Correct 29 ms 49384 KB Output is correct
12 Correct 30 ms 49448 KB Output is correct
13 Correct 30 ms 49364 KB Output is correct
14 Correct 28 ms 49476 KB Output is correct
15 Correct 28 ms 49396 KB Output is correct
16 Correct 26 ms 49260 KB Output is correct
17 Correct 26 ms 49236 KB Output is correct
18 Correct 26 ms 49236 KB Output is correct
19 Correct 31 ms 49228 KB Output is correct
20 Correct 29 ms 49332 KB Output is correct
21 Correct 315 ms 50764 KB Output is correct
22 Correct 308 ms 50932 KB Output is correct
23 Correct 289 ms 50544 KB Output is correct
24 Correct 289 ms 50636 KB Output is correct
25 Correct 305 ms 50660 KB Output is correct
26 Correct 568 ms 51356 KB Output is correct
27 Correct 579 ms 51140 KB Output is correct
28 Correct 564 ms 51280 KB Output is correct
29 Correct 570 ms 51320 KB Output is correct
30 Correct 38 ms 49484 KB Output is correct
31 Correct 35 ms 49492 KB Output is correct
32 Correct 32 ms 49468 KB Output is correct
33 Correct 35 ms 49480 KB Output is correct
34 Correct 32 ms 49504 KB Output is correct
35 Correct 32 ms 49432 KB Output is correct
36 Correct 30 ms 49380 KB Output is correct
37 Correct 31 ms 49468 KB Output is correct
38 Correct 39 ms 49508 KB Output is correct
39 Correct 35 ms 49752 KB Output is correct
40 Correct 30 ms 49620 KB Output is correct
41 Correct 30 ms 49720 KB Output is correct
42 Correct 30 ms 49756 KB Output is correct
43 Correct 35 ms 49748 KB Output is correct
44 Correct 40 ms 50044 KB Output is correct
45 Correct 40 ms 50108 KB Output is correct
46 Correct 40 ms 50016 KB Output is correct
47 Correct 47 ms 50088 KB Output is correct
48 Correct 42 ms 50132 KB Output is correct
49 Correct 35 ms 49808 KB Output is correct
50 Correct 30 ms 49708 KB Output is correct
51 Correct 32 ms 49776 KB Output is correct
52 Correct 35 ms 49728 KB Output is correct
53 Correct 32 ms 49832 KB Output is correct
54 Correct 29 ms 49484 KB Output is correct
55 Correct 27 ms 49424 KB Output is correct
56 Correct 28 ms 49504 KB Output is correct
57 Correct 27 ms 49532 KB Output is correct
58 Correct 28 ms 49492 KB Output is correct
59 Correct 980 ms 61532 KB Output is correct
60 Correct 882 ms 60816 KB Output is correct
61 Correct 791 ms 60560 KB Output is correct
62 Correct 945 ms 61848 KB Output is correct
63 Correct 943 ms 61240 KB Output is correct
64 Execution timed out 2093 ms 68908 KB Time limit exceeded
65 Halted 0 ms 0 KB -