답안 #108349

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
108349 2019-04-28T16:14:31 Z kuroni Boat (APIO16_boat) C++17
100 / 100
225 ms 512 KB
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

const int N = 510, MOD = 1E9 + 7;

int n, l, r;
bool vis[N];
long long ans = 0, f[N], g[N], c[N], inv[N];
vector<pair<int, int>> sw;
vector<int> ve;

void init()
{
    c[0] = 1;
    vis[0] = true;
    for (int i = 0; i <= n; i++)
        f[i] = 1;
    inv[1] = 1;
    for (int i = 2; i <= n + 2; i++)
        inv[i] = MOD - MOD / i * inv[MOD % i] % MOD;
}

long long sum(int l, int r)
{
    return f[r] - (l == 0 ? 0 : f[l - 1]);
}

long long solve(int u, int len)
{
    long long ret = 0;
    vis[u] = !vis[u];
    ve.clear();
    for (int i = 0; i <= n; i++)
        if (vis[i])
            ve.push_back(i);
    for (int i = 1; i <= (int)ve.size() + 2; i++)
        c[i] = c[i - 1] * (len + i - 1) % MOD * inv[i] % MOD;
    for (int i = 1; i < (int)ve.size(); i++)
        for (int j = 0; j < i; j++)
            (g[ve[i]] += c[i - j] * sum(ve[j], ve[j + 1] - 1)) %= MOD;
    for (int i = 1; i <= n; i++)
    {
        (ret += g[i]) %= MOD;
        (f[i] += ret) %= MOD;
        g[i] = 0;
    }
    return ret;
}

int main()
{
    scanf("%d", &n);
    init();
    for (int i = 1; i <= n; i++)
    {
        scanf("%d%d", &l, &r);
        sw.push_back({l, i});
        sw.push_back({r + 1, i});
    }
    sort(sw.begin(), sw.end());
    for (int i = 0; i < (int)sw.size() - 1; i++)
        (ans += solve(sw[i].second, sw[i + 1].first - sw[i].first)) %= MOD;
    printf("%lld\n", (ans + MOD) % MOD);
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:55:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
boat.cpp:59:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &l, &r);
         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 384 KB Output is correct
