Submission #44897

# Submission time Handle Problem Language Result Execution time Memory
44897 2018-04-09T06:57:34 Z Kerim Boat (APIO16_boat) C++17
100 / 100
1286 ms 2676 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#define pb push_back
#define orta (bas + son >> 1)
#define sag (k + k + 1)
#define sol (k + k)
#define endl '\n'
#define foreach(i,x) for(type(x)i=x.begin();i!=x.end();i++)
#define FOR(ii,aa,bb) for(int ii=aa;ii<=bb;ii++)
#define ROF(ii,aa,bb) for(int ii=aa;ii>=bb;ii--)
#define mp make_pair
#define nd second
#define st first
#define type(x) __typeof(x.begin())
 
typedef pair < int ,int > pii;
 
typedef long long ll;
 
const long long linf = 1e18+5;
const int mod = (int) 1e9 + 7;
const int logN = 17;
const int inf = 1e9 + 7;
const int N = 2e5 + 5;
 
int F[N], P[N], con[N], m, pre[N], n, l, r, x, y, z, dp[N], dd[505][505];
map< int , vector< int > > add, del;
map< int , int > H;
vector< int > v;
 
int FE(int x, int k) {
    if(!k) return 1;
    int temp = FE(x, k / 2);
    if(k & 1) return (ll) temp * temp % mod * x % mod;
    return (ll) temp * temp % mod;
}
 
int GO(int x, int y) {
    int ans = 1;
    FOR(i, 1, y) ans = ans * (ll) x-- % mod;
    return ans;
}
 
void calc(int x) {
    FOR(i, 1, m) {
        con[i] = GO(x, i) * (ll) F[i] % mod;
    }
}
 
int NX(type(H) it) {
    it++;
    if(it == H.end()) return inf + 5;
    return it->st;
}
 
int f(int x, int y) {
    if(y == 0 || x == 0 || y > x) return 0;
    int &r = dd[x][y];
    if(r != -1) return r;
    if(y == 1) return r = (pre[v[x] - 1] + f(x - 1, y)) % mod;
    return r = (f(x - 1, y) + f(x - 1, y - 1)) % mod;
}
 
int main() {
	//~ freopen("file.in","r",stdin);
    scanf("%d", &n);
 
    P[0] = 1;
    FOR(i, 1, n) P[i] = P[i-1] * (ll) i % mod;
    FOR(i, 0, n) F[i] = FE(P[i], mod - 2);
 
    FOR(i, 1, n) {
        scanf("%d %d", &l, &r);
        add[l].pb(i);
        del[r + 1].pb(i);
        H[l] = H[r + 1] = 1;
    }
 
    set< int > S;
 
    foreach(tt, H) {
        int p = tt->st, next = NX(tt);
        foreach(it, add[p]) S.insert(*it);
        foreach(it, del[p]) S.erase(S.find(*it));
        if(S.size()) {
            v.clear();
            pre[0] = 1; FOR(i, 1, n) pre[i] = (dp[i] + pre[i-1]) % mod;
            v.pb(0); foreach(it, S) v.pb(*it);
            m = v.size() - 1;
            calc(next - p);
            memset(dd, -1, sizeof dd);
            FOR(i, 1, m)
                FOR(j, 1, i) {
                    if(j == 1) {
                        dp[v[i]] = (dp[v[i]] + con[j] * (ll) pre[v[i] - 1]) % mod;
                    }
                    else {
                        dp[v[i]] = (dp[v[i]] + con[j] * (ll) f(i - 1, j - 1)) % mod;
                    }
                }
        }
    }
 
    dp[0] = 0;
    FOR(i, 1, n) dp[i] = (dp[i] + dp[i-1]) % mod;
 
    cout << dp[n] << endl;
 
    return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:68:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
boat.cpp:75:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &l, &r);
         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 32 ms 1528 KB Output is correct
