Submission #242168

# Submission time Handle Problem Language Result Execution time Memory
242168 2020-06-27T04:03:11 Z WhaleVomit Boat (APIO16_boat) C++14
100 / 100
1343 ms 16632 KB
#include <bits/stdc++.h>
using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()

#define MOO(i, a, b) for(int i=a; i<b; i++)
#define M00(i, a) for(int i=0; i<a; i++)
#define MOOd(i,a,b) for(int i = (b)-1; i >= a; i--)
#define M00d(i,a) for(int i = (a)-1; i>=0; i--)

#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << '\n', 0;
#define dbg(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _ << " _ " <<

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ld,ld> pd;
typedef complex<ld> cd;

const ll MOD = 1000000007;
const int MAX_N = 505;
int n;
pi arr[MAX_N];
ll fact[MAX_N];
ll factor[MAX_N*4][MAX_N];
vector<ll> dp[4*MAX_N];

bool cont(pi p1, pi p2) {
    return p2.f <= p1.f && p1.s <= p2.s;
}

int len(pi p) {
    return p.s - p.f + 1;
}

ll mpow(ll base, ll exp) {
    if(exp == 0) return 1;
    ll res = mpow(base, exp/2);
    res *= res; res %= MOD;
    if(exp%2 == 1) {
        res *= base; res %= MOD;
    }
    return res;
}

ll inv(ll k) {
    return mpow(k, MOD-2);
}

ll getSum(int j, vector<ll>& v) {
    ll res = 0;
    int ctr = 0;
    M00d(idx, sz(v)) {
        if(v[idx] == 0) continue;
        ll val = (v[idx] * factor[j][ctr]) % MOD;
        res += val;
        res %= MOD;
        ctr++;
    }
    return res;
}

int main() { FAST
    fact[0] = 1;
    MOO(i, 1, MAX_N) fact[i] = (fact[i-1] * i) % MOD;
    cin >> n;
    M00(i, n) cin >> arr[i].f >> arr[i].s;
    vi idxs;
    idxs.pb(0);
    M00(i, n) {
        idxs.pb(arr[i].f);
        idxs.pb(arr[i].s);
    }
    sort(all(idxs));
    idxs.erase(unique(all(idxs)), idxs.end());
    vector<pi> intervals;
    intervals.pb(mp(0,0));
    MOO(i, 1, sz(idxs)) {
        pi p = mp(idxs[i-1]+1, idxs[i]-1);
        if(p.f <= p.s) intervals.pb(p);
        intervals.pb(mp(idxs[i], idxs[i]));
    }
    sort(all(intervals));
    M00(i, sz(intervals)) {
        ll x = len(intervals[i]);
        ll cur = 1;
        M00(j, MAX_N-1) {
            cur *= x+j; cur %= MOD;
            factor[i][j] = (cur * inv(fact[j+1])) % MOD;
        }
    }

    dp[0].pb(1);
    MOO(i, 1, sz(intervals)) {
        if(cont(intervals[i], arr[0])) dp[i].pb(1);
        else dp[i].pb(0);
    }
    MOO(i, 1, n) {
        ll cursum = 0;
        M00(j, sz(intervals)) {
            ll add = getSum(j, dp[j]);
            if(cont(intervals[j], arr[i])) {
                dp[j].pb(cursum);
            } else {
                dp[j].pb(0);
            }
            cursum += add;
            cursum %= MOD;
        }
    }
    ll ans = MOD-1;
    M00(i, sz(intervals)) {
        ans += getSum(i, dp[i]);
        ans %= MOD;
    }
    finish(ans);
}

