Submission #1076388

# Submission time Handle Problem Language Result Execution time Memory
1076388 2024-08-26T13:30:40 Z alexdd Boat (APIO16_boat) C++17
100 / 100
1196 ms 8664 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1e9+7;
const int MAXV = 2000;
int put(int a, int exp)
{
    if(exp==0)
        return 1;
    if(exp%2==0)
        return put(a*a%MOD,exp/2);
    else
        return put(a*a%MOD,exp/2)*a%MOD;
}
int n,cate;
int le[505],ri[505];
map<int,int> mp,nrm;
int invnrm[MAXV+5],nr[MAXV+5];
int dp[MAXV+5][505];
int sumdp[MAXV+5];
int prec_inv[505];
signed main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>le[i]>>ri[i];
        mp[le[i]]++;
        mp[ri[i]]++;
        prec_inv[i] = put(i,MOD-2);
    }
    for(auto it:mp)
    {
        if(it.second)
        {
            nrm[it.first]=++cate;
            invnrm[cate]=it.first;
            cate++;
        }
    }
    for(int i=1;i<=cate;i+=2)
    {
        nr[i]=1;
        nr[i+1]=invnrm[i+2]-invnrm[i]-1;
    }
    dp[0][0]=1;
    sumdp[0]=1;
    for(int ult=1;ult<cate;ult++)
        sumdp[ult] = sumdp[ult-1];
    for(int i=1;i<=n;i++)
    {
        le[i] = nrm[le[i]];
        ri[i] = nrm[ri[i]];
        for(int ult=ri[i];ult>=le[i];ult--)
        {
            for(int cnt=min(i,nr[ult]);cnt>1;cnt--)
            {
                dp[ult][cnt]= (dp[ult][cnt] + dp[ult][cnt-1] * (nr[ult]-cnt+1)%MOD * prec_inv[cnt])%MOD;
            }
            dp[ult][1] = (dp[ult][1] + sumdp[ult-1]*nr[ult])%MOD;
        }
        sumdp[0]=1;
        for(int ult=1;ult<cate;ult++)
        {
            sumdp[ult] = sumdp[ult-1];
            for(int cnt=1;cnt<=i;cnt++)
                sumdp[ult] = (sumdp[ult] + dp[ult][cnt])%MOD;
        }
    }
    int rez=0;
    for(int ult=1;ult<=cate;ult++)
        for(int cnt=1;cnt<=n;cnt++)
            rez = (rez + dp[ult][cnt])%MOD;
    cout<<rez;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 497 ms 2340 KB Output is correct
