Submission #57079

# Submission time Handle Problem Language Result Execution time Memory
57079 2018-07-13T20:09:38 Z Benq Boat (APIO16_boat) C++14
100 / 100
1316 ms 3820 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

ll po (ll b, ll p) { return !p?1:po(b*b%MOD,p/2)*(p&1?b:1)%MOD; }
ll inv (ll b) { return po(b,MOD-2); }

ll ad(ll a, ll b) { return (a+b)%MOD; }
ll sub(ll a, ll b) { return (a-b+MOD)%MOD; }
ll mul(ll a, ll b) { return a*b%MOD; }
ll divi(ll a, ll b) { return mul(a,inv(b)); }

int N, dp[1000][501], in[1001];
vi rm;
map<int,int> m;
vpi v;

void input() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N;
    F0R(i,N) {
        int a,b; cin >> a >> b;
        v.pb({a,b});
        m[a-1] = m[b] = 0;
    }
    FOR(i,1,1001) in[i] = inv(i);
    int co = 0;
    for (auto& a: m) {
        rm.pb(a.f);
        a.s = co++;
    }
}

int main() {
    input();
    F0R(i,sz(v)) {
        auto a = v[i];
        int l = m[a.f-1]+1, r = m[a.s];
        
        int csum = 1;
        FOR(j,1,r+1) {
            int tmp = 0; F0R(k,i) tmp = ad(tmp,dp[j][k]);
            if (l <= j) {
                int w = rm[j]-rm[j-1];
                FORd(k,1,i+1) dp[j][k] = ad(dp[j][k],mul(dp[j][k-1],mul(w-k,in[k+1])));
                dp[j][0] = ad(dp[j][0],mul(w,csum));
            }
            csum = ad(csum,tmp);
        }
    }
    int ans = 0;
    FOR(i,1,sz(m)) F0R(j,sz(v)) ans = ad(ans,dp[i][j]);
    cout << ans;
}

