Submission #667418

# Submission time Handle Problem Language Result Execution time Memory
667418 2022-12-01T09:45:24 Z MohammadAghil Boat (APIO16_boat) C++17
100 / 100
645 ms 4412 KB
      #include <bits/stdc++.h>
//   #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
 using namespace std;
  typedef long long ll;
   typedef pair<ll, ll> pp;
     #define per(i,r,l) for(int i = (r); i >= (l); i--)
       #define rep(i,l,r) for(int i = (l); i < (r); i++)
          #define all(x) begin(x), end(x)
             #define sz(x) (int)(x).size()
                 #define pb push_back
                     #define ss second
                          #define ff first
                                  void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
void IOS(){
     cin.tie(0) -> sync_with_stdio(0);
     // #ifndef ONLINE_JUDGE
     //      #define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
     //      freopen("inp.txt", "r", stdin);
     //      freopen("out.txt", "w", stdout);
     // #else
     //      #define er(args ...) 0
     // #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 1e9 + 7, maxn = 5e2 + 5, lg = 17, inf = ll(1e18) + 5, p = 9973;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll,md);return k*k%md*(b&1ll?a:1)%md;}
 
ll dp[maxn][maxn<<1], a[maxn], b[maxn];
ll inv[maxn];

int main(){ IOS();
     inv[0] = 1;
     rep(i,1,maxn) inv[i] = pw(i, mod-2);
     
     int n; cin >> n;
     vector<int> p{0};
     rep(i,1,n+1){
          cin >> a[i] >> b[i];
          b[i]++;
          p.pb(a[i]), p.pb(b[i]);
     }
     sort(all(p)), p.erase(unique(all(p)), end(p));
     int m = sz(p);
     rep(i,0,m) dp[0][i] = 1;
     rep(i,1,n+1){
          int t = upper_bound(all(p), a[i]) - begin(p);
          rep(j,t,m){
               dp[i][j] = dp[i][j-1];
               if(p[j] > b[i]) continue;
               ll cr = p[j] - p[j-1];
               int s = 1;
               per(k,i-1,0){
                    dp[i][j] += cr*dp[k][j-1]%mod;
                    dp[i][j] %= mod;

                    if(a[k] <= p[j-1] && b[k] >= p[j]){
                         cr = cr*(s + p[j] - p[j-1])%mod;
                         s++;
                         cr = cr*inv[s]%mod;
                    }
               }
               // er(i, j, p[j], dp[i][j]);
          }
     } 
     ll ans = 0;
     rep(i,1,n+1) ans += dp[i][m-1], ans %= mod;
     cout << ans << '\n';
     return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3796 KB Output is correct
2 Correct 4 ms 3796 KB Output is correct
3 Correct 5 ms 3800 KB Output is correct
4 Correct 4 ms 3796 KB Output is correct
5 Correct 4 ms 3796 KB Output is correct
6 Correct 4 ms 3796 KB Output is correct
7 Correct 5 ms 3812 KB Output is correct
8 Correct 4 ms 3924 KB Output is correct
9 Correct 4 ms 3796 KB Output is correct
10 Correct 4 ms 3796 KB Output is correct
11 Correct 4 ms 3796 KB Output is correct
12 Correct 5 ms 3776 KB Output is correct
13 Correct 4 ms 3808 KB Output is correct
14 Correct 3 ms 3796 KB Output is correct
15 Correct 3 ms 3796 KB Output is correct
16 Correct 3 ms 2772 KB Output is correct
17 Correct 3 ms 2772 KB Output is correct
18 Correct 3 ms 2772 KB Output is correct
19 Correct 3 ms 2772 KB Output is correct
20 Correct 4 ms 2772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3796 KB Output is correct
2 Correct 4 ms 3796 KB Output is correct
3 Correct 5 ms 3800 KB Output is correct
4 Correct 4 ms 3796 KB Output is correct
5 Correct 4 ms 3796 KB Output is correct
6 Correct 4 ms 3796 KB Output is correct
7 Correct 5 ms 3812 KB Output is correct
8 Correct 4 ms 3924 KB Output is correct
9 Correct 4 ms 3796 KB Output is correct
10 Correct 4 ms 3796 KB Output is correct
11 Correct 4 ms 3796 KB Output is correct
12 Correct 5 ms 3776 KB Output is correct
13 Correct 4 ms 3808 KB Output is correct
14 Correct 3 ms 3796 KB Output is correct
15 Correct 3 ms 3796 KB Output is correct
16 Correct 3 ms 2772 KB Output is correct
17 Correct 3 ms 2772 KB Output is correct
18 Correct 3 ms 2772 KB Output is correct
19 Correct 3 ms 2772 KB Output is correct
20 Correct 4 ms 2772 KB Output is correct
21 Correct 270 ms 4112 KB Output is correct
22 Correct 292 ms 4024 KB Output is correct
23 Correct 225 ms 4044 KB Output is correct
24 Correct 257 ms 4092 KB Output is correct
25 Correct 259 ms 3964 KB Output is correct
26 Correct 465 ms 4412 KB Output is correct
27 Correct 484 ms 4256 KB Output is correct
28 Correct 483 ms 4276 KB Output is correct
29 Correct 501 ms 4196 KB Output is correct
30 Correct 5 ms 3796 KB Output is correct
31 Correct 5 ms 3796 KB Output is correct
32 Correct 5 ms 3748 KB Output is correct
33 Correct 5 ms 3796 KB Output is correct
34 Correct 5 ms 3796 KB Output is correct
35 Correct 6 ms 3800 KB Output is correct
36 Correct 5 ms 3804 KB Output is correct
37 Correct 6 ms 3796 KB Output is correct
38 Correct 6 ms 3796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 852 KB Output is correct
2 Correct 3 ms 852 KB Output is correct
3 Correct 3 ms 852 KB Output is correct
4 Correct 3 ms 852 KB Output is correct
5 Correct 4 ms 852 KB Output is correct
6 Correct 6 ms 852 KB Output is correct
7 Correct 5 ms 852 KB Output is correct
8 Correct 5 ms 856 KB Output is correct
9 Correct 6 ms 856 KB Output is correct
10 Correct 6 ms 852 KB Output is correct
11 Correct 3 ms 852 KB Output is correct
12 Correct 3 ms 844 KB Output is correct
13 Correct 3 ms 852 KB Output is correct
14 Correct 3 ms 852 KB Output is correct
15 Correct 4 ms 852 KB Output is correct
16 Correct 2 ms 724 KB Output is correct
17 Correct 2 ms 724 KB Output is correct
18 Correct 2 ms 724 KB Output is correct
19 Correct 2 ms 724 KB Output is correct
20 Correct 3 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3796 KB Output is correct
2 Correct 4 ms 3796 KB Output is correct
3 Correct 5 ms 3800 KB Output is correct
4 Correct 4 ms 3796 KB Output is correct
5 Correct 4 ms 3796 KB Output is correct
6 Correct 4 ms 3796 KB Output is correct
7 Correct 5 ms 3812 KB Output is correct
8 Correct 4 ms 3924 KB Output is correct
9 Correct 4 ms 3796 KB Output is correct
10 Correct 4 ms 3796 KB Output is correct
11 Correct 4 ms 3796 KB Output is correct
12 Correct 5 ms 3776 KB Output is correct
13 Correct 4 ms 3808 KB Output is correct
14 Correct 3 ms 3796 KB Output is correct
15 Correct 3 ms 3796 KB Output is correct
16 Correct 3 ms 2772 KB Output is correct
17 Correct 3 ms 2772 KB Output is correct
18 Correct 3 ms 2772 KB Output is correct
19 Correct 3 ms 2772 KB Output is correct
20 Correct 4 ms 2772 KB Output is correct
21 Correct 270 ms 4112 KB Output is correct
22 Correct 292 ms 4024 KB Output is correct
23 Correct 225 ms 4044 KB Output is correct
24 Correct 257 ms 4092 KB Output is correct
25 Correct 259 ms 3964 KB Output is correct
26 Correct 465 ms 4412 KB Output is correct
27 Correct 484 ms 4256 KB Output is correct
28 Correct 483 ms 4276 KB Output is correct
29 Correct 501 ms 4196 KB Output is correct
30 Correct 5 ms 3796 KB Output is correct
31 Correct 5 ms 3796 KB Output is correct
32 Correct 5 ms 3748 KB Output is correct
33 Correct 5 ms 3796 KB Output is correct
34 Correct 5 ms 3796 KB Output is correct
35 Correct 6 ms 3800 KB Output is correct
36 Correct 5 ms 3804 KB Output is correct
37 Correct 6 ms 3796 KB Output is correct
38 Correct 6 ms 3796 KB Output is correct
39 Correct 3 ms 852 KB Output is correct
40 Correct 3 ms 852 KB Output is correct
41 Correct 3 ms 852 KB Output is correct
42 Correct 3 ms 852 KB Output is correct
43 Correct 4 ms 852 KB Output is correct
44 Correct 6 ms 852 KB Output is correct
45 Correct 5 ms 852 KB Output is correct
46 Correct 5 ms 856 KB Output is correct
47 Correct 6 ms 856 KB Output is correct
48 Correct 6 ms 852 KB Output is correct
49 Correct 3 ms 852 KB Output is correct
50 Correct 3 ms 844 KB Output is correct
51 Correct 3 ms 852 KB Output is correct
52 Correct 3 ms 852 KB Output is correct
53 Correct 4 ms 852 KB Output is correct
54 Correct 2 ms 724 KB Output is correct
55 Correct 2 ms 724 KB Output is correct
56 Correct 2 ms 724 KB Output is correct
57 Correct 2 ms 724 KB Output is correct
58 Correct 3 ms 724 KB Output is correct
59 Correct 297 ms 4092 KB Output is correct
60 Correct 283 ms 4132 KB Output is correct
61 Correct 251 ms 4008 KB Output is correct
62 Correct 353 ms 4040 KB Output is correct
63 Correct 305 ms 4116 KB Output is correct
64 Correct 645 ms 4356 KB Output is correct
65 Correct 577 ms 4248 KB Output is correct
66 Correct 550 ms 4184 KB Output is correct
67 Correct 545 ms 4336 KB Output is correct
68 Correct 532 ms 4304 KB Output is correct
69 Correct 230 ms 4124 KB Output is correct
70 Correct 225 ms 4028 KB Output is correct
71 Correct 219 ms 4080 KB Output is correct
72 Correct 241 ms 4080 KB Output is correct
73 Correct 243 ms 4136 KB Output is correct
74 Correct 60 ms 2740 KB Output is correct
75 Correct 56 ms 2764 KB Output is correct
76 Correct 58 ms 2856 KB Output is correct
77 Correct 58 ms 2932 KB Output is correct
78 Correct 61 ms 2792 KB Output is correct