Submission #699578

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

const int nax = 503;
const int mod = 1e9 + 7;

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;
}
unordered_map<long long,int>table;
int C(int n, int r) {
  int& ret = table[n * 1000000LL + r];
  if(ret==0) {
    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));
    }
  }
  return ret;
}

unordered_map<long long,int>andp;
int get(int len, int op) {
  int &ret = andp[len * 1000000LL + op];
  if(ret==0) {
    for(int take=0; take<=min(op, len-1); ++take) {
      ret = add(ret, mul(C(op, take), C(len, take+1)));
    }
  }
  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:73:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |   for(int mx=0, cur_op=0; mx<ind[i].size(); ++mx) {
      |                           ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2388 KB Output is correct
2 Correct 6 ms 2504 KB Output is correct
3 Correct 7 ms 2388 KB Output is correct
4 Correct 6 ms 2388 KB Output is correct
5 Correct 7 ms 2388 KB Output is correct
6 Correct 8 ms 2388 KB Output is correct
7 Correct 7 ms 2388 KB Output is correct
8 Correct 7 ms 2508 KB Output is correct
9 Correct 8 ms 2508 KB Output is correct
10 Correct 8 ms 2388 KB Output is correct
11 Correct 7 ms 2388 KB Output is correct
12 Correct 7 ms 2500 KB Output is correct
13 Correct 8 ms 2388 KB Output is correct
14 Correct 7 ms 2388 KB Output is correct
15 Correct 8 ms 2504 KB Output is correct
16 Correct 3 ms 2260 KB Output is correct
17 Correct 3 ms 2284 KB Output is correct
18 Correct 4 ms 2260 KB Output is correct
19 Correct 3 ms 2260 KB Output is correct
20 Correct 4 ms 2260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2388 KB Output is correct
2 Correct 6 ms 2504 KB Output is correct
3 Correct 7 ms 2388 KB Output is correct
4 Correct 6 ms 2388 KB Output is correct
5 Correct 7 ms 2388 KB Output is correct
6 Correct 8 ms 2388 KB Output is correct
7 Correct 7 ms 2388 KB Output is correct
8 Correct 7 ms 2508 KB Output is correct
9 Correct 8 ms 2508 KB Output is correct
10 Correct 8 ms 2388 KB Output is correct
11 Correct 7 ms 2388 KB Output is correct
12 Correct 7 ms 2500 KB Output is correct
13 Correct 8 ms 2388 KB Output is correct
14 Correct 7 ms 2388 KB Output is correct
15 Correct 8 ms 2504 KB Output is correct
16 Correct 3 ms 2260 KB Output is correct
17 Correct 3 ms 2284 KB Output is correct
18 Correct 4 ms 2260 KB Output is correct
19 Correct 3 ms 2260 KB Output is correct
20 Correct 4 ms 2260 KB Output is correct
21 Correct 411 ms 3928 KB Output is correct
22 Correct 366 ms 4224 KB Output is correct
23 Correct 375 ms 3792 KB Output is correct
24 Correct 359 ms 3824 KB Output is correct
25 Correct 370 ms 3840 KB Output is correct
26 Correct 773 ms 4572 KB Output is correct
27 Correct 822 ms 4492 KB Output is correct
28 Correct 822 ms 4508 KB Output is correct
29 Correct 814 ms 4812 KB Output is correct
30 Correct 17 ms 2516 KB Output is correct
31 Correct 14 ms 2556 KB Output is correct
32 Correct 15 ms 2664 KB Output is correct
33 Correct 14 ms 2516 KB Output is correct
34 Correct 15 ms 2516 KB Output is correct
35 Correct 9 ms 2476 KB Output is correct
36 Correct 10 ms 2552 KB Output is correct
37 Correct 10 ms 2516 KB Output is correct
38 Correct 14 ms 2516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 2900 KB Output is correct
2 Correct 10 ms 2900 KB Output is correct
3 Correct 11 ms 2900 KB Output is correct
4 Correct 12 ms 2992 KB Output is correct
5 Correct 13 ms 3028 KB Output is correct
6 Correct 24 ms 3408 KB Output is correct
7 Correct 24 ms 3412 KB Output is correct
8 Correct 25 ms 3328 KB Output is correct
9 Correct 24 ms 3356 KB Output is correct
10 Correct 24 ms 3404 KB Output is correct
11 Correct 13 ms 2980 KB Output is correct
12 Correct 11 ms 2900 KB Output is correct
13 Correct 12 ms 2900 KB Output is correct
14 Correct 12 ms 2900 KB Output is correct
15 Correct 14 ms 2940 KB Output is correct
16 Correct 7 ms 2644 KB Output is correct
17 Correct 6 ms 2644 KB Output is correct
18 Correct 7 ms 2572 KB Output is correct
19 Correct 6 ms 2644 KB Output is correct
20 Correct 11 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2388 KB Output is correct
2 Correct 6 ms 2504 KB Output is correct
3 Correct 7 ms 2388 KB Output is correct
4 Correct 6 ms 2388 KB Output is correct
5 Correct 7 ms 2388 KB Output is correct
6 Correct 8 ms 2388 KB Output is correct
7 Correct 7 ms 2388 KB Output is correct
8 Correct 7 ms 2508 KB Output is correct
9 Correct 8 ms 2508 KB Output is correct
10 Correct 8 ms 2388 KB Output is correct
11 Correct 7 ms 2388 KB Output is correct
12 Correct 7 ms 2500 KB Output is correct
13 Correct 8 ms 2388 KB Output is correct
14 Correct 7 ms 2388 KB Output is correct
15 Correct 8 ms 2504 KB Output is correct
16 Correct 3 ms 2260 KB Output is correct
17 Correct 3 ms 2284 KB Output is correct
18 Correct 4 ms 2260 KB Output is correct
19 Correct 3 ms 2260 KB Output is correct
20 Correct 4 ms 2260 KB Output is correct
21 Correct 411 ms 3928 KB Output is correct
22 Correct 366 ms 4224 KB Output is correct
23 Correct 375 ms 3792 KB Output is correct
24 Correct 359 ms 3824 KB Output is correct
25 Correct 370 ms 3840 KB Output is correct
26 Correct 773 ms 4572 KB Output is correct
27 Correct 822 ms 4492 KB Output is correct
28 Correct 822 ms 4508 KB Output is correct
29 Correct 814 ms 4812 KB Output is correct
30 Correct 17 ms 2516 KB Output is correct
31 Correct 14 ms 2556 KB Output is correct
32 Correct 15 ms 2664 KB Output is correct
33 Correct 14 ms 2516 KB Output is correct
34 Correct 15 ms 2516 KB Output is correct
35 Correct 9 ms 2476 KB Output is correct
36 Correct 10 ms 2552 KB Output is correct
37 Correct 10 ms 2516 KB Output is correct
38 Correct 14 ms 2516 KB Output is correct
39 Correct 13 ms 2900 KB Output is correct
40 Correct 10 ms 2900 KB Output is correct
41 Correct 11 ms 2900 KB Output is correct
42 Correct 12 ms 2992 KB Output is correct
43 Correct 13 ms 3028 KB Output is correct
44 Correct 24 ms 3408 KB Output is correct
45 Correct 24 ms 3412 KB Output is correct
46 Correct 25 ms 3328 KB Output is correct
47 Correct 24 ms 3356 KB Output is correct
48 Correct 24 ms 3404 KB Output is correct
49 Correct 13 ms 2980 KB Output is correct
50 Correct 11 ms 2900 KB Output is correct
51 Correct 12 ms 2900 KB Output is correct
52 Correct 12 ms 2900 KB Output is correct
53 Correct 14 ms 2940 KB Output is correct
54 Correct 7 ms 2644 KB Output is correct
55 Correct 6 ms 2644 KB Output is correct
56 Correct 7 ms 2572 KB Output is correct
57 Correct 6 ms 2644 KB Output is correct
58 Correct 11 ms 2644 KB Output is correct
59 Correct 1241 ms 19220 KB Output is correct
60 Correct 1218 ms 18580 KB Output is correct
61 Correct 1122 ms 18668 KB Output is correct
62 Correct 1274 ms 19432 KB Output is correct
63 Correct 1298 ms 18920 KB Output is correct
64 Execution timed out 2081 ms 21248 KB Time limit exceeded
65 Halted 0 ms 0 KB -