답안 #554424

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
554424 2022-04-28T11:25:37 Z fatemetmhr Boat (APIO16_boat) C++17
100 / 100
1577 ms 7520 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;
}


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++){
        ll s = 1, m = 1;
        for(int j = 1; j < maxn5 && j <= szb[i]; j++){
            s = s * (szb[i] - j + 1) % mod;
            m = m * j % mod;
            ent2[i][j] = s * pw(m, mod - 2) % mod;
        }
    }


    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 < blsz; j++){
            ansbl[j] = (ansbl[j] + ansel[i][j]) % mod;
            ansel[i][j] = (ansel[i][j - 1] + ansel[i][j]) % mod;
            //cout << i << ' ' << j << ' ' << ansel[i][j] << endl;
        }
    }
    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:52:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for(int i = 1; i < exx.size(); i++){
      |                    ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 307 ms 7244 KB Output is correct
2 Correct 309 ms 7264 KB Output is correct
3 Correct 320 ms 7264 KB Output is correct
4 Correct 317 ms 7228 KB Output is correct
5 Correct 324 ms 7348 KB Output is correct
6 Correct 317 ms 7176 KB Output is correct
7 Correct 314 ms 7156 KB Output is correct
8 Correct 314 ms 7140 KB Output is correct
9 Correct 313 ms 7380 KB Output is correct
10 Correct 311 ms 7312 KB Output is correct
11 Correct 317 ms 7176 KB Output is correct
12 Correct 313 ms 7344 KB Output is correct
13 Correct 313 ms 7244 KB Output is correct
14 Correct 323 ms 7260 KB Output is correct
15 Correct 313 ms 7244 KB Output is correct
16 Correct 58 ms 3904 KB Output is correct
17 Correct 63 ms 4052 KB Output is correct
18 Correct 60 ms 3976 KB Output is correct
19 Correct 65 ms 4056 KB Output is correct
20 Correct 68 ms 3924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 307 ms 7244 KB Output is correct
2 Correct 309 ms 7264 KB Output is correct
3 Correct 320 ms 7264 KB Output is correct
4 Correct 317 ms 7228 KB Output is correct
5 Correct 324 ms 7348 KB Output is correct
6 Correct 317 ms 7176 KB Output is correct
7 Correct 314 ms 7156 KB Output is correct
8 Correct 314 ms 7140 KB Output is correct
9 Correct 313 ms 7380 KB Output is correct
10 Correct 311 ms 7312 KB Output is correct
11 Correct 317 ms 7176 KB Output is correct
12 Correct 313 ms 7344 KB Output is correct
13 Correct 313 ms 7244 KB Output is correct
14 Correct 323 ms 7260 KB Output is correct
15 Correct 313 ms 7244 KB Output is correct
16 Correct 58 ms 3904 KB Output is correct
17 Correct 63 ms 4052 KB Output is correct
18 Correct 60 ms 3976 KB Output is correct
19 Correct 65 ms 4056 KB Output is correct
20 Correct 68 ms 3924 KB Output is correct
21 Correct 599 ms 6912 KB Output is correct
22 Correct 572 ms 7048 KB Output is correct
23 Correct 559 ms 6904 KB Output is correct
24 Correct 560 ms 6860 KB Output is correct
25 Correct 589 ms 6824 KB Output is correct
26 Correct 817 ms 6844 KB Output is correct
27 Correct 833 ms 6884 KB Output is correct
28 Correct 777 ms 6760 KB Output is correct
29 Correct 783 ms 6760 KB Output is correct
30 Correct 298 ms 7132 KB Output is correct
31 Correct 302 ms 7216 KB Output is correct
32 Correct 299 ms 7244 KB Output is correct
33 Correct 301 ms 7236 KB Output is correct
34 Correct 303 ms 7204 KB Output is correct
35 Correct 295 ms 7216 KB Output is correct
36 Correct 299 ms 7236 KB Output is correct
37 Correct 296 ms 7164 KB Output is correct
38 Correct 299 ms 7244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 2448 KB Output is correct
2 Correct 25 ms 2516 KB Output is correct
3 Correct 24 ms 2508 KB Output is correct
4 Correct 25 ms 2508 KB Output is correct
5 Correct 25 ms 2408 KB Output is correct
6 Correct 27 ms 2508 KB Output is correct
7 Correct 28 ms 2516 KB Output is correct
8 Correct 27 ms 2500 KB Output is correct
9 Correct 29 ms 2508 KB Output is correct
10 Correct 28 ms 2464 KB Output is correct
11 Correct 25 ms 2452 KB Output is correct
12 Correct 24 ms 2528 KB Output is correct
13 Correct 24 ms 2524 KB Output is correct
14 Correct 24 ms 2516 KB Output is correct
15 Correct 27 ms 2488 KB Output is correct
16 Correct 12 ms 2132 KB Output is correct
17 Correct 13 ms 2132 KB Output is correct
18 Correct 12 ms 2128 KB Output is correct
19 Correct 12 ms 2152 KB Output is correct
20 Correct 12 ms 2124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 307 ms 7244 KB Output is correct
2 Correct 309 ms 7264 KB Output is correct
3 Correct 320 ms 7264 KB Output is correct
4 Correct 317 ms 7228 KB Output is correct
5 Correct 324 ms 7348 KB Output is correct
6 Correct 317 ms 7176 KB Output is correct
7 Correct 314 ms 7156 KB Output is correct
8 Correct 314 ms 7140 KB Output is correct
9 Correct 313 ms 7380 KB Output is correct
10 Correct 311 ms 7312 KB Output is correct
11 Correct 317 ms 7176 KB Output is correct
12 Correct 313 ms 7344 KB Output is correct
13 Correct 313 ms 7244 KB Output is correct
14 Correct 323 ms 7260 KB Output is correct
15 Correct 313 ms 7244 KB Output is correct
16 Correct 58 ms 3904 KB Output is correct
17 Correct 63 ms 4052 KB Output is correct
18 Correct 60 ms 3976 KB Output is correct
19 Correct 65 ms 4056 KB Output is correct
20 Correct 68 ms 3924 KB Output is correct
21 Correct 599 ms 6912 KB Output is correct
22 Correct 572 ms 7048 KB Output is correct
23 Correct 559 ms 6904 KB Output is correct
24 Correct 560 ms 6860 KB Output is correct
25 Correct 589 ms 6824 KB Output is correct
26 Correct 817 ms 6844 KB Output is correct
27 Correct 833 ms 6884 KB Output is correct
28 Correct 777 ms 6760 KB Output is correct
29 Correct 783 ms 6760 KB Output is correct
30 Correct 298 ms 7132 KB Output is correct
31 Correct 302 ms 7216 KB Output is correct
32 Correct 299 ms 7244 KB Output is correct
33 Correct 301 ms 7236 KB Output is correct
34 Correct 303 ms 7204 KB Output is correct
35 Correct 295 ms 7216 KB Output is correct
36 Correct 299 ms 7236 KB Output is correct
37 Correct 296 ms 7164 KB Output is correct
38 Correct 299 ms 7244 KB Output is correct
39 Correct 26 ms 2448 KB Output is correct
40 Correct 25 ms 2516 KB Output is correct
41 Correct 24 ms 2508 KB Output is correct
42 Correct 25 ms 2508 KB Output is correct
43 Correct 25 ms 2408 KB Output is correct
44 Correct 27 ms 2508 KB Output is correct
45 Correct 28 ms 2516 KB Output is correct
46 Correct 27 ms 2500 KB Output is correct
47 Correct 29 ms 2508 KB Output is correct
48 Correct 28 ms 2464 KB Output is correct
49 Correct 25 ms 2452 KB Output is correct
50 Correct 24 ms 2528 KB Output is correct
51 Correct 24 ms 2524 KB Output is correct
52 Correct 24 ms 2516 KB Output is correct
53 Correct 27 ms 2488 KB Output is correct
54 Correct 12 ms 2132 KB Output is correct
55 Correct 13 ms 2132 KB Output is correct
56 Correct 12 ms 2128 KB Output is correct
57 Correct 12 ms 2152 KB Output is correct
58 Correct 12 ms 2124 KB Output is correct
59 Correct 1268 ms 7316 KB Output is correct
60 Correct 1264 ms 7480 KB Output is correct
61 Correct 1201 ms 7400 KB Output is correct
62 Correct 1284 ms 7272 KB Output is correct
63 Correct 1255 ms 7232 KB Output is correct
64 Correct 1565 ms 7432 KB Output is correct
65 Correct 1571 ms 7268 KB Output is correct
66 Correct 1577 ms 7316 KB Output is correct
67 Correct 1574 ms 7520 KB Output is correct
68 Correct 1547 ms 7244 KB Output is correct
69 Correct 1184 ms 7324 KB Output is correct
70 Correct 1177 ms 7176 KB Output is correct
71 Correct 1161 ms 7268 KB Output is correct
72 Correct 1182 ms 7304 KB Output is correct
73 Correct 1190 ms 7196 KB Output is correct
74 Correct 134 ms 3912 KB Output is correct
75 Correct 130 ms 4004 KB Output is correct
76 Correct 133 ms 3936 KB Output is correct
77 Correct 136 ms 4044 KB Output is correct
78 Correct 136 ms 4000 KB Output is correct