Submission #699594

# Submission time Handle Problem Language Result Execution time Memory
699594 2023-02-17T13:10:13 Z Abrar_Al_Samit Boat (APIO16_boat) C++17
9 / 100
318 ms 50628 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 = 103217;

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;
}

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, inv[i]);
  }
  table[H2].emplace_back(H, ret);
  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, to=min(op, len-1); take<=to; ++take) {
    ret = add(ret, mul(C(op, take), C(len, take+1)));
  }

  andp[H2].emplace_back(H, ret);
  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, ++cur_op) {
    if(ind[i][mx]<=prv) continue;

    int cur = mul(solve(i+1, ind[i][mx]), get(len, 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);
      }
    }
  }
  for(int i=1; i<=n; ++i) {
    inv[i] = quickpow(i, mod-2);
  }
  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:79:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |   for(int mx=0, cur_op=0; mx<ind[i].size(); ++mx, ++cur_op) {
      |                           ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 32 ms 49364 KB Output is correct
2 Correct 32 ms 49364 KB Output is correct
3 Correct 31 ms 49364 KB Output is correct
4 Correct 34 ms 49436 KB Output is correct
5 Correct 29 ms 49452 KB Output is correct
6 Correct 29 ms 49384 KB Output is correct
7 Correct 29 ms 49460 KB Output is correct
8 Correct 29 ms 49364 KB Output is correct
9 Correct 29 ms 49364 KB Output is correct
10 Correct 29 ms 49460 KB Output is correct
11 Correct 28 ms 49364 KB Output is correct
12 Correct 28 ms 49364 KB Output is correct
13 Correct 31 ms 49364 KB Output is correct
14 Correct 29 ms 49364 KB Output is correct
15 Correct 34 ms 49372 KB Output is correct
16 Correct 25 ms 49312 KB Output is correct
17 Correct 28 ms 49320 KB Output is correct
18 Correct 26 ms 49244 KB Output is correct
19 Correct 26 ms 49328 KB Output is correct
20 Correct 25 ms 49276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 49364 KB Output is correct
2 Correct 32 ms 49364 KB Output is correct
3 Correct 31 ms 49364 KB Output is correct
4 Correct 34 ms 49436 KB Output is correct
5 Correct 29 ms 49452 KB Output is correct
6 Correct 29 ms 49384 KB Output is correct
7 Correct 29 ms 49460 KB Output is correct
8 Correct 29 ms 49364 KB Output is correct
9 Correct 29 ms 49364 KB Output is correct
10 Correct 29 ms 49460 KB Output is correct
11 Correct 28 ms 49364 KB Output is correct
12 Correct 28 ms 49364 KB Output is correct
13 Correct 31 ms 49364 KB Output is correct
14 Correct 29 ms 49364 KB Output is correct
15 Correct 34 ms 49372 KB Output is correct
16 Correct 25 ms 49312 KB Output is correct
17 Correct 28 ms 49320 KB Output is correct
18 Correct 26 ms 49244 KB Output is correct
19 Correct 26 ms 49328 KB Output is correct
20 Correct 25 ms 49276 KB Output is correct
21 Incorrect 318 ms 50628 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 49688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 49364 KB Output is correct
2 Correct 32 ms 49364 KB Output is correct
3 Correct 31 ms 49364 KB Output is correct
4 Correct 34 ms 49436 KB Output is correct
5 Correct 29 ms 49452 KB Output is correct
6 Correct 29 ms 49384 KB Output is correct
7 Correct 29 ms 49460 KB Output is correct
8 Correct 29 ms 49364 KB Output is correct
9 Correct 29 ms 49364 KB Output is correct
10 Correct 29 ms 49460 KB Output is correct
11 Correct 28 ms 49364 KB Output is correct
12 Correct 28 ms 49364 KB Output is correct
13 Correct 31 ms 49364 KB Output is correct
14 Correct 29 ms 49364 KB Output is correct
15 Correct 34 ms 49372 KB Output is correct
16 Correct 25 ms 49312 KB Output is correct
17 Correct 28 ms 49320 KB Output is correct
18 Correct 26 ms 49244 KB Output is correct
19 Correct 26 ms 49328 KB Output is correct
20 Correct 25 ms 49276 KB Output is correct
21 Incorrect 318 ms 50628 KB Output isn't correct
22 Halted 0 ms 0 KB -