# Verdict Execution time Memory Grader output
1 Correct 314 ms 8440 KB Output is correct
2 Correct 342 ms 8520 KB Output is correct
3 Correct 322 ms 8440 KB Output is correct
4 Correct 323 ms 8568 KB Output is correct
5 Correct 341 ms 8440 KB Output is correct
6 Correct 317 ms 8440 KB Output is correct
7 Correct 319 ms 8312 KB Output is correct
8 Correct 328 ms 8376 KB Output is correct
9 Correct 313 ms 8464 KB Output is correct
10 Correct 316 ms 8540 KB Output is correct
11 Correct 316 ms 8440 KB Output is correct
12 Correct 322 ms 8568 KB Output is correct
13 Correct 319 ms 8568 KB Output is correct
14 Correct 330 ms 8440 KB Output is correct
15 Correct 321 ms 8360 KB Output is correct
16 Correct 61 ms 1784 KB Output is correct
17 Correct 65 ms 1912 KB Output is correct
18 Correct 63 ms 1912 KB Output is correct
19 Correct 64 ms 2004 KB Output is correct
20 Correct 62 ms 2040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 314 ms 8440 KB Output is correct
2 Correct 342 ms 8520 KB Output is correct
3 Correct 322 ms 8440 KB Output is correct
4 Correct 323 ms 8568 KB Output is correct
5 Correct 341 ms 8440 KB Output is correct
6 Correct 317 ms 8440 KB Output is correct
7 Correct 319 ms 8312 KB Output is correct
8 Correct 328 ms 8376 KB Output is correct
9 Correct 313 ms 8464 KB Output is correct
10 Correct 316 ms 8540 KB Output is correct
11 Correct 316 ms 8440 KB Output is correct
12 Correct 322 ms 8568 KB Output is correct
13 Correct 319 ms 8568 KB Output is correct
14 Correct 330 ms 8440 KB Output is correct
15 Correct 321 ms 8360 KB Output is correct
16 Correct 61 ms 1784 KB Output is correct
17 Correct 65 ms 1912 KB Output is correct
18 Correct 63 ms 1912 KB Output is correct
19 Correct 64 ms 2004 KB Output is correct
20 Correct 62 ms 2040 KB Output is correct
21 Correct 927 ms 13816 KB Output is correct
22 Correct 1006 ms 13816 KB Output is correct
23 Correct 865 ms 13716 KB Output is correct
24 Correct 909 ms 13792 KB Output is correct
25 Correct 1006 ms 13688 KB Output is correct
26 Correct 989 ms 12920 KB Output is correct
27 Correct 1046 ms 13176 KB Output is correct
28 Correct 988 ms 13176 KB Output is correct
29 Correct 1000 ms 13176 KB Output is correct
30 Correct 648 ms 15344 KB Output is correct
31 Correct 678 ms 15352 KB Output is correct
32 Correct 650 ms 15224 KB Output is correct
33 Correct 650 ms 15352 KB Output is correct
34 Correct 642 ms 15224 KB Output is correct
35 Correct 365 ms 8568 KB Output is correct
36 Correct 327 ms 8440 KB Output is correct
37 Correct 351 ms 8552 KB Output is correct
38 Correct 324 ms 8568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 2424 KB Output is correct
2 Correct 65 ms 2424 KB Output is correct
3 Correct 65 ms 2552 KB Output is correct
4 Correct 66 ms 2424 KB Output is correct
5 Correct 66 ms 2556 KB Output is correct
6 Correct 66 ms 2424 KB Output is correct
7 Correct 66 ms 2424 KB Output is correct
8 Correct 67 ms 2424 KB Output is correct
9 Correct 67 ms 2424 KB Output is correct
10 Correct 66 ms 2424 KB Output is correct
11 Correct 66 ms 2552 KB Output is correct
12 Correct 65 ms 2348 KB Output is correct
13 Correct 66 ms 2424 KB Output is correct
14 Correct 66 ms 2424 KB Output is correct
15 Correct 66 ms 2552 KB Output is correct
16 Correct 31 ms 1280 KB Output is correct
17 Correct 31 ms 1280 KB Output is correct
18 Correct 31 ms 1276 KB Output is correct
19 Correct 32 ms 1280 KB Output is correct
20 Correct 32 ms 1272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 314 ms 8440 KB Output is correct
2 Correct 342 ms 8520 KB Output is correct
3 Correct 322 ms 8440 KB Output is correct
4 Correct 323 ms 8568 KB Output is correct
5 Correct 341 ms 8440 KB Output is correct
6 Correct 317 ms 8440 KB Output is correct
7 Correct 319 ms 8312 KB Output is correct
8 Correct 328 ms 8376 KB Output is correct
9 Correct 313 ms 8464 KB Output is correct
10 Correct 316 ms 8540 KB Output is correct
11 Correct 316 ms 8440 KB Output is correct
12 Correct 322 ms 8568 KB Output is correct
13 Correct 319 ms 8568 KB Output is correct
14 Correct 330 ms 8440 KB Output is correct
15 Correct 321 ms 8360 KB Output is correct
16 Correct 61 ms 1784 KB Output is correct
17 Correct 65 ms 1912 KB Output is correct
18 Correct 63 ms 1912 KB Output is correct
19 Correct 64 ms 2004 KB Output is correct
20 Correct 62 ms 2040 KB Output is correct
21 Correct 927 ms 13816 KB Output is correct
22 Correct 1006 ms 13816 KB Output is correct
23 Correct 865 ms 13716 KB Output is correct
24 Correct 909 ms 13792 KB Output is correct
25 Correct 1006 ms 13688 KB Output is correct
26 Correct 989 ms 12920 KB Output is correct
27 Correct 1046 ms 13176 KB Output is correct
28 Correct 988 ms 13176 KB Output is correct
29 Correct 1000 ms 13176 KB Output is correct
30 Correct 648 ms 15344 KB Output is correct
31 Correct 678 ms 15352 KB Output is correct
32 Correct 650 ms 15224 KB Output is correct
33 Correct 650 ms 15352 KB Output is correct
34 Correct 642 ms 15224 KB Output is correct
35 Correct 365 ms 8568 KB Output is correct
36 Correct 327 ms 8440 KB Output is correct
37 Correct 351 ms 8552 KB Output is correct
38 Correct 324 ms 8568 KB Output is correct
39 Correct 66 ms 2424 KB Output is correct
40 Correct 65 ms 2424 KB Output is correct
41 Correct 65 ms 2552 KB Output is correct
42 Correct 66 ms 2424 KB Output is correct
43 Correct 66 ms 2556 KB Output is correct
44 Correct 66 ms 2424 KB Output is correct
45 Correct 66 ms 2424 KB Output is correct
46 Correct 67 ms 2424 KB Output is correct
47 Correct 67 ms 2424 KB Output is correct
48 Correct 66 ms 2424 KB Output is correct
49 Correct 66 ms 2552 KB Output is correct
50 Correct 65 ms 2348 KB Output is correct
51 Correct 66 ms 2424 KB Output is correct
52 Correct 66 ms 2424 KB Output is correct
53 Correct 66 ms 2552 KB Output is correct
54 Correct 31 ms 1280 KB Output is correct
55 Correct 31 ms 1280 KB Output is correct
56 Correct 31 ms 1276 KB Output is correct
57 Correct 32 ms 1280 KB Output is correct
58 Correct 32 ms 1272 KB Output is correct
59 Correct 1091 ms 16524 KB Output is correct
60 Correct 1062 ms 16480 KB Output is correct
61 Correct 1068 ms 16500 KB Output is correct
62 Correct 1092 ms 16548 KB Output is correct
63 Correct 1056 ms 16564 KB Output is correct
64 Correct 1244 ms 16376 KB Output is correct
65 Correct 1280 ms 16632 KB Output is correct
66 Correct 1278 ms 16512 KB Output is correct
67 Correct 1343 ms 16504 KB Output is correct
68 Correct 1261 ms 16632 KB Output is correct
69 Correct 1111 ms 16376 KB Output is correct
70 Correct 1118 ms 16548 KB Output is correct
71 Correct 1173 ms 16632 KB Output is correct
72 Correct 1115 ms 16444 KB Output is correct
73 Correct 1227 ms 16444 KB Output is correct
74 Correct 115 ms 2168 KB Output is correct
75 Correct 117 ms 2296 KB Output is correct
76 Correct 116 ms 1984 KB Output is correct
77 Correct 119 ms 2040 KB Output is correct
78 Correct 116 ms 2040 KB Output is correct