Submission #203416

# Submission time Handle Problem Language Result Execution time Memory
203416 2020-02-20T15:02:36 Z dsabolic Boat (APIO16_boat) C++17
9 / 100
108 ms 4776 KB
#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, n) for(int (i) = (a); (i) < (n); ++(i))
#define per(i, n, a) for(int (i) = (n) - 1; (i) >= (a); --(i))
#define trav(i, x) for(auto& (i) : (x))
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define X first
#define Y second

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef double db;
mt19937 mrand(random_device{}());

const int INF = 0x3f3f3f3f;
const int OFF = 1 << 20;
const int MOD = (int)1e9 + 7;
const int N = 550;

int n;
pii q[N];
vector<int> comp;
int dist[2 * N];
int dp[N][2 * N];
int binom[2 * N][N];

int add(int a, int b) {
    if(a + b >= MOD) return a + b - MOD;
    return a + b;
}

void gen_pascal() {
    binom[0][0] = 1;
    rep(i, 1, SZ(comp)) {
        binom[i][0] = 1;

        rep(j, 1, i + 1)
            binom[i][j] = add(binom[i - 1][j], binom[i - 1][j - 1]);
    }
}
int main() {
    scanf("%d", &n);
    rep(i, 1, n + 1) {
        scanf("%d%d", &q[i].X, &q[i].Y);
        comp.pb(q[i].X); comp.pb(q[i].Y + 1);
    }
    sort(all(comp));
    gen_pascal();

    comp.erase(unique(all(comp)), comp.end());

    rep(i, 1, n + 1) {
        q[i].X = lower_bound(all(comp), q[i].X) - comp.begin() + 1;
        q[i].Y = lower_bound(all(comp), q[i].Y + 1) - comp.begin();
    }
    rep(i, 1, SZ(comp)) dist[i] = comp[i] - comp[i - 1];

    rep(j, 0, SZ(comp)) dp[0][j] = 1;
    rep(i, 1, n + 1) { // fiksiramo prefix
        dp[i][0] = 1;
        rep(j, q[i].X, q[i].Y + 1) { // fiksiramo kraj
            dp[i][j] = add(dp[i][j], dp[i - 1][j - 1] * dist[j]); // ako samo sebe uzimamo
            //printf("dp[%d][%d] -> %d\n", i, j, dp[i][j]);

            int cnt = 1;
            per(k, i, 1) {
                if(j >= q[k].X && j <= q[k].Y) {
                    dp[i][j] = add(dp[i][j], dp[k - 1][j - 1] * binom[dist[j]][++cnt]);
                }
            }
        }

        rep(j, 1, SZ(comp))
            dp[i][j] = (dp[i][j] + dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]) % MOD;
    }

    printf("%d\n", (dp[n][SZ(comp) - 1] - 1 + MOD) % MOD);

    return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:48:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
boat.cpp:50:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &q[i].X, &q[i].Y);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 4600 KB Output is correct
2 Correct 13 ms 4728 KB Output is correct
3 Correct 13 ms 4728 KB Output is correct
4 Correct 13 ms 4600 KB Output is correct
5 Correct 13 ms 4600 KB Output is correct
6 Correct 13 ms 4600 KB Output is correct
7 Correct 12 ms 4600 KB Output is correct
8 Correct 12 ms 4776 KB Output is correct
9 Correct 12 ms 4600 KB Output is correct
10 Correct 12 ms 4600 KB Output is correct
11 Correct 12 ms 4600 KB Output is correct
12 Correct 12 ms 4604 KB Output is correct
13 Correct 12 ms 4600 KB Output is correct
14 Correct 14 ms 4728 KB Output is correct
15 Correct 12 ms 4728 KB Output is correct
16 Correct 9 ms 4600 KB Output is correct
17 Correct 11 ms 4600 KB Output is correct
18 Correct 11 ms 4600 KB Output is correct
19 Correct 9 ms 4600 KB Output is correct
20 Correct 9 ms 4600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 4600 KB Output is correct
2 Correct 13 ms 4728 KB Output is correct
3 Correct 13 ms 4728 KB Output is correct
4 Correct 13 ms 4600 KB Output is correct
5 Correct 13 ms 4600 KB Output is correct
6 Correct 13 ms 4600 KB Output is correct
7 Correct 12 ms 4600 KB Output is correct
8 Correct 12 ms 4776 KB Output is correct
9 Correct 12 ms 4600 KB Output is correct
10 Correct 12 ms 4600 KB Output is correct
11 Correct 12 ms 4600 KB Output is correct
12 Correct 12 ms 4604 KB Output is correct
13 Correct 12 ms 4600 KB Output is correct
14 Correct 14 ms 4728 KB Output is correct
15 Correct 12 ms 4728 KB Output is correct
16 Correct 9 ms 4600 KB Output is correct
17 Correct 11 ms 4600 KB Output is correct
18 Correct 11 ms 4600 KB Output is correct
19 Correct 9 ms 4600 KB Output is correct
20 Correct 9 ms 4600 KB Output is correct
21 Incorrect 108 ms 4728 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 1400 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 4600 KB Output is correct
2 Correct 13 ms 4728 KB Output is correct
3 Correct 13 ms 4728 KB Output is correct
4 Correct 13 ms 4600 KB Output is correct
5 Correct 13 ms 4600 KB Output is correct
6 Correct 13 ms 4600 KB Output is correct
7 Correct 12 ms 4600 KB Output is correct
8 Correct 12 ms 4776 KB Output is correct
9 Correct 12 ms 4600 KB Output is correct
10 Correct 12 ms 4600 KB Output is correct
11 Correct 12 ms 4600 KB Output is correct
12 Correct 12 ms 4604 KB Output is correct
13 Correct 12 ms 4600 KB Output is correct
14 Correct 14 ms 4728 KB Output is correct
15 Correct 12 ms 4728 KB Output is correct
16 Correct 9 ms 4600 KB Output is correct
17 Correct 11 ms 4600 KB Output is correct
18 Correct 11 ms 4600 KB Output is correct
19 Correct 9 ms 4600 KB Output is correct
20 Correct 9 ms 4600 KB Output is correct
21 Incorrect 108 ms 4728 KB Output isn't correct
22 Halted 0 ms 0 KB -