답안 #523177

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
523177 2022-02-07T07:19:36 Z blue Boat (APIO16_boat) C++17
100 / 100
1686 ms 12356 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
#define sz(x) int(x.size())

const ll mod = 1'000'000'007;

ll mul(ll a, ll b)
{
    return (a*b) % mod;
}

ll ad(ll a, ll b)
{
    return (a+b) % mod;
}

ll sq(ll a)
{
    return mul(a,a);
}

ll pow(ll b, ll e)
{
    if(e == 0) return 1;
    else if(e % 2 == 1) return mul(b, pow(b, e-1));
    else return sq(pow(b, e/2));
}

ll get_inv(ll a)
{
    return pow(a, mod-2);
}

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

    int N;
    cin >> N;

    ll a[1+N], b[1+N];


    map<ll, ll> values;

    for(int i = 1; i <= N; i++)
    {
        cin >> a[i] >> b[i];
        b[i]++;

        values[a[i]] = 0;
        values[b[i]] = 0;
    }

    values[0] = 0;
    values[1] = 0;


    vll ep;

    for(auto& z : values) ep.push_back(z.first);

    int ct = sz(ep) - 1;

    vll blocksize(1+ct);
    blocksize[0] = 0;
    for(int i = 1; i <= ct; i++)
        blocksize[i] = ep[i] - ep[i-1];

    
    int x[1+N], y[1+N];


    // for(int i = 0; i <= ct; i++) cerr << i << " : " << ep[i] << ' ' << blocksize[i] << '\n';

    for(int i = 1; i <= N; i++)
    {
        x[i] = 0;
        int lo = 1, hi = ct;
        while(lo != hi)
        {
            int mid = (lo+hi)/2 + 1;
            if(ep[mid] <= a[i])
                lo = mid;
            else
                hi = mid-1;
        }
        x[i] = lo + 1;

        y[i] = 0;
        lo = 1, hi = ct;
        while(lo != hi)
        {
            int mid = (lo+hi)/2+1;
            if(ep[mid] <= b[i])
                lo = mid;
            else
                hi = mid-1;
        }
        y[i] = lo;
    }


    ll*** DP = new ll**[1+N];
    for(int i = 0; i <= N; i++)
    {
        if(i <= 1)
        {
            DP[i] = new ll*[1+ct];
            for(int j = 0; j <= ct; j++)
            {
                DP[i][j] = new ll[1+N];
                for(int k = 0; k <= N; k++) DP[i][j][k] = 0;
            }
        }
        else DP[i] = DP[i-2]; 
    }


    ll inv[1+N];
    for(int i = 1; i <= N; i++) inv[i] = get_inv(i);

    vvll DPsum(1+N, vll(1+ct, 0)); 

    // cerr << "!" <<  x[1] << ' ' << y[1] << '\n';
    for(int j = x[1]; j <= y[1]; j++)
    {
        DPsum[1][j] = ad(DPsum[1][j], blocksize[j]);
        DP[1][j][1] = blocksize[j];   
    }


    for(int i = 2; i <= N; i++)
    {   
       
        for(int j = 1; j <= ct; j++)
        {
            for(int k = 1; k <= i; k++)
            {
                DP[i][j][k] = DP[i-1][j][k];

                if(x[i] <= j && j <= y[i])
                {
                    if(j == 1 && k == 1)
                    {
                        ;//DP[i][1][1] = blocksize[j] * 
                    }
                    else if(j == 1)
                    {
                        ;
                    }
                    else if(k == 1)
                    {
                        ll curr = 1;

                        for(int j2 = 1; j2 < j; j2++)
                            curr = ad(curr, DPsum[i-1][j2]);

                        DP[i][j][1] = ad(DP[i][j][1], mul(curr, blocksize[j]));
                    }
                    else
                    {
                        if(k <= blocksize[j])
                            DP[i][j][k] = ad(DP[i][j][k], mul(DP[i-1][j][k-1], mul(blocksize[j] - k + 1, inv[k])));
                    }
                }

                DPsum[i][j] = ad(DPsum[i][j], DP[i][j][k]);
            }
        }
    }

    ll res = 0;
    for(int j = 1; j <= ct; j++)
        res = ad(res, DPsum[N][j]);

    cout << res << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 822 ms 12240 KB Output is correct
