Submission #970794

# Submission time Handle Problem Language Result Execution time Memory
970794 2024-04-27T09:18:06 Z vjudge1 Boat (APIO16_boat) C++14
100 / 100
705 ms 4696 KB
#include<bits/stdc++.h>

using namespace std;

const int N=510, mod=1e9+7;
int fact[N*2], invfact[N*2], inv[N*2];

int binpow(int x, int y){
   int t=1;
   while (y){
      if (y&1) t=1ll*t*x%mod;
      x=1ll*x*x%mod;
      y>>=1;
   }
   return t;
}

void precalc(){
   fact[0]=1;
   for (int i=1; i<N*2; ++i) fact[i]=1ll*fact[i-1]*i%mod;
   invfact[N*2-1]=binpow(fact[N*2-1], mod-2);
   for (int i=N*2-2; i>=0; --i) invfact[i]=1ll*invfact[i+1]*(i+1)%mod;
   for (int i=1; i<N*2; ++i) inv[i]=1ll*invfact[i]*fact[i-1]%mod;
}

int C(int n, int k){
   if (n<0 || k<0 || n<k) return 0;
   return 1ll*fact[n]*invfact[k]%mod*invfact[n-k]%mod;
}

int f[N*2][N], g[N*2][N], sf[N*2], sg[N*2], n, a[N], b[N];
vector<int> vals;