2 Correct 10 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 7 ms 384 KB Output is correct
5 Correct 8 ms 384 KB Output is correct
6 Correct 7 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 7 ms 384 KB Output is correct
10 Correct 7 ms 384 KB Output is correct
11 Correct 7 ms 384 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 7 ms 384 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 7 ms 384 KB Output is correct
16 Correct 8 ms 384 KB Output is correct
17 Correct 7 ms 384 KB Output is correct
18 Correct 6 ms 384 KB Output is correct
19 Correct 6 ms 384 KB Output is correct
20 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 384 KB Output is correct
2 Correct 10 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 7 ms 384 KB Output is correct
5 Correct 8 ms 384 KB Output is correct
6 Correct 7 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 7 ms 384 KB Output is correct
10 Correct 7 ms 384 KB Output is correct
11 Correct 7 ms 384 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 7 ms 384 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 7 ms 384 KB Output is correct
16 Correct 8 ms 384 KB Output is correct
17 Correct 7 ms 384 KB Output is correct
18 Correct 6 ms 384 KB Output is correct
19 Correct 6 ms 384 KB Output is correct
20 Correct 6 ms 384 KB Output is correct
21 Correct 86 ms 504 KB Output is correct
22 Correct 84 ms 396 KB Output is correct
23 Correct 76 ms 424 KB Output is correct
24 Correct 89 ms 476 KB Output is correct
25 Correct 85 ms 384 KB Output is correct
26 Correct 206 ms 504 KB Output is correct
27 Correct 225 ms 384 KB Output is correct
28 Correct 198 ms 384 KB Output is correct
29 Correct 222 ms 504 KB Output is correct
30 Correct 6 ms 384 KB Output is correct
31 Correct 7 ms 384 KB Output is correct
32 Correct 7 ms 512 KB Output is correct
33 Correct 6 ms 384 KB Output is correct
34 Correct 6 ms 384 KB Output is correct
35 Correct 6 ms 512 KB Output is correct
36 Correct 6 ms 384 KB Output is correct
37 Correct 7 ms 384 KB Output is correct
38 Correct 7 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 384 KB Output is correct
2 Correct 10 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 7 ms 384 KB Output is correct
5 Correct 8 ms 384 KB Output is correct
6 Correct 7 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 7 ms 384 KB Output is correct
10 Correct 7 ms 384 KB Output is correct
11 Correct 7 ms 384 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 7 ms 384 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 7 ms 384 KB Output is correct
16 Correct 8 ms 384 KB Output is correct
17 Correct 7 ms 384 KB Output is correct
18 Correct 6 ms 384 KB Output is correct
19 Correct 6 ms 384 KB Output is correct
20 Correct 6 ms 384 KB Output is correct
21 Correct 86 ms 504 KB Output is correct
22 Correct 84 ms 396 KB Output is correct
23 Correct 76 ms 424 KB Output is correct
24 Correct 89 ms 476 KB Output is correct
25 Correct 85 ms 384 KB Output is correct
26 Correct 206 ms 504 KB Output is correct
27 Correct 225 ms 384 KB Output is correct
28 Correct 198 ms 384 KB Output is correct
29 Correct 222 ms 504 KB Output is correct
30 Correct 6 ms 384 KB Output is correct
31 Correct 7 ms 384 KB Output is correct
32 Correct 7 ms 512 KB Output is correct
33 Correct 6 ms 384 KB Output is correct
34 Correct 6 ms 384 KB Output is correct
35 Correct 6 ms 512 KB Output is correct
36 Correct 6 ms 384 KB Output is correct
37 Correct 7 ms 384 KB Output is correct
38 Correct 7 ms 384 KB Output is correct
39 Correct 3 ms 384 KB Output is correct
40 Correct 3 ms 384 KB Output is correct
41 Correct 3 ms 384 KB Output is correct
42 Correct 3 ms 384 KB Output is correct
43 Correct 4 ms 384 KB Output is correct
44 Correct 3 ms 384 KB Output is correct
45 Correct 4 ms 384 KB Output is correct
46 Correct 3 ms 384 KB Output is correct
47 Correct 4 ms 384 KB Output is correct
48 Correct 4 ms 384 KB Output is correct
49 Correct 3 ms 384 KB Output is correct
50 Correct 3 ms 384 KB Output is correct
51 Correct 4 ms 384 KB Output is correct
52 Correct 4 ms 384 KB Output is correct
53 Correct 3 ms 384 KB Output is correct
54 Correct 3 ms 384 KB Output is correct
55 Correct 3 ms 384 KB Output is correct
56 Correct 3 ms 384 KB Output is correct
57 Correct 3 ms 384 KB Output is correct
58 Correct 3 ms 384 KB Output is correct
59 Correct 90 ms 384 KB Output is correct
60 Correct 79 ms 428 KB Output is correct
61 Correct 76 ms 388 KB Output is correct
62 Correct 90 ms 384 KB Output is correct
63 Correct 82 ms 384 KB Output is correct
64 Correct 223 ms 384 KB Output is correct
65 Correct 214 ms 384 KB Output is correct
66 Correct 198 ms 384 KB Output is correct
67 Correct 212 ms 424 KB Output is correct
68 Correct 215 ms 504 KB Output is correct
69 Correct 78 ms 384 KB Output is correct
70 Correct 76 ms 384 KB Output is correct
71 Correct 74 ms 384 KB Output is correct
72 Correct 81 ms 384 KB Output is correct
73 Correct 89 ms 504 KB Output is correct
74 Correct 93 ms 384 KB Output is correct
75 Correct 81 ms 384 KB Output is correct
76 Correct 92 ms 384 KB Output is correct
77 Correct 88 ms 384 KB Output is correct
78 Correct 98 ms 384 KB Output is correct