2 Correct 836 ms 12240 KB Output is correct
3 Correct 827 ms 12236 KB Output is correct
4 Correct 815 ms 12236 KB Output is correct
5 Correct 797 ms 12236 KB Output is correct
6 Correct 830 ms 12240 KB Output is correct
7 Correct 824 ms 12236 KB Output is correct
8 Correct 830 ms 12240 KB Output is correct
9 Correct 829 ms 12244 KB Output is correct
10 Correct 821 ms 12344 KB Output is correct
11 Correct 826 ms 12356 KB Output is correct
12 Correct 817 ms 12236 KB Output is correct
13 Correct 848 ms 12236 KB Output is correct
14 Correct 821 ms 12244 KB Output is correct
15 Correct 850 ms 12240 KB Output is correct
16 Correct 144 ms 2448 KB Output is correct
17 Correct 152 ms 2508 KB Output is correct
18 Correct 149 ms 2528 KB Output is correct
19 Correct 160 ms 2508 KB Output is correct
20 Correct 144 ms 2544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 822 ms 12240 KB Output is correct
2 Correct 836 ms 12240 KB Output is correct
3 Correct 827 ms 12236 KB Output is correct
4 Correct 815 ms 12236 KB Output is correct
5 Correct 797 ms 12236 KB Output is correct
6 Correct 830 ms 12240 KB Output is correct
7 Correct 824 ms 12236 KB Output is correct
8 Correct 830 ms 12240 KB Output is correct
9 Correct 829 ms 12244 KB Output is correct
10 Correct 821 ms 12344 KB Output is correct
11 Correct 826 ms 12356 KB Output is correct
12 Correct 817 ms 12236 KB Output is correct
13 Correct 848 ms 12236 KB Output is correct
14 Correct 821 ms 12244 KB Output is correct
15 Correct 850 ms 12240 KB Output is correct
16 Correct 144 ms 2448 KB Output is correct
17 Correct 152 ms 2508 KB Output is correct
18 Correct 149 ms 2528 KB Output is correct
19 Correct 160 ms 2508 KB Output is correct
20 Correct 144 ms 2544 KB Output is correct
21 Correct 1044 ms 11192 KB Output is correct
22 Correct 1053 ms 11316 KB Output is correct
23 Correct 1000 ms 11132 KB Output is correct
24 Correct 1008 ms 11048 KB Output is correct
25 Correct 1012 ms 11092 KB Output is correct
26 Correct 1112 ms 10956 KB Output is correct
27 Correct 1129 ms 10980 KB Output is correct
28 Correct 1121 ms 10792 KB Output is correct
29 Correct 1104 ms 10740 KB Output is correct
30 Correct 811 ms 12196 KB Output is correct
31 Correct 816 ms 12236 KB Output is correct
32 Correct 816 ms 12196 KB Output is correct
33 Correct 838 ms 12236 KB Output is correct
34 Correct 820 ms 12236 KB Output is correct
35 Correct 812 ms 12196 KB Output is correct
36 Correct 858 ms 12196 KB Output is correct
37 Correct 824 ms 12108 KB Output is correct
38 Correct 805 ms 12108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 716 KB Output is correct
2 Correct 12 ms 716 KB Output is correct
3 Correct 13 ms 784 KB Output is correct
4 Correct 13 ms 816 KB Output is correct
5 Correct 13 ms 820 KB Output is correct
6 Correct 14 ms 716 KB Output is correct
7 Correct 13 ms 780 KB Output is correct
8 Correct 13 ms 784 KB Output is correct
9 Correct 14 ms 844 KB Output is correct
10 Correct 14 ms 716 KB Output is correct
11 Correct 11 ms 716 KB Output is correct
12 Correct 10 ms 780 KB Output is correct
13 Correct 10 ms 780 KB Output is correct
14 Correct 11 ms 784 KB Output is correct
15 Correct 11 ms 844 KB Output is correct
16 Correct 6 ms 588 KB Output is correct
17 Correct 6 ms 596 KB Output is correct
18 Correct 8 ms 588 KB Output is correct
19 Correct 7 ms 588 KB Output is correct
20 Correct 7 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 822 ms 12240 KB Output is correct
2 Correct 836 ms 12240 KB Output is correct
3 Correct 827 ms 12236 KB Output is correct
4 Correct 815 ms 12236 KB Output is correct
5 Correct 797 ms 12236 KB Output is correct
6 Correct 830 ms 12240 KB Output is correct
7 Correct 824 ms 12236 KB Output is correct
8 Correct 830 ms 12240 KB Output is correct
9 Correct 829 ms 12244 KB Output is correct
10 Correct 821 ms 12344 KB Output is correct
11 Correct 826 ms 12356 KB Output is correct
12 Correct 817 ms 12236 KB Output is correct
13 Correct 848 ms 12236 KB Output is correct
14 Correct 821 ms 12244 KB Output is correct
15 Correct 850 ms 12240 KB Output is correct
16 Correct 144 ms 2448 KB Output is correct
17 Correct 152 ms 2508 KB Output is correct
18 Correct 149 ms 2528 KB Output is correct
19 Correct 160 ms 2508 KB Output is correct
20 Correct 144 ms 2544 KB Output is correct
21 Correct 1044 ms 11192 KB Output is correct
22 Correct 1053 ms 11316 KB Output is correct
23 Correct 1000 ms 11132 KB Output is correct
24 Correct 1008 ms 11048 KB Output is correct
25 Correct 1012 ms 11092 KB Output is correct
26 Correct 1112 ms 10956 KB Output is correct
27 Correct 1129 ms 10980 KB Output is correct
28 Correct 1121 ms 10792 KB Output is correct
29 Correct 1104 ms 10740 KB Output is correct
30 Correct 811 ms 12196 KB Output is correct
31 Correct 816 ms 12236 KB Output is correct
32 Correct 816 ms 12196 KB Output is correct
33 Correct 838 ms 12236 KB Output is correct
34 Correct 820 ms 12236 KB Output is correct
35 Correct 812 ms 12196 KB Output is correct
36 Correct 858 ms 12196 KB Output is correct
37 Correct 824 ms 12108 KB Output is correct
38 Correct 805 ms 12108 KB Output is correct
39 Correct 11 ms 716 KB Output is correct
40 Correct 12 ms 716 KB Output is correct
41 Correct 13 ms 784 KB Output is correct
42 Correct 13 ms 816 KB Output is correct
43 Correct 13 ms 820 KB Output is correct
44 Correct 14 ms 716 KB Output is correct
45 Correct 13 ms 780 KB Output is correct
46 Correct 13 ms 784 KB Output is correct
47 Correct 14 ms 844 KB Output is correct
48 Correct 14 ms 716 KB Output is correct
49 Correct 11 ms 716 KB Output is correct
50 Correct 10 ms 780 KB Output is correct
51 Correct 10 ms 780 KB Output is correct
52 Correct 11 ms 784 KB Output is correct
53 Correct 11 ms 844 KB Output is correct
54 Correct 6 ms 588 KB Output is correct
55 Correct 6 ms 596 KB Output is correct
56 Correct 8 ms 588 KB Output is correct
57 Correct 7 ms 588 KB Output is correct
58 Correct 7 ms 588 KB Output is correct
59 Correct 1376 ms 12236 KB Output is correct
60 Correct 1330 ms 12240 KB Output is correct
61 Correct 1343 ms 12240 KB Output is correct
62 Correct 1378 ms 12236 KB Output is correct
63 Correct 1395 ms 12240 KB Output is correct
64 Correct 1686 ms 12236 KB Output is correct
65 Correct 1612 ms 12240 KB Output is correct
66 Correct 1685 ms 12236 KB Output is correct
67 Correct 1619 ms 12240 KB Output is correct
68 Correct 1631 ms 12240 KB Output is correct
69 Correct 1337 ms 12236 KB Output is correct
70 Correct 1275 ms 12240 KB Output is correct
71 Correct 1351 ms 12240 KB Output is correct
72 Correct 1296 ms 12240 KB Output is correct
73 Correct 1330 ms 12240 KB Output is correct
74 Correct 173 ms 2508 KB Output is correct
75 Correct 194 ms 2564 KB Output is correct
76 Correct 174 ms 2508 KB Output is correct
77 Correct 178 ms 2508 KB Output is correct
78 Correct 191 ms 2508 KB Output is correct