Submission #116761

# Submission time Handle Problem Language Result Execution time Memory
116761 2019-06-13T17:53:42 Z roseanne_pcy Boat (APIO16_boat) C++14
100 / 100
1268 ms 8508 KB
//Power Of Ninja Go
#include <bits/stdc++.h>
//#ifdef atom #else #endif
using namespace std;
typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector< ii > vii;
#define X first
#define Y second
#define pb push_back
const int maxn = 505;
const int md = 1e9+7;
void add(int &a, int b)
{
    a += b;
    if(a>= md) a-= md;
}
int mul(int a, int b)
{
    return (1LL*a*b)%md;
}
int expo(int a, int b)
{
    if(b == 0) return 1;
    int x = expo(a, b/2);
    int y = mul(x, x);
    if(b%2) y = mul(y, a);
    return y;
}
int inv(int x)
{
    return expo(x, md-2);
}
int a[maxn];
int b[maxn];
int qu[maxn][2*maxn];
int f[maxn][2*maxn];
int sum[maxn][2*maxn];
int mem[maxn][2*maxn];
int invfac[maxn];
int n;
vi vec;
int g(int L, int R, int intv)
{
    //cout << L << ' ' << R << ' ' << intv << endl;
    int k = qu[R][intv]-qu[L-1][intv]-1;
    int sz = vec[intv+1]-vec[intv];
    if(mem[k][intv] != -1) return mem[k][intv];
    int res = 1;
    for(int i = sz; i<= sz+k; i++) res = mul(res, i);
    res = mul(res, invfac[k+1]);
    return mem[k][intv] = res;
}
int main()
{
    memset(mem, -1, sizeof mem);
    cin >> n;
    invfac[0] = 1;
    for(int i = 1; i<= n; i++) invfac[i] = mul(invfac[i-1], inv(i));
    for(int i = 1; i<= n; i++)
    {
        cin >> a[i] >> b[i];
        b[i]++;
        vec.pb(a[i]); vec.pb(b[i]);
    }
    sort(vec.begin(), vec.end()); vec.resize(unique(vec.begin(), vec.end())-vec.begin());
    for(int i = 1; i<= n; i++)
    {
        a[i] = lower_bound(vec.begin(), vec.end(), a[i])-vec.begin();
        b[i] = lower_bound(vec.begin(), vec.end(), b[i])-vec.begin();
    }
    for(int i = 1; i<= n; i++)
    {
        for(int j = 0; j< (int) vec.size()-1; j++)
        {
            qu[i][j] = qu[i-1][j] + (a[i]<= j && j< b[i]);
        }
    }
    for(int j = 0; j< (int) vec.size()-1; j++) sum[0][j] = 1;
    for(int i = 1; i<= n; i++)
    {
        for(int j = 0; j< (int) vec.size()-1; j++)
        {
            if(a[i]<= j && j <b[i])
            {
                for(int a = 0; a< i ; a++)
                {
                    int sm;
                    if(j == 0 && a == 0) sm = 1;
                    else if(j == 0) sm = 0;
                    else sm = sum[a][j-1];
                    //cout << sm << endl;
                    add(f[i][j], mul(sm, g(a+1, i, j)));
                }
            }
            //printf("f[%d][%d] = %d\n", i, j, f[i][j]);
            sum[i][j] = j?sum[i][j-1]:0;
            add(sum[i][j], f[i][j]);
        }
    }
    int res = 0;
    for(int i = 1; i<= n; i++)
    {
        for(int j = 0; j< (int) vec.size()-1; j++)
        {
            add(res, f[i][j]);
        }
    }
    cout << res << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8064 KB Output is correct
2 Correct 13 ms 7936 KB Output is correct
3 Correct 14 ms 7904 KB Output is correct
4 Correct 13 ms 7936 KB Output is correct
5 Correct 13 ms 7936 KB Output is correct
6 Correct 13 ms 8320 KB Output is correct
7 Correct 13 ms 8320 KB Output is correct
8 Correct 13 ms 8320 KB Output is correct
9 Correct 13 ms 8320 KB Output is correct
10 Correct 14 ms 8320 KB Output is correct
11 Correct 13 ms 8320 KB Output is correct
12 Correct 14 ms 8192 KB Output is correct
13 Correct 14 ms 8192 KB Output is correct
14 Correct 13 ms 8320 KB Output is correct
15 Correct 13 ms 8320 KB Output is correct
16 Correct 11 ms 8320 KB Output is correct
17 Correct 13 ms 8192 KB Output is correct
18 Correct 12 ms 8320 KB Output is correct
19 Correct 12 ms 8320 KB Output is correct
20 Correct 11 ms 8264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8064 KB Output is correct
2 Correct 13 ms 7936 KB Output is correct
3 Correct 14 ms 7904 KB Output is correct
4 Correct 13 ms 7936 KB Output is correct
5 Correct 13 ms 7936 KB Output is correct
6 Correct 13 ms 8320 KB Output is correct
7 Correct 13 ms 8320 KB Output is correct
8 Correct 13 ms 8320 KB Output is correct
9 Correct 13 ms 8320 KB Output is correct
10 Correct 14 ms 8320 KB Output is correct
11 Correct 13 ms 8320 KB Output is correct
12 Correct 14 ms 8192 KB Output is correct
13 Correct 14 ms 8192 KB Output is correct
14 Correct 13 ms 8320 KB Output is correct
15 Correct 13 ms 8320 KB Output is correct
16 Correct 11 ms 8320 KB Output is correct
17 Correct 13 ms 8192 KB Output is correct
18 Correct 12 ms 8320 KB Output is correct
19 Correct 12 ms 8320 KB Output is correct
20 Correct 11 ms 8264 KB Output is correct
21 Correct 679 ms 8268 KB Output is correct
22 Correct 632 ms 8276 KB Output is correct
23 Correct 669 ms 8256 KB Output is correct
24 Correct 643 ms 8312 KB Output is correct
25 Correct 612 ms 8236 KB Output is correct
26 Correct 896 ms 8340 KB Output is correct
27 Correct 1073 ms 8480 KB Output is correct
28 Correct 851 ms 8324 KB Output is correct
29 Correct 909 ms 8384 KB Output is correct
30 Correct 17 ms 8320 KB Output is correct
31 Correct 16 ms 8320 KB Output is correct
32 Correct 17 ms 8320 KB Output is correct
33 Correct 18 ms 8320 KB Output is correct
34 Correct 16 ms 8320 KB Output is correct
35 Correct 17 ms 7936 KB Output is correct
36 Correct 18 ms 8064 KB Output is correct
37 Correct 17 ms 7936 KB Output is correct
38 Correct 17 ms 8052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 3584 KB Output is correct
2 Correct 7 ms 3580 KB Output is correct
3 Correct 8 ms 3456 KB Output is correct
4 Correct 8 ms 3456 KB Output is correct
5 Correct 9 ms 3584 KB Output is correct
6 Correct 11 ms 3520 KB Output is correct
7 Correct 11 ms 3584 KB Output is correct
8 Correct 12 ms 3584 KB Output is correct
9 Correct 11 ms 3456 KB Output is correct
10 Correct 11 ms 3584 KB Output is correct
11 Correct 9 ms 3584 KB Output is correct
12 Correct 8 ms 3560 KB Output is correct
13 Correct 8 ms 3584 KB Output is correct
14 Correct 8 ms 3584 KB Output is correct
15 Correct 8 ms 3584 KB Output is correct
16 Correct 8 ms 3712 KB Output is correct
17 Correct 7 ms 3584 KB Output is correct
18 Correct 7 ms 3456 KB Output is correct
19 Correct 7 ms 3584 KB Output is correct
20 Correct 8 ms 3584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8064 KB Output is correct
2 Correct 13 ms 7936 KB Output is correct
3 Correct 14 ms 7904 KB Output is correct
4 Correct 13 ms 7936 KB Output is correct
5 Correct 13 ms 7936 KB Output is correct
6 Correct 13 ms 8320 KB Output is correct
7 Correct 13 ms 8320 KB Output is correct
8 Correct 13 ms 8320 KB Output is correct
9 Correct 13 ms 8320 KB Output is correct
10 Correct 14 ms 8320 KB Output is correct
11 Correct 13 ms 8320 KB Output is correct
12 Correct 14 ms 8192 KB Output is correct
13 Correct 14 ms 8192 KB Output is correct
14 Correct 13 ms 8320 KB Output is correct
15 Correct 13 ms 8320 KB Output is correct
16 Correct 11 ms 8320 KB Output is correct
17 Correct 13 ms 8192 KB Output is correct
18 Correct 12 ms 8320 KB Output is correct
19 Correct 12 ms 8320 KB Output is correct
20 Correct 11 ms 8264 KB Output is correct
21 Correct 679 ms 8268 KB Output is correct
22 Correct 632 ms 8276 KB Output is correct
23 Correct 669 ms 8256 KB Output is correct
24 Correct 643 ms 8312 KB Output is correct
25 Correct 612 ms 8236 KB Output is correct
26 Correct 896 ms 8340 KB Output is correct
27 Correct 1073 ms 8480 KB Output is correct
28 Correct 851 ms 8324 KB Output is correct
29 Correct 909 ms 8384 KB Output is correct
30 Correct 17 ms 8320 KB Output is correct
31 Correct 16 ms 8320 KB Output is correct
32 Correct 17 ms 8320 KB Output is correct
33 Correct 18 ms 8320 KB Output is correct
34 Correct 16 ms 8320 KB Output is correct
35 Correct 17 ms 7936 KB Output is correct
36 Correct 18 ms 8064 KB Output is correct
37 Correct 17 ms 7936 KB Output is correct
38 Correct 17 ms 8052 KB Output is correct
39 Correct 8 ms 3584 KB Output is correct
40 Correct 7 ms 3580 KB Output is correct
41 Correct 8 ms 3456 KB Output is correct
42 Correct 8 ms 3456 KB Output is correct
43 Correct 9 ms 3584 KB Output is correct
44 Correct 11 ms 3520 KB Output is correct
45 Correct 11 ms 3584 KB Output is correct
46 Correct 12 ms 3584 KB Output is correct
47 Correct 11 ms 3456 KB Output is correct
48 Correct 11 ms 3584 KB Output is correct
49 Correct 9 ms 3584 KB Output is correct
50 Correct 8 ms 3560 KB Output is correct
51 Correct 8 ms 3584 KB Output is correct
52 Correct 8 ms 3584 KB Output is correct
53 Correct 8 ms 3584 KB Output is correct
54 Correct 8 ms 3712 KB Output is correct
55 Correct 7 ms 3584 KB Output is correct
56 Correct 7 ms 3456 KB Output is correct
57 Correct 7 ms 3584 KB Output is correct
58 Correct 8 ms 3584 KB Output is correct
59 Correct 788 ms 8384 KB Output is correct
60 Correct 697 ms 8204 KB Output is correct
61 Correct 768 ms 8456 KB Output is correct
62 Correct 762 ms 8300 KB Output is correct
63 Correct 821 ms 8204 KB Output is correct
64 Correct 1268 ms 8352 KB Output is correct
65 Correct 1053 ms 8508 KB Output is correct
66 Correct 1116 ms 8324 KB Output is correct
67 Correct 1085 ms 8388 KB Output is correct
68 Correct 1134 ms 8312 KB Output is correct
69 Correct 452 ms 8348 KB Output is correct
70 Correct 460 ms 8284 KB Output is correct
71 Correct 443 ms 8384 KB Output is correct
72 Correct 501 ms 8316 KB Output is correct
73 Correct 576 ms 8368 KB Output is correct
74 Correct 111 ms 8312 KB Output is correct
75 Correct 105 ms 8184 KB Output is correct
76 Correct 112 ms 8184 KB Output is correct
77 Correct 112 ms 8308 KB Output is correct
78 Correct 113 ms 8284 KB Output is correct