2 Correct 32 ms 1636 KB Output is correct
3 Correct 32 ms 1840 KB Output is correct
4 Correct 31 ms 1840 KB Output is correct
5 Correct 31 ms 1840 KB Output is correct
6 Correct 31 ms 1840 KB Output is correct
7 Correct 32 ms 1984 KB Output is correct
8 Correct 31 ms 1984 KB Output is correct
9 Correct 32 ms 1984 KB Output is correct
10 Correct 36 ms 1984 KB Output is correct
11 Correct 31 ms 1984 KB Output is correct
12 Correct 34 ms 1984 KB Output is correct
13 Correct 32 ms 1984 KB Output is correct
14 Correct 32 ms 1984 KB Output is correct
15 Correct 31 ms 1984 KB Output is correct
16 Correct 9 ms 1984 KB Output is correct
17 Correct 9 ms 1984 KB Output is correct
18 Correct 9 ms 1984 KB Output is correct
19 Correct 10 ms 1984 KB Output is correct
20 Correct 8 ms 1984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 1528 KB Output is correct
2 Correct 32 ms 1636 KB Output is correct
3 Correct 32 ms 1840 KB Output is correct
4 Correct 31 ms 1840 KB Output is correct
5 Correct 31 ms 1840 KB Output is correct
6 Correct 31 ms 1840 KB Output is correct
7 Correct 32 ms 1984 KB Output is correct
8 Correct 31 ms 1984 KB Output is correct
9 Correct 32 ms 1984 KB Output is correct
10 Correct 36 ms 1984 KB Output is correct
11 Correct 31 ms 1984 KB Output is correct
12 Correct 34 ms 1984 KB Output is correct
13 Correct 32 ms 1984 KB Output is correct
14 Correct 32 ms 1984 KB Output is correct
15 Correct 31 ms 1984 KB Output is correct
16 Correct 9 ms 1984 KB Output is correct
17 Correct 9 ms 1984 KB Output is correct
18 Correct 9 ms 1984 KB Output is correct
19 Correct 10 ms 1984 KB Output is correct
20 Correct 8 ms 1984 KB Output is correct
21 Correct 494 ms 1984 KB Output is correct
22 Correct 521 ms 2000 KB Output is correct
23 Correct 484 ms 2084 KB Output is correct
24 Correct 487 ms 2088 KB Output is correct
25 Correct 501 ms 2168 KB Output is correct
26 Correct 1022 ms 2304 KB Output is correct
27 Correct 1208 ms 2304 KB Output is correct
28 Correct 1029 ms 2304 KB Output is correct
29 Correct 1059 ms 2304 KB Output is correct
30 Correct 56 ms 2304 KB Output is correct
31 Correct 60 ms 2304 KB Output is correct
32 Correct 58 ms 2304 KB Output is correct
33 Correct 62 ms 2304 KB Output is correct
34 Correct 56 ms 2304 KB Output is correct
35 Correct 57 ms 2304 KB Output is correct
36 Correct 62 ms 2304 KB Output is correct
37 Correct 59 ms 2304 KB Output is correct
38 Correct 56 ms 2304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 2304 KB Output is correct
2 Correct 15 ms 2304 KB Output is correct
3 Correct 17 ms 2304 KB Output is correct
4 Correct 18 ms 2304 KB Output is correct
5 Correct 17 ms 2304 KB Output is correct
6 Correct 23 ms 2304 KB Output is correct
7 Correct 21 ms 2304 KB Output is correct
8 Correct 21 ms 2304 KB Output is correct
9 Correct 22 ms 2304 KB Output is correct
10 Correct 22 ms 2304 KB Output is correct
11 Correct 17 ms 2304 KB Output is correct
12 Correct 16 ms 2304 KB Output is correct
13 Correct 19 ms 2304 KB Output is correct
14 Correct 16 ms 2304 KB Output is correct
15 Correct 17 ms 2304 KB Output is correct
16 Correct 11 ms 2304 KB Output is correct
17 Correct 13 ms 2304 KB Output is correct
18 Correct 11 ms 2304 KB Output is correct
19 Correct 11 ms 2304 KB Output is correct
20 Correct 12 ms 2304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 1528 KB Output is correct
2 Correct 32 ms 1636 KB Output is correct
3 Correct 32 ms 1840 KB Output is correct
4 Correct 31 ms 1840 KB Output is correct
5 Correct 31 ms 1840 KB Output is correct
6 Correct 31 ms 1840 KB Output is correct
7 Correct 32 ms 1984 KB Output is correct
8 Correct 31 ms 1984 KB Output is correct
9 Correct 32 ms 1984 KB Output is correct
10 Correct 36 ms 1984 KB Output is correct
11 Correct 31 ms 1984 KB Output is correct
12 Correct 34 ms 1984 KB Output is correct
13 Correct 32 ms 1984 KB Output is correct
14 Correct 32 ms 1984 KB Output is correct
15 Correct 31 ms 1984 KB Output is correct
16 Correct 9 ms 1984 KB Output is correct
17 Correct 9 ms 1984 KB Output is correct
18 Correct 9 ms 1984 KB Output is correct
19 Correct 10 ms 1984 KB Output is correct
20 Correct 8 ms 1984 KB Output is correct
21 Correct 494 ms 1984 KB Output is correct
22 Correct 521 ms 2000 KB Output is correct
23 Correct 484 ms 2084 KB Output is correct
24 Correct 487 ms 2088 KB Output is correct
25 Correct 501 ms 2168 KB Output is correct
26 Correct 1022 ms 2304 KB Output is correct
27 Correct 1208 ms 2304 KB Output is correct
28 Correct 1029 ms 2304 KB Output is correct
29 Correct 1059 ms 2304 KB Output is correct
30 Correct 56 ms 2304 KB Output is correct
31 Correct 60 ms 2304 KB Output is correct
32 Correct 58 ms 2304 KB Output is correct
33 Correct 62 ms 2304 KB Output is correct
34 Correct 56 ms 2304 KB Output is correct
35 Correct 57 ms 2304 KB Output is correct
36 Correct 62 ms 2304 KB Output is correct
37 Correct 59 ms 2304 KB Output is correct
38 Correct 56 ms 2304 KB Output is correct
39 Correct 17 ms 2304 KB Output is correct
40 Correct 15 ms 2304 KB Output is correct
41 Correct 17 ms 2304 KB Output is correct
42 Correct 18 ms 2304 KB Output is correct
43 Correct 17 ms 2304 KB Output is correct
44 Correct 23 ms 2304 KB Output is correct
45 Correct 21 ms 2304 KB Output is correct
46 Correct 21 ms 2304 KB Output is correct
47 Correct 22 ms 2304 KB Output is correct
48 Correct 22 ms 2304 KB Output is correct
49 Correct 17 ms 2304 KB Output is correct
50 Correct 16 ms 2304 KB Output is correct
51 Correct 19 ms 2304 KB Output is correct
52 Correct 16 ms 2304 KB Output is correct
53 Correct 17 ms 2304 KB Output is correct
54 Correct 11 ms 2304 KB Output is correct
55 Correct 13 ms 2304 KB Output is correct
56 Correct 11 ms 2304 KB Output is correct
57 Correct 11 ms 2304 KB Output is correct
58 Correct 12 ms 2304 KB Output is correct
59 Correct 559 ms 2380 KB Output is correct
60 Correct 541 ms 2392 KB Output is correct
61 Correct 492 ms 2488 KB Output is correct
62 Correct 550 ms 2488 KB Output is correct
63 Correct 532 ms 2488 KB Output is correct
64 Correct 1211 ms 2536 KB Output is correct
65 Correct 1245 ms 2584 KB Output is correct
66 Correct 1267 ms 2584 KB Output is correct
67 Correct 1257 ms 2612 KB Output is correct
68 Correct 1286 ms 2676 KB Output is correct
69 Correct 472 ms 2676 KB Output is correct
70 Correct 493 ms 2676 KB Output is correct
71 Correct 492 ms 2676 KB Output is correct
72 Correct 534 ms 2676 KB Output is correct
73 Correct 592 ms 2676 KB Output is correct
74 Correct 125 ms 2676 KB Output is correct
75 Correct 114 ms 2676 KB Output is correct
76 Correct 163 ms 2676 KB Output is correct
77 Correct 112 ms 2676 KB Output is correct
78 Correct 115 ms 2676 KB Output is correct