2 Correct 493 ms 2388 KB Output is correct
3 Correct 494 ms 2516 KB Output is correct
4 Correct 494 ms 2384 KB Output is correct
5 Correct 494 ms 2384 KB Output is correct
6 Correct 495 ms 2384 KB Output is correct
7 Correct 499 ms 2348 KB Output is correct
8 Correct 497 ms 2380 KB Output is correct
9 Correct 499 ms 2528 KB Output is correct
10 Correct 497 ms 2436 KB Output is correct
11 Correct 499 ms 2412 KB Output is correct
12 Correct 497 ms 2336 KB Output is correct
13 Correct 495 ms 2388 KB Output is correct
14 Correct 502 ms 2388 KB Output is correct
15 Correct 497 ms 2640 KB Output is correct
16 Correct 88 ms 816 KB Output is correct
17 Correct 94 ms 824 KB Output is correct
18 Correct 90 ms 600 KB Output is correct
19 Correct 95 ms 836 KB Output is correct
20 Correct 92 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 497 ms 2340 KB Output is correct
2 Correct 493 ms 2388 KB Output is correct
3 Correct 494 ms 2516 KB Output is correct
4 Correct 494 ms 2384 KB Output is correct
5 Correct 494 ms 2384 KB Output is correct
6 Correct 495 ms 2384 KB Output is correct
7 Correct 499 ms 2348 KB Output is correct
8 Correct 497 ms 2380 KB Output is correct
9 Correct 499 ms 2528 KB Output is correct
10 Correct 497 ms 2436 KB Output is correct
11 Correct 499 ms 2412 KB Output is correct
12 Correct 497 ms 2336 KB Output is correct
13 Correct 495 ms 2388 KB Output is correct
14 Correct 502 ms 2388 KB Output is correct
15 Correct 497 ms 2640 KB Output is correct
16 Correct 88 ms 816 KB Output is correct
17 Correct 94 ms 824 KB Output is correct
18 Correct 90 ms 600 KB Output is correct
19 Correct 95 ms 836 KB Output is correct
20 Correct 92 ms 604 KB Output is correct
21 Correct 931 ms 8064 KB Output is correct
22 Correct 918 ms 7824 KB Output is correct
23 Correct 896 ms 7512 KB Output is correct
24 Correct 904 ms 7760 KB Output is correct
25 Correct 904 ms 7660 KB Output is correct
26 Correct 879 ms 7472 KB Output is correct
27 Correct 889 ms 7760 KB Output is correct
28 Correct 877 ms 7508 KB Output is correct
29 Correct 878 ms 7256 KB Output is correct
30 Correct 943 ms 8008 KB Output is correct
31 Correct 941 ms 8020 KB Output is correct
32 Correct 947 ms 8016 KB Output is correct
33 Correct 942 ms 8020 KB Output is correct
34 Correct 934 ms 8016 KB Output is correct
35 Correct 495 ms 4308 KB Output is correct
36 Correct 499 ms 4260 KB Output is correct
37 Correct 500 ms 4440 KB Output is correct
38 Correct 500 ms 4268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 1884 KB Output is correct
2 Correct 10 ms 2040 KB Output is correct
3 Correct 12 ms 2136 KB Output is correct
4 Correct 10 ms 2072 KB Output is correct
5 Correct 10 ms 2072 KB Output is correct
6 Correct 11 ms 2068 KB Output is correct
7 Correct 12 ms 1884 KB Output is correct
8 Correct 11 ms 1880 KB Output is correct
9 Correct 11 ms 1880 KB Output is correct
10 Correct 11 ms 1884 KB Output is correct
11 Correct 10 ms 1884 KB Output is correct
12 Correct 10 ms 2068 KB Output is correct
13 Correct 10 ms 2076 KB Output is correct
14 Correct 10 ms 1884 KB Output is correct
15 Correct 10 ms 1884 KB Output is correct
16 Correct 5 ms 1368 KB Output is correct
17 Correct 5 ms 1116 KB Output is correct
18 Correct 5 ms 1116 KB Output is correct
19 Correct 5 ms 1116 KB Output is correct
20 Correct 5 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 497 ms 2340 KB Output is correct
2 Correct 493 ms 2388 KB Output is correct
3 Correct 494 ms 2516 KB Output is correct
4 Correct 494 ms 2384 KB Output is correct
5 Correct 494 ms 2384 KB Output is correct
6 Correct 495 ms 2384 KB Output is correct
7 Correct 499 ms 2348 KB Output is correct
8 Correct 497 ms 2380 KB Output is correct
9 Correct 499 ms 2528 KB Output is correct
10 Correct 497 ms 2436 KB Output is correct
11 Correct 499 ms 2412 KB Output is correct
12 Correct 497 ms 2336 KB Output is correct
13 Correct 495 ms 2388 KB Output is correct
14 Correct 502 ms 2388 KB Output is correct
15 Correct 497 ms 2640 KB Output is correct
16 Correct 88 ms 816 KB Output is correct
17 Correct 94 ms 824 KB Output is correct
18 Correct 90 ms 600 KB Output is correct
19 Correct 95 ms 836 KB Output is correct
20 Correct 92 ms 604 KB Output is correct
21 Correct 931 ms 8064 KB Output is correct
22 Correct 918 ms 7824 KB Output is correct
23 Correct 896 ms 7512 KB Output is correct
24 Correct 904 ms 7760 KB Output is correct
25 Correct 904 ms 7660 KB Output is correct
26 Correct 879 ms 7472 KB Output is correct
27 Correct 889 ms 7760 KB Output is correct
28 Correct 877 ms 7508 KB Output is correct
29 Correct 878 ms 7256 KB Output is correct
30 Correct 943 ms 8008 KB Output is correct
31 Correct 941 ms 8020 KB Output is correct
32 Correct 947 ms 8016 KB Output is correct
33 Correct 942 ms 8020 KB Output is correct
34 Correct 934 ms 8016 KB Output is correct
35 Correct 495 ms 4308 KB Output is correct
36 Correct 499 ms 4260 KB Output is correct
37 Correct 500 ms 4440 KB Output is correct
38 Correct 500 ms 4268 KB Output is correct
39 Correct 10 ms 1884 KB Output is correct
40 Correct 10 ms 2040 KB Output is correct
41 Correct 12 ms 2136 KB Output is correct
42 Correct 10 ms 2072 KB Output is correct
43 Correct 10 ms 2072 KB Output is correct
44 Correct 11 ms 2068 KB Output is correct
45 Correct 12 ms 1884 KB Output is correct
46 Correct 11 ms 1880 KB Output is correct
47 Correct 11 ms 1880 KB Output is correct
48 Correct 11 ms 1884 KB Output is correct
49 Correct 10 ms 1884 KB Output is correct
50 Correct 10 ms 2068 KB Output is correct
51 Correct 10 ms 2076 KB Output is correct
52 Correct 10 ms 1884 KB Output is correct
53 Correct 10 ms 1884 KB Output is correct
54 Correct 5 ms 1368 KB Output is correct
55 Correct 5 ms 1116 KB Output is correct
56 Correct 5 ms 1116 KB Output is correct
57 Correct 5 ms 1116 KB Output is correct
58 Correct 5 ms 1116 KB Output is correct
59 Correct 1125 ms 8468 KB Output is correct
60 Correct 1118 ms 8472 KB Output is correct
61 Correct 1127 ms 8280 KB Output is correct
62 Correct 1129 ms 8280 KB Output is correct
63 Correct 1124 ms 8472 KB Output is correct
64 Correct 1186 ms 8536 KB Output is correct
65 Correct 1196 ms 8304 KB Output is correct
66 Correct 1195 ms 8280 KB Output is correct
67 Correct 1183 ms 8664 KB Output is correct
68 Correct 1190 ms 8272 KB Output is correct
69 Correct 1100 ms 8280 KB Output is correct
70 Correct 1097 ms 8492 KB Output is correct
71 Correct 1090 ms 8440 KB Output is correct
72 Correct 1106 ms 8536 KB Output is correct
73 Correct 1102 ms 8492 KB Output is correct
74 Correct 115 ms 1112 KB Output is correct
75 Correct 112 ms 1112 KB Output is correct
76 Correct 116 ms 1116 KB Output is correct
77 Correct 113 ms 1116 KB Output is correct
78 Correct 115 ms 1260 KB Output is correct