/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( ) 
* special cases (n=1?)
* overflow (ll vs int?)
* array bounds
*/
# Verdict Execution time Memory Grader output
1 Correct 393 ms 2552 KB Output is correct
2 Correct 396 ms 2592 KB Output is correct
3 Correct 407 ms 2608 KB Output is correct
4 Correct 393 ms 2912 KB Output is correct
5 Correct 394 ms 2940 KB Output is correct
6 Correct 502 ms 2940 KB Output is correct
7 Correct 505 ms 3204 KB Output is correct
8 Correct 551 ms 3204 KB Output is correct
9 Correct 515 ms 3204 KB Output is correct
10 Correct 527 ms 3204 KB Output is correct
11 Correct 507 ms 3204 KB Output is correct
12 Correct 505 ms 3204 KB Output is correct
13 Correct 510 ms 3204 KB Output is correct
14 Correct 502 ms 3204 KB Output is correct
15 Correct 504 ms 3204 KB Output is correct
16 Correct 54 ms 3204 KB Output is correct
17 Correct 57 ms 3204 KB Output is correct
18 Correct 58 ms 3204 KB Output is correct
19 Correct 55 ms 3204 KB Output is correct
20 Correct 59 ms 3204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 393 ms 2552 KB Output is correct
2 Correct 396 ms 2592 KB Output is correct
3 Correct 407 ms 2608 KB Output is correct
4 Correct 393 ms 2912 KB Output is correct
5 Correct 394 ms 2940 KB Output is correct
6 Correct 502 ms 2940 KB Output is correct
7 Correct 505 ms 3204 KB Output is correct
8 Correct 551 ms 3204 KB Output is correct
9 Correct 515 ms 3204 KB Output is correct
10 Correct 527 ms 3204 KB Output is correct
11 Correct 507 ms 3204 KB Output is correct
12 Correct 505 ms 3204 KB Output is correct
13 Correct 510 ms 3204 KB Output is correct
14 Correct 502 ms 3204 KB Output is correct
15 Correct 504 ms 3204 KB Output is correct
16 Correct 54 ms 3204 KB Output is correct
17 Correct 57 ms 3204 KB Output is correct
18 Correct 58 ms 3204 KB Output is correct
19 Correct 55 ms 3204 KB Output is correct
20 Correct 59 ms 3204 KB Output is correct
21 Correct 782 ms 3204 KB Output is correct
22 Correct 769 ms 3204 KB Output is correct
23 Correct 733 ms 3208 KB Output is correct
24 Correct 765 ms 3208 KB Output is correct
25 Correct 731 ms 3216 KB Output is correct
26 Correct 962 ms 3216 KB Output is correct
27 Correct 988 ms 3216 KB Output is correct
28 Correct 941 ms 3216 KB Output is correct
29 Correct 1027 ms 3216 KB Output is correct
30 Correct 492 ms 3216 KB Output is correct
31 Correct 501 ms 3304 KB Output is correct
32 Correct 512 ms 3540 KB Output is correct
33 Correct 510 ms 3540 KB Output is correct
34 Correct 507 ms 3540 KB Output is correct
35 Correct 390 ms 3540 KB Output is correct
36 Correct 380 ms 3540 KB Output is correct
37 Correct 383 ms 3540 KB Output is correct
38 Correct 388 ms 3540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 3540 KB Output is correct
2 Correct 13 ms 3540 KB Output is correct
3 Correct 11 ms 3540 KB Output is correct
4 Correct 11 ms 3540 KB Output is correct
5 Correct 12 ms 3540 KB Output is correct
6 Correct 12 ms 3540 KB Output is correct
7 Correct 13 ms 3540 KB Output is correct
8 Correct 12 ms 3540 KB Output is correct
9 Correct 13 ms 3540 KB Output is correct
10 Correct 12 ms 3540 KB Output is correct
11 Correct 10 ms 3540 KB Output is correct
12 Correct 10 ms 3540 KB Output is correct
13 Correct 10 ms 3540 KB Output is correct
14 Correct 9 ms 3540 KB Output is correct
15 Correct 10 ms 3540 KB Output is correct
16 Correct 7 ms 3540 KB Output is correct
17 Correct 6 ms 3540 KB Output is correct
18 Correct 7 ms 3540 KB Output is correct
19 Correct 7 ms 3540 KB Output is correct
20 Correct 6 ms 3540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 393 ms 2552 KB Output is correct
2 Correct 396 ms 2592 KB Output is correct
3 Correct 407 ms 2608 KB Output is correct
4 Correct 393 ms 2912 KB Output is correct
5 Correct 394 ms 2940 KB Output is correct
6 Correct 502 ms 2940 KB Output is correct
7 Correct 505 ms 3204 KB Output is correct
8 Correct 551 ms 3204 KB Output is correct
9 Correct 515 ms 3204 KB Output is correct
10 Correct 527 ms 3204 KB Output is correct
11 Correct 507 ms 3204 KB Output is correct
12 Correct 505 ms 3204 KB Output is correct
13 Correct 510 ms 3204 KB Output is correct
14 Correct 502 ms 3204 KB Output is correct
15 Correct 504 ms 3204 KB Output is correct
16 Correct 54 ms 3204 KB Output is correct
17 Correct 57 ms 3204 KB Output is correct
18 Correct 58 ms 3204 KB Output is correct
19 Correct 55 ms 3204 KB Output is correct
20 Correct 59 ms 3204 KB Output is correct
21 Correct 782 ms 3204 KB Output is correct
22 Correct 769 ms 3204 KB Output is correct
23 Correct 733 ms 3208 KB Output is correct
24 Correct 765 ms 3208 KB Output is correct
25 Correct 731 ms 3216 KB Output is correct
26 Correct 962 ms 3216 KB Output is correct
27 Correct 988 ms 3216 KB Output is correct
28 Correct 941 ms 3216 KB Output is correct
29 Correct 1027 ms 3216 KB Output is correct
30 Correct 492 ms 3216 KB Output is correct
31 Correct 501 ms 3304 KB Output is correct
32 Correct 512 ms 3540 KB Output is correct
33 Correct 510 ms 3540 KB Output is correct
34 Correct 507 ms 3540 KB Output is correct
35 Correct 390 ms 3540 KB Output is correct
36 Correct 380 ms 3540 KB Output is correct
37 Correct 383 ms 3540 KB Output is correct
38 Correct 388 ms 3540 KB Output is correct
39 Correct 13 ms 3540 KB Output is correct
40 Correct 13 ms 3540 KB Output is correct
41 Correct 11 ms 3540 KB Output is correct
42 Correct 11 ms 3540 KB Output is correct
43 Correct 12 ms 3540 KB Output is correct
44 Correct 12 ms 3540 KB Output is correct
45 Correct 13 ms 3540 KB Output is correct
46 Correct 12 ms 3540 KB Output is correct
47 Correct 13 ms 3540 KB Output is correct
48 Correct 12 ms 3540 KB Output is correct
49 Correct 10 ms 3540 KB Output is correct
50 Correct 10 ms 3540 KB Output is correct
51 Correct 10 ms 3540 KB Output is correct
52 Correct 9 ms 3540 KB Output is correct
53 Correct 10 ms 3540 KB Output is correct
54 Correct 7 ms 3540 KB Output is correct
55 Correct 6 ms 3540 KB Output is correct
56 Correct 7 ms 3540 KB Output is correct
57 Correct 7 ms 3540 KB Output is correct
58 Correct 6 ms 3540 KB Output is correct
59 Correct 854 ms 3540 KB Output is correct
60 Correct 824 ms 3596 KB Output is correct
61 Correct 788 ms 3624 KB Output is correct
62 Correct 882 ms 3624 KB Output is correct
63 Correct 980 ms 3624 KB Output is correct
64 Correct 1215 ms 3624 KB Output is correct
65 Correct 1316 ms 3668 KB Output is correct
66 Correct 1175 ms 3668 KB Output is correct
67 Correct 1243 ms 3820 KB Output is correct
68 Correct 1141 ms 3820 KB Output is correct
69 Correct 821 ms 3820 KB Output is correct
70 Correct 819 ms 3820 KB Output is correct
71 Correct 778 ms 3820 KB Output is correct
72 Correct 862 ms 3820 KB Output is correct
73 Correct 829 ms 3820 KB Output is correct
74 Correct 160 ms 3820 KB Output is correct
75 Correct 163 ms 3820 KB Output is correct
76 Correct 165 ms 3820 KB Output is correct
77 Correct 169 ms 3820 KB Output is correct
78 Correct 158 ms 3820 KB Output is correct