int32_t main(){
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   precalc();
   vals.push_back(-1);
   cin >> n;
   for (int i=1; i<=n; ++i) cin >> a[i] >> b[i], vals.push_back(a[i]), vals.push_back(++b[i]);
   sort(vals.begin(), vals.end());
   vals.resize(unique(vals.begin(), vals.end())-vals.begin());
   for (int i=1; i<=n; ++i){
      a[i]=lower_bound(vals.begin(), vals.end(), a[i])-vals.begin();
      b[i]=lower_bound(vals.begin(), vals.end(), b[i])-vals.begin();
   }
   f[0][0]=1;
   for (int i=0; i<(int)vals.size(); ++i) sf[i]=1;
   for (int i=1; i<=n; ++i){
      for (int j=a[i]; j<b[i]; ++j){
         int len=vals[j+1]-vals[j];
         for (int k=1; k<=i && k<=len; ++k){
            g[j][k]=(g[j][k]+1ll*(k==1?sf[j-1]:f[j][k-1])*(len-k+1)%mod*inv[k])%mod;
         }
      }
      for (int j=0; j<(int)vals.size(); ++j) for (int k=0; k<=i; ++k){
         g[j][k]=(g[j][k]+f[j][k])%mod;
         sg[j]=(sg[j]+g[j][k])%mod;
      }
      for (int j=1; j<(int)vals.size(); ++j) sg[j]=(sg[j]+sg[j-1])%mod;
      memcpy(f, g, sizeof f);
      memcpy(sf, sg, sizeof sf);
      memset(g, 0, sizeof g);
      memset(sg, 0, sizeof sg);
   }
   cout << (sf[(int)vals.size()-1]+mod-1)%mod << '\n';
   return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 497 ms 4440 KB Output is correct
2 Correct 488 ms 4444 KB Output is correct
3 Correct 490 ms 4532 KB Output is correct
4 Correct 485 ms 4444 KB Output is correct
5 Correct 487 ms 4532 KB Output is correct
6 Correct 487 ms 4532 KB Output is correct
7 Correct 484 ms 4444 KB Output is correct
8 Correct 502 ms 4692 KB Output is correct
9 Correct 491 ms 4532 KB Output is correct
10 Correct 494 ms 4536 KB Output is correct
11 Correct 490 ms 4536 KB Output is correct
12 Correct 487 ms 4540 KB Output is correct
13 Correct 490 ms 4540 KB Output is correct
14 Correct 485 ms 4440 KB Output is correct
15 Correct 489 ms 4440 KB Output is correct
16 Correct 125 ms 4532 KB Output is correct
17 Correct 134 ms 4536 KB Output is correct
18 Correct 128 ms 4532 KB Output is correct
19 Correct 136 ms 4444 KB Output is correct
20 Correct 127 ms 4540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 497 ms 4440 KB Output is correct
2 Correct 488 ms 4444 KB Output is correct
3 Correct 490 ms 4532 KB Output is correct
4 Correct 485 ms 4444 KB Output is correct
5 Correct 487 ms 4532 KB Output is correct
6 Correct 487 ms 4532 KB Output is correct
7 Correct 484 ms 4444 KB Output is correct
8 Correct 502 ms 4692 KB Output is correct
9 Correct 491 ms 4532 KB Output is correct
10 Correct 494 ms 4536 KB Output is correct
11 Correct 490 ms 4536 KB Output is correct
12 Correct 487 ms 4540 KB Output is correct
13 Correct 490 ms 4540 KB Output is correct
14 Correct 485 ms 4440 KB Output is correct
15 Correct 489 ms 4440 KB Output is correct
16 Correct 125 ms 4532 KB Output is correct
17 Correct 134 ms 4536 KB Output is correct
18 Correct 128 ms 4532 KB Output is correct
19 Correct 136 ms 4444 KB Output is correct
20 Correct 127 ms 4540 KB Output is correct
21 Correct 462 ms 4540 KB Output is correct
22 Correct 460 ms 4556 KB Output is correct
23 Correct 453 ms 4444 KB Output is correct
24 Correct 449 ms 4440 KB Output is correct
25 Correct 454 ms 4544 KB Output is correct
26 Correct 443 ms 4544 KB Output is correct
27 Correct 448 ms 4692 KB Output is correct
28 Correct 442 ms 4544 KB Output is correct
29 Correct 445 ms 4544 KB Output is correct
30 Correct 490 ms 4548 KB Output is correct
31 Correct 492 ms 4444 KB Output is correct
32 Correct 483 ms 4548 KB Output is correct
33 Correct 486 ms 4440 KB Output is correct
34 Correct 487 ms 4544 KB Output is correct
35 Correct 490 ms 4688 KB Output is correct
36 Correct 490 ms 4444 KB Output is correct
37 Correct 493 ms 4548 KB Output is correct
38 Correct 489 ms 4688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 4444 KB Output is correct
2 Correct 16 ms 4552 KB Output is correct
3 Correct 15 ms 4444 KB Output is correct
4 Correct 18 ms 4556 KB Output is correct
5 Correct 15 ms 4444 KB Output is correct
6 Correct 16 ms 4444 KB Output is correct
7 Correct 17 ms 4444 KB Output is correct
8 Correct 16 ms 4440 KB Output is correct
9 Correct 16 ms 4444 KB Output is correct
10 Correct 19 ms 4440 KB Output is correct
11 Correct 18 ms 4444 KB Output is correct
12 Correct 15 ms 4544 KB Output is correct
13 Correct 14 ms 4444 KB Output is correct
14 Correct 15 ms 4444 KB Output is correct
15 Correct 15 ms 4444 KB Output is correct
16 Correct 13 ms 4552 KB Output is correct
17 Correct 13 ms 4552 KB Output is correct
18 Correct 12 ms 4444 KB Output is correct
19 Correct 13 ms 4440 KB Output is correct
20 Correct 13 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 497 ms 4440 KB Output is correct
2 Correct 488 ms 4444 KB Output is correct
3 Correct 490 ms 4532 KB Output is correct
4 Correct 485 ms 4444 KB Output is correct
5 Correct 487 ms 4532 KB Output is correct
6 Correct 487 ms 4532 KB Output is correct
7 Correct 484 ms 4444 KB Output is correct
8 Correct 502 ms 4692 KB Output is correct
9 Correct 491 ms 4532 KB Output is correct
10 Correct 494 ms 4536 KB Output is correct
11 Correct 490 ms 4536 KB Output is correct
12 Correct 487 ms 4540 KB Output is correct
13 Correct 490 ms 4540 KB Output is correct
14 Correct 485 ms 4440 KB Output is correct
15 Correct 489 ms 4440 KB Output is correct
16 Correct 125 ms 4532 KB Output is correct
17 Correct 134 ms 4536 KB Output is correct
18 Correct 128 ms 4532 KB Output is correct
19 Correct 136 ms 4444 KB Output is correct
20 Correct 127 ms 4540 KB Output is correct
21 Correct 462 ms 4540 KB Output is correct
22 Correct 460 ms 4556 KB Output is correct
23 Correct 453 ms 4444 KB Output is correct
24 Correct 449 ms 4440 KB Output is correct
25 Correct 454 ms 4544 KB Output is correct
26 Correct 443 ms 4544 KB Output is correct
27 Correct 448 ms 4692 KB Output is correct
28 Correct 442 ms 4544 KB Output is correct
29 Correct 445 ms 4544 KB Output is correct
30 Correct 490 ms 4548 KB Output is correct
31 Correct 492 ms 4444 KB Output is correct
32 Correct 483 ms 4548 KB Output is correct
33 Correct 486 ms 4440 KB Output is correct
34 Correct 487 ms 4544 KB Output is correct
35 Correct 490 ms 4688 KB Output is correct
36 Correct 490 ms 4444 KB Output is correct
37 Correct 493 ms 4548 KB Output is correct
38 Correct 489 ms 4688 KB Output is correct
39 Correct 15 ms 4444 KB Output is correct
40 Correct 16 ms 4552 KB Output is correct
41 Correct 15 ms 4444 KB Output is correct
42 Correct 18 ms 4556 KB Output is correct
43 Correct 15 ms 4444 KB Output is correct
44 Correct 16 ms 4444 KB Output is correct
45 Correct 17 ms 4444 KB Output is correct
46 Correct 16 ms 4440 KB Output is correct
47 Correct 16 ms 4444 KB Output is correct
48 Correct 19 ms 4440 KB Output is correct
49 Correct 18 ms 4444 KB Output is correct
50 Correct 15 ms 4544 KB Output is correct
51 Correct 14 ms 4444 KB Output is correct
52 Correct 15 ms 4444 KB Output is correct
53 Correct 15 ms 4444 KB Output is correct
54 Correct 13 ms 4552 KB Output is correct
55 Correct 13 ms 4552 KB Output is correct
56 Correct 12 ms 4444 KB Output is correct
57 Correct 13 ms 4440 KB Output is correct
58 Correct 13 ms 4440 KB Output is correct
59 Correct 634 ms 4696 KB Output is correct
60 Correct 634 ms 4544 KB Output is correct
61 Correct 621 ms 4692 KB Output is correct
62 Correct 630 ms 4544 KB Output is correct
63 Correct 635 ms 4548 KB Output is correct
64 Correct 704 ms 4548 KB Output is correct
65 Correct 705 ms 4544 KB Output is correct
66 Correct 699 ms 4692 KB Output is correct
67 Correct 695 ms 4444 KB Output is correct
68 Correct 704 ms 4444 KB Output is correct
69 Correct 600 ms 4548 KB Output is correct
70 Correct 599 ms 4440 KB Output is correct
71 Correct 597 ms 4548 KB Output is correct
72 Correct 597 ms 4548 KB Output is correct
73 Correct 601 ms 4692 KB Output is correct
74 Correct 141 ms 4544 KB Output is correct
75 Correct 145 ms 4548 KB Output is correct
76 Correct 144 ms 4440 KB Output is correct
77 Correct 144 ms 4552 KB Output is correct
78 Correct 144 ms 4548 KB Output is correct