Submission #554421

# Submission time Handle Problem Language Result Execution time Memory
554421 2022-04-28T11:18:30 Z fatemetmhr Boat (APIO16_boat) C++17
58 / 100
2000 ms 7432 KB
// Be name khoda //


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define all(x)     x.begin(), x.end()
#define fi         first
#define se         second
#define pb         push_back

const int maxn5 = 5e2 + 5;
const int maxnb = 1e3 + 10;
const int mod   = 1e9 + 7;

int ent[maxn5][maxn5], val[maxnb][maxn5];
int ent2[maxnb][maxn5], szb[maxnb];
int l[maxn5], r[maxn5], ansel[maxn5][maxnb];
int ansbl[maxnb];
vector <int> exx;

inline ll pw(ll a, ll b){
    ll ret = 1;
    for(; b; b >>= 1, a = a * a % mod)
        if(b&1) ret = ret * a % mod;
    return ret;
}

inline ll entof(ll n, ll r){
    ll s = 1, m = 1;
    for(int i = 0; i < r; i++){
        s = s * (n - i) % mod;
        m = m * (i + 1) % mod;
    }
    return (s * pw(m, mod - 2)) % mod;
}


int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);


    int n; cin >> n;
    for(int i = 0; i < n; i++){
        cin >> l[i] >> r[i]; // (..]
        r[i]++;
        exx.pb(l[i]);
        exx.pb(r[i]);
    }
    exx.pb(0);
    sort(all(exx));
    exx.resize(unique(all(exx)) - exx.begin());
    for(int i = 0; i < n; i++){
        l[i] = lower_bound(all(exx), l[i]) - exx.begin();
        r[i] = lower_bound(all(exx), r[i]) - exx.begin();
        //cout << "segment " << i << ' ' << l[i] << ' ' << r[i] << endl;
    }
    for(int i = 1; i < exx.size(); i++){
        szb[i] = exx[i] - exx[i - 1];
        //cout << "a bl of " << exx[i] << ' ' << exx[i - 1] << ' ' << szb[i + 1] << endl;
    }
    int blsz = exx.size();

    ent[0][0] = 1;
    for(int i = 1; i < maxn5; i++){
        ent[i][0] = 1;
        for(int j = 1; j <= i; j++)
            ent[i][j] = (ent[i - 1][j - 1] + ent[i - 1][j]) % mod;
    }
    
    for(int i = 1; i < blsz; i++) for(int j = 0; j < maxn5 && j <= szb[i]; j++){
        ent2[i][j] = entof(szb[i], j);
    }


    for(int i = 1; i < blsz; i++) for(int j = 1; j < n; j++){ // bl e i om hast va j nafar davtalab
        // val[i][j] = SIGMA z : C(sz[i], z + 1) * C(j, z);
        for(int z = 1; z + 1 <= szb[i] && z <= j; z++)
            val[i][j] = (val[i][j] + ll(ent2[i][z + 1]) * ent[j][z]) % mod;
        //assert(val[i][j] <= 1 || szb[i] > 1);
    }

    ansbl[0] = 1;
    for(int i = 0; i < n; i++){
        for(int j = l[i] + 1; j <= r[i]; j++){
            for(int k = 0; k < j; k++)
                ansel[i][j] = (ansel[i][j] + ansbl[k] * ll(szb[j])) % mod;
            //cout << "cur having " << i << ' ' << j << ' ' << ansel[i][j] << endl;
            if(i == 0)
                continue;
            int num = l[i - 1] < j && j <= r[i - 1];
            for(int k = i - 2; k >= 0; k--){
                //cout << "aha " << i << ' ' << j << ' ' << k << ' ' << num << ' ' << ansel[k][j - 1] << endl;
                if(num)
                    ansel[i][j] = (ansel[i][j] + ll(ansel[k][j - 1]) * val[j][num]) % mod;
                //assert(szb[j] == 1);
                //cout << "with " << i << ' ' << j << ' ' << k << ' ' << num << ' ' << ' ' << ansel[k][j - 1] << ' ' << val[j][num] << ' ' << ansel[i][j] << endl;
                num += l[k] < j && j <= r[k];
            }
            if(num)
                ansel[i][j] = (ansel[i][j] + val[j][num]) % mod;
        }
        for(int j = l[i] + 1; j <= r[i]; j++){
            ansbl[j] = (ansbl[j] + ansel[i][j]) % mod;
            //cout << i << ' ' << j << ' ' << ansel[i][j] << endl;
        }
        for(int j = 1; j < blsz; j++)
            ansel[i][j] = (ansel[i][j - 1] + ansel[i][j]) % mod;
    }
    ll out = 0;
    for(int i = 1; i < blsz; i++)
        out += ansbl[i];
    cout << out % mod << endl;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:61:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |     for(int i = 1; i < exx.size(); i++){
      |                    ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 629 ms 7168 KB Output is correct
2 Correct 638 ms 7312 KB Output is correct
3 Correct 635 ms 7240 KB Output is correct
4 Correct 614 ms 7196 KB Output is correct
5 Correct 628 ms 7164 KB Output is correct
6 Correct 636 ms 7264 KB Output is correct
7 Correct 642 ms 7228 KB Output is correct
8 Correct 632 ms 7216 KB Output is correct
9 Correct 614 ms 7244 KB Output is correct
10 Correct 642 ms 7332 KB Output is correct
11 Correct 643 ms 7336 KB Output is correct
12 Correct 617 ms 7264 KB Output is correct
13 Correct 622 ms 7264 KB Output is correct
14 Correct 630 ms 7144 KB Output is correct
15 Correct 631 ms 7176 KB Output is correct
16 Correct 122 ms 3932 KB Output is correct
17 Correct 126 ms 3980 KB Output is correct
18 Correct 119 ms 3928 KB Output is correct
19 Correct 122 ms 3964 KB Output is correct
20 Correct 126 ms 3936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 629 ms 7168 KB Output is correct
2 Correct 638 ms 7312 KB Output is correct
3 Correct 635 ms 7240 KB Output is correct
4 Correct 614 ms 7196 KB Output is correct
5 Correct 628 ms 7164 KB Output is correct
6 Correct 636 ms 7264 KB Output is correct
7 Correct 642 ms 7228 KB Output is correct
8 Correct 632 ms 7216 KB Output is correct
9 Correct 614 ms 7244 KB Output is correct
10 Correct 642 ms 7332 KB Output is correct
11 Correct 643 ms 7336 KB Output is correct
12 Correct 617 ms 7264 KB Output is correct
13 Correct 622 ms 7264 KB Output is correct
14 Correct 630 ms 7144 KB Output is correct
15 Correct 631 ms 7176 KB Output is correct
16 Correct 122 ms 3932 KB Output is correct
17 Correct 126 ms 3980 KB Output is correct
18 Correct 119 ms 3928 KB Output is correct
19 Correct 122 ms 3964 KB Output is correct
20 Correct 126 ms 3936 KB Output is correct
21 Correct 610 ms 6900 KB Output is correct
22 Correct 641 ms 7116 KB Output is correct
23 Correct 616 ms 6768 KB Output is correct
24 Correct 642 ms 6772 KB Output is correct
25 Correct 632 ms 6844 KB Output is correct
26 Correct 818 ms 6840 KB Output is correct
27 Correct 850 ms 6856 KB Output is correct
28 Correct 797 ms 6820 KB Output is correct
29 Correct 782 ms 6828 KB Output is correct
30 Correct 578 ms 7212 KB Output is correct
31 Correct 574 ms 7176 KB Output is correct
32 Correct 574 ms 7332 KB Output is correct
33 Correct 576 ms 7164 KB Output is correct
34 Correct 569 ms 7264 KB Output is correct
35 Correct 573 ms 7156 KB Output is correct
36 Correct 563 ms 7268 KB Output is correct
37 Correct 588 ms 7148 KB Output is correct
38 Correct 569 ms 7316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 151 ms 2500 KB Output is correct
2 Correct 154 ms 2472 KB Output is correct
3 Correct 149 ms 2524 KB Output is correct
4 Correct 146 ms 2416 KB Output is correct
5 Correct 149 ms 2572 KB Output is correct
6 Correct 150 ms 2508 KB Output is correct
7 Correct 146 ms 2500 KB Output is correct
8 Correct 150 ms 2476 KB Output is correct
9 Correct 160 ms 2468 KB Output is correct
10 Correct 151 ms 2496 KB Output is correct
11 Correct 148 ms 2536 KB Output is correct
12 Correct 147 ms 2448 KB Output is correct
13 Correct 149 ms 2508 KB Output is correct
14 Correct 153 ms 2584 KB Output is correct
15 Correct 149 ms 2484 KB Output is correct
16 Correct 64 ms 2152 KB Output is correct
17 Correct 65 ms 2136 KB Output is correct
18 Correct 66 ms 2136 KB Output is correct
19 Correct 64 ms 2092 KB Output is correct
20 Correct 68 ms 2044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 629 ms 7168 KB Output is correct
2 Correct 638 ms 7312 KB Output is correct
3 Correct 635 ms 7240 KB Output is correct
4 Correct 614 ms 7196 KB Output is correct
5 Correct 628 ms 7164 KB Output is correct
6 Correct 636 ms 7264 KB Output is correct
7 Correct 642 ms 7228 KB Output is correct
8 Correct 632 ms 7216 KB Output is correct
9 Correct 614 ms 7244 KB Output is correct
10 Correct 642 ms 7332 KB Output is correct
11 Correct 643 ms 7336 KB Output is correct
12 Correct 617 ms 7264 KB Output is correct
13 Correct 622 ms 7264 KB Output is correct
14 Correct 630 ms 7144 KB Output is correct
15 Correct 631 ms 7176 KB Output is correct
16 Correct 122 ms 3932 KB Output is correct
17 Correct 126 ms 3980 KB Output is correct
18 Correct 119 ms 3928 KB Output is correct
19 Correct 122 ms 3964 KB Output is correct
20 Correct 126 ms 3936 KB Output is correct
21 Correct 610 ms 6900 KB Output is correct
22 Correct 641 ms 7116 KB Output is correct
23 Correct 616 ms 6768 KB Output is correct
24 Correct 642 ms 6772 KB Output is correct
25 Correct 632 ms 6844 KB Output is correct
26 Correct 818 ms 6840 KB Output is correct
27 Correct 850 ms 6856 KB Output is correct
28 Correct 797 ms 6820 KB Output is correct
29 Correct 782 ms 6828 KB Output is correct
30 Correct 578 ms 7212 KB Output is correct
31 Correct 574 ms 7176 KB Output is correct
32 Correct 574 ms 7332 KB Output is correct
33 Correct 576 ms 7164 KB Output is correct
34 Correct 569 ms 7264 KB Output is correct
35 Correct 573 ms 7156 KB Output is correct
36 Correct 563 ms 7268 KB Output is correct
37 Correct 588 ms 7148 KB Output is correct
38 Correct 569 ms 7316 KB Output is correct
39 Correct 151 ms 2500 KB Output is correct
40 Correct 154 ms 2472 KB Output is correct
41 Correct 149 ms 2524 KB Output is correct
42 Correct 146 ms 2416 KB Output is correct
43 Correct 149 ms 2572 KB Output is correct
44 Correct 150 ms 2508 KB Output is correct
45 Correct 146 ms 2500 KB Output is correct
46 Correct 150 ms 2476 KB Output is correct
47 Correct 160 ms 2468 KB Output is correct
48 Correct 151 ms 2496 KB Output is correct
49 Correct 148 ms 2536 KB Output is correct
50 Correct 147 ms 2448 KB Output is correct
51 Correct 149 ms 2508 KB Output is correct
52 Correct 153 ms 2584 KB Output is correct
53 Correct 149 ms 2484 KB Output is correct
54 Correct 64 ms 2152 KB Output is correct
55 Correct 65 ms 2136 KB Output is correct
56 Correct 66 ms 2136 KB Output is correct
57 Correct 64 ms 2092 KB Output is correct
58 Correct 68 ms 2044 KB Output is correct
59 Correct 1924 ms 7240 KB Output is correct
60 Correct 1873 ms 7296 KB Output is correct
61 Correct 1849 ms 7432 KB Output is correct
62 Correct 1900 ms 7332 KB Output is correct
63 Correct 1884 ms 7264 KB Output is correct
64 Execution timed out 2086 ms 7224 KB Time limit exceeded
65 Halted 0 ms 0 KB -