Submission #108348

# Submission time Handle Problem Language Result Execution time Memory
108348 2019-04-28T16:12:30 Z kuroni Boat (APIO16_boat) C++17
9 / 100
103 ms 384 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);
    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);
         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 384 KB Output is correct
2 Correct 8 ms 384 KB Output is correct
3 Correct 7 ms 384 KB Output is correct
4 Correct 7 ms 384 KB Output is correct
5 Correct 6 ms 256 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 7 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 7 ms 384 KB Output is correct
12 Correct 7 ms 384 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 7 ms 384 KB Output is correct
15 Correct 7 ms 384 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 6 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 7 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 384 KB Output is correct
2 Correct 8 ms 384 KB Output is correct
3 Correct 7 ms 384 KB Output is correct
4 Correct 7 ms 384 KB Output is correct
5 Correct 6 ms 256 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 7 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 7 ms 384 KB Output is correct
12 Correct 7 ms 384 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 7 ms 384 KB Output is correct
15 Correct 7 ms 384 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 6 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 7 ms 384 KB Output is correct
21 Incorrect 103 ms 384 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 384 KB Output is correct
2 Correct 8 ms 384 KB Output is correct
3 Correct 7 ms 384 KB Output is correct
4 Correct 7 ms 384 KB Output is correct
5 Correct 6 ms 256 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 7 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 7 ms 384 KB Output is correct
12 Correct 7 ms 384 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 7 ms 384 KB Output is correct
15 Correct 7 ms 384 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 6 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 7 ms 384 KB Output is correct
21 Incorrect 103 ms 384 KB Output isn't correct
22 Halted 0 ms 0 KB -