Submission #500523

# Submission time Handle Problem Language Result Execution time Memory
500523 2021-12-31T09:44:31 Z doowey Boat (APIO16_boat) C++14
100 / 100
1689 ms 13436 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = 505;
const int M = N * 4;
const int MOD = (int)1e9 + 7;
int L[N], R[N];

int C[M][N];
int I[N][N];

int fin[M][N];

int powr(int n, int k){
    if(k == 0) return 1;
    int p = powr(n, k / 2);
    p = (p * 1ll * p) % MOD;
    if(k % 2 == 1) p = (p * 1ll * n) % MOD;
    return p;
}

void add(int &a, int b){
    a += b;
    if(a >= MOD) a -= MOD;
    else if(a < 0) a += MOD;
}

int dp[N][M];
int dif[N];


int main(){
    fastIO;
    //freopen("in.txt","r",stdin);
    int n;
    cin >> n;
    vector<int> pp;
    for(int i = 1; i <= n; i ++ ){
        cin >> L[i] >> R[i];
        pp.push_back(L[i]);
        pp.push_back(R[i]);
    }
    sort(pp.begin(), pp.end());
    pp.resize(unique(pp.begin(), pp.end()) - pp.begin());
    vector<pii> segm;
    for(int i = 0 ; i < pp.size(); i ++ ){
        segm.push_back(mp(pp[i], pp[i]));
        if(i + 1 < pp.size() && pp[i] + 1 <= pp[i + 1] - 1){
            segm.push_back(mp(pp[i] + 1, pp[i + 1] - 1));
        }
    }
    int m = segm.size();
    for(int i = 0; i < N ;i ++ ){
        I[i][0] = 1;
    }
    for(int k = 1; k < N ; k ++ ){
        for(int i = 1; i < N ; i ++ ){
            add(I[i][k], I[i-1][k]);
            add(I[i][k], I[i-1][k-1]);
        }
    }
    int sz;
    int P, Q;
    int inv;
    int cum;
    for(int i = 0 ; i < m ; i ++ ){
        sz = segm[i].se - segm[i].fi + 1;
        P = Q = 1;
        for(int j = 1; j <= n; j ++ ){
            if(j > sz) break;
            P = (P * 1ll * (sz - j + 1)) % MOD;
            Q = (Q * 1ll * j) % MOD;
            inv = powr(Q, MOD - 2);
            C[i][j] = (P * 1ll * inv) % MOD;
        }
        if(sz == 1){
            for(int j = 1; j <= n; j ++ ){
                fin[i][j] = j;
            }
        }
        else{
            for(int j = 1; j <= n; j ++ ){
                for(int v = 1; v <= j; v ++ ){
                    add(fin[i][j], (C[i][v] * 1ll * I[j][v]) % MOD);
                }
            }
        }
        for(int j = n; j >= 1; j -- ){
            add(fin[i][j], -fin[i][j-1]);
        }
    }

    int tl, tr;
    int mm;
    int side;
    int res = 0;
    for(int i = 1; i <= n; i ++ ){
        for(int j = 0 ; j < m ; j ++ ){
            tl = segm[j].fi;
            tr = segm[j].se;
            if(L[i] <= tl && tr <= R[i]){
                if(tl == tr){
                    add(dp[i][j], +1);
                    if(j > 0){
                        for(int v = i - 1; v >= 1; v -- ){
                            add(dp[i][j], dp[v][j-1]);
                        }
                    }
                }
                else{
                    mm = 0;
                    for(int v = i; v >= 1; v -- ){

                        if(L[v] <= tl && tr <= R[v]) mm ++ ;
                        side = 0;
                        if(j > 0) add(side, dp[v - 1][j - 1]);
                        if(v == 1) add(side, 1);
                        add(dp[i][j], (side * 1ll * fin[j][mm]) % MOD);
                    }
                }
            }
            add(res, dp[i][j]);
            if(j)
                add(dp[i][j], dp[i][j-1]);
        }
    }

    cout << res << "\n";
    return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:55:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     for(int i = 0 ; i < pp.size(); i ++ ){
      |                     ~~^~~~~~~~~~~
boat.cpp:57:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |         if(i + 1 < pp.size() && pp[i] + 1 <= pp[i + 1] - 1){
      |            ~~~~~~^~~~~~~~~~~
boat.cpp:74:9: warning: unused variable 'cum' [-Wunused-variable]
   74 |     int cum;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 500 ms 9192 KB Output is correct
2 Correct 469 ms 9112 KB Output is correct
3 Correct 484 ms 9340 KB Output is correct
4 Correct 464 ms 9224 KB Output is correct
5 Correct 481 ms 9132 KB Output is correct
6 Correct 473 ms 9124 KB Output is correct
7 Correct 465 ms 9284 KB Output is correct
8 Correct 456 ms 9452 KB Output is correct
9 Correct 454 ms 9152 KB Output is correct
10 Correct 459 ms 9268 KB Output is correct
11 Correct 460 ms 9160 KB Output is correct
12 Correct 460 ms 9312 KB Output is correct
13 Correct 457 ms 9232 KB Output is correct
14 Correct 457 ms 9156 KB Output is correct
15 Correct 465 ms 9324 KB Output is correct
16 Correct 85 ms 4304 KB Output is correct
17 Correct 90 ms 4308 KB Output is correct
18 Correct 85 ms 4344 KB Output is correct
19 Correct 89 ms 4380 KB Output is correct
20 Correct 91 ms 4356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 500 ms 9192 KB Output is correct
2 Correct 469 ms 9112 KB Output is correct
3 Correct 484 ms 9340 KB Output is correct
4 Correct 464 ms 9224 KB Output is correct
5 Correct 481 ms 9132 KB Output is correct
6 Correct 473 ms 9124 KB Output is correct
7 Correct 465 ms 9284 KB Output is correct
8 Correct 456 ms 9452 KB Output is correct
9 Correct 454 ms 9152 KB Output is correct
10 Correct 459 ms 9268 KB Output is correct
11 Correct 460 ms 9160 KB Output is correct
12 Correct 460 ms 9312 KB Output is correct
13 Correct 457 ms 9232 KB Output is correct
14 Correct 457 ms 9156 KB Output is correct
15 Correct 465 ms 9324 KB Output is correct
16 Correct 85 ms 4304 KB Output is correct
17 Correct 90 ms 4308 KB Output is correct
18 Correct 85 ms 4344 KB Output is correct
19 Correct 89 ms 4380 KB Output is correct
20 Correct 91 ms 4356 KB Output is correct
21 Correct 681 ms 11856 KB Output is correct
22 Correct 675 ms 11808 KB Output is correct
23 Correct 642 ms 11748 KB Output is correct
24 Correct 686 ms 12108 KB Output is correct
25 Correct 667 ms 11716 KB Output is correct
26 Correct 716 ms 11388 KB Output is correct
27 Correct 751 ms 11440 KB Output is correct
28 Correct 740 ms 11604 KB Output is correct
29 Correct 751 ms 11704 KB Output is correct
30 Correct 553 ms 12612 KB Output is correct
31 Correct 557 ms 12468 KB Output is correct
32 Correct 560 ms 12640 KB Output is correct
33 Correct 573 ms 12540 KB Output is correct
34 Correct 584 ms 12492 KB Output is correct
35 Correct 446 ms 9340 KB Output is correct
36 Correct 435 ms 9156 KB Output is correct
37 Correct 467 ms 9236 KB Output is correct
38 Correct 445 ms 9180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 3404 KB Output is correct
2 Correct 22 ms 3456 KB Output is correct
3 Correct 23 ms 3376 KB Output is correct
4 Correct 19 ms 3344 KB Output is correct
5 Correct 20 ms 3428 KB Output is correct
6 Correct 21 ms 3392 KB Output is correct
7 Correct 21 ms 3372 KB Output is correct
8 Correct 21 ms 3444 KB Output is correct
9 Correct 21 ms 3396 KB Output is correct
10 Correct 21 ms 3352 KB Output is correct
11 Correct 20 ms 3388 KB Output is correct
12 Correct 18 ms 3336 KB Output is correct
13 Correct 18 ms 3456 KB Output is correct
14 Correct 19 ms 3424 KB Output is correct
15 Correct 19 ms 3440 KB Output is correct
16 Correct 9 ms 2380 KB Output is correct
17 Correct 9 ms 2444 KB Output is correct
18 Correct 10 ms 2380 KB Output is correct
19 Correct 9 ms 2380 KB Output is correct
20 Correct 10 ms 2380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 500 ms 9192 KB Output is correct
2 Correct 469 ms 9112 KB Output is correct
3 Correct 484 ms 9340 KB Output is correct
4 Correct 464 ms 9224 KB Output is correct
5 Correct 481 ms 9132 KB Output is correct
6 Correct 473 ms 9124 KB Output is correct
7 Correct 465 ms 9284 KB Output is correct
8 Correct 456 ms 9452 KB Output is correct
9 Correct 454 ms 9152 KB Output is correct
10 Correct 459 ms 9268 KB Output is correct
11 Correct 460 ms 9160 KB Output is correct
12 Correct 460 ms 9312 KB Output is correct
13 Correct 457 ms 9232 KB Output is correct
14 Correct 457 ms 9156 KB Output is correct
15 Correct 465 ms 9324 KB Output is correct
16 Correct 85 ms 4304 KB Output is correct
17 Correct 90 ms 4308 KB Output is correct
18 Correct 85 ms 4344 KB Output is correct
19 Correct 89 ms 4380 KB Output is correct
20 Correct 91 ms 4356 KB Output is correct
21 Correct 681 ms 11856 KB Output is correct
22 Correct 675 ms 11808 KB Output is correct
23 Correct 642 ms 11748 KB Output is correct
24 Correct 686 ms 12108 KB Output is correct
25 Correct 667 ms 11716 KB Output is correct
26 Correct 716 ms 11388 KB Output is correct
27 Correct 751 ms 11440 KB Output is correct
28 Correct 740 ms 11604 KB Output is correct
29 Correct 751 ms 11704 KB Output is correct
30 Correct 553 ms 12612 KB Output is correct
31 Correct 557 ms 12468 KB Output is correct
32 Correct 560 ms 12640 KB Output is correct
33 Correct 573 ms 12540 KB Output is correct
34 Correct 584 ms 12492 KB Output is correct
35 Correct 446 ms 9340 KB Output is correct
36 Correct 435 ms 9156 KB Output is correct
37 Correct 467 ms 9236 KB Output is correct
38 Correct 445 ms 9180 KB Output is correct
39 Correct 19 ms 3404 KB Output is correct
40 Correct 22 ms 3456 KB Output is correct
41 Correct 23 ms 3376 KB Output is correct
42 Correct 19 ms 3344 KB Output is correct
43 Correct 20 ms 3428 KB Output is correct
44 Correct 21 ms 3392 KB Output is correct
45 Correct 21 ms 3372 KB Output is correct
46 Correct 21 ms 3444 KB Output is correct
47 Correct 21 ms 3396 KB Output is correct
48 Correct 21 ms 3352 KB Output is correct
49 Correct 20 ms 3388 KB Output is correct
50 Correct 18 ms 3336 KB Output is correct
51 Correct 18 ms 3456 KB Output is correct
52 Correct 19 ms 3424 KB Output is correct
53 Correct 19 ms 3440 KB Output is correct
54 Correct 9 ms 2380 KB Output is correct
55 Correct 9 ms 2444 KB Output is correct
56 Correct 10 ms 2380 KB Output is correct
57 Correct 9 ms 2380 KB Output is correct
58 Correct 10 ms 2380 KB Output is correct
59 Correct 1528 ms 13152 KB Output is correct
60 Correct 1519 ms 13344 KB Output is correct
61 Correct 1518 ms 13184 KB Output is correct
62 Correct 1584 ms 13284 KB Output is correct
63 Correct 1573 ms 13232 KB Output is correct
64 Correct 1686 ms 13196 KB Output is correct
65 Correct 1686 ms 13240 KB Output is correct
66 Correct 1673 ms 13216 KB Output is correct
67 Correct 1683 ms 13208 KB Output is correct
68 Correct 1689 ms 13208 KB Output is correct
69 Correct 1437 ms 13260 KB Output is correct
70 Correct 1459 ms 13176 KB Output is correct
71 Correct 1421 ms 13436 KB Output is correct
72 Correct 1467 ms 13148 KB Output is correct
73 Correct 1593 ms 13092 KB Output is correct
74 Correct 176 ms 4508 KB Output is correct
75 Correct 174 ms 4416 KB Output is correct
76 Correct 161 ms 4504 KB Output is correct
77 Correct 164 ms 4512 KB Output is correct
78 Correct 176 ms 4488 KB Output is correct