Submission #48373

# Submission time Handle Problem Language Result Execution time Memory
48373 2018-05-12T09:37:57 Z BThero Boat (APIO16_boat) C++17
9 / 100
2000 ms 2620 KB
// Why am I so stupid? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

typedef long long ll;

using namespace std;

const int mod = 1e9+7;

pair <int, int> l[505];

pair <int, int> r[505];

int dp[505][1005];

int rl[1005];

int ans;

int n;

void addMod(int &a, int b) {
    a += b;

    if (mod <= a) {
        a -= mod;
    }
}

void compress() {
    vector <int> vv;

    for (int i = 1; i <= n; ++i) {
        vv.pb(l[i].fi);
        vv.pb(r[i].fi);
    }

    sort(all(vv));
    vv.resize(unique(all(vv)) - vv.begin());

    for (int i = 1; i <= n; ++i) {
        l[i].se = upper_bound(all(vv), l[i].fi) - vv.begin();
        r[i].se = upper_bound(all(vv), r[i].fi) - vv.begin();
    }

    for (int i = 1; i <= n; ++i) {
        rl[l[i].se] = l[i].fi;
        rl[r[i].se] = r[i].fi;
    }
}

void solve() {
    scanf("%d", &n);

    for (int i = 1; i <= n; ++i) {
        scanf("%d %d", &l[i].fi, &r[i].fi);
    }

    compress();

    for (int i = 1; i <= n; ++i) {
        for (int cur = l[i].se; cur <= r[i].se; ++cur) {
            dp[i][cur] = 1;

            for (int j = 1; j < i; ++j) {
                int lim = min(cur - 1, r[j].se);

                for (int pr = l[j].se; pr <= lim; ++pr) {
                    int mlt = (rl[lim] - rl[pr] + 1);

                    addMod(dp[i][cur], dp[j][pr] * 1ll * mlt % mod);
                }
            }
        }
    }

    for (int i = 1; i <= n; ++i) {
        for (int last = l[i].se; last <= r[i].se; ++last) {
            addMod(ans, dp[i][last]);
        }
    }

    printf("%d\n", ans);
}

int main() {
#ifdef BThero
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // BThero

    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Compilation message

boat.cpp: In function 'void solve()':
boat.cpp:61:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
boat.cpp:64:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &l[i].fi, &r[i].fi);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2168 KB Output is correct
2 Correct 4 ms 2168 KB Output is correct
3 Correct 4 ms 2224 KB Output is correct
4 Correct 4 ms 2224 KB Output is correct
5 Correct 4 ms 2252 KB Output is correct
6 Correct 5 ms 2380 KB Output is correct
7 Correct 4 ms 2380 KB Output is correct
8 Correct 4 ms 2556 KB Output is correct
9 Correct 4 ms 2556 KB Output is correct
10 Correct 4 ms 2556 KB Output is correct
11 Correct 5 ms 2608 KB Output is correct
12 Correct 4 ms 2608 KB Output is correct
13 Correct 4 ms 2620 KB Output is correct
14 Correct 4 ms 2620 KB Output is correct
15 Correct 4 ms 2620 KB Output is correct
16 Correct 4 ms 2620 KB Output is correct
17 Correct 4 ms 2620 KB Output is correct
18 Correct 4 ms 2620 KB Output is correct
19 Correct 4 ms 2620 KB Output is correct
20 Correct 4 ms 2620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2168 KB Output is correct
2 Correct 4 ms 2168 KB Output is correct
3 Correct 4 ms 2224 KB Output is correct
4 Correct 4 ms 2224 KB Output is correct
5 Correct 4 ms 2252 KB Output is correct
6 Correct 5 ms 2380 KB Output is correct
7 Correct 4 ms 2380 KB Output is correct
8 Correct 4 ms 2556 KB Output is correct
9 Correct 4 ms 2556 KB Output is correct
10 Correct 4 ms 2556 KB Output is correct
11 Correct 5 ms 2608 KB Output is correct
12 Correct 4 ms 2608 KB Output is correct
13 Correct 4 ms 2620 KB Output is correct
14 Correct 4 ms 2620 KB Output is correct
15 Correct 4 ms 2620 KB Output is correct
16 Correct 4 ms 2620 KB Output is correct
17 Correct 4 ms 2620 KB Output is correct
18 Correct 4 ms 2620 KB Output is correct
19 Correct 4 ms 2620 KB Output is correct
20 Correct 4 ms 2620 KB Output is correct
21 Execution timed out 2067 ms 2620 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 2620 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2168 KB Output is correct
2 Correct 4 ms 2168 KB Output is correct
3 Correct 4 ms 2224 KB Output is correct
4 Correct 4 ms 2224 KB Output is correct
5 Correct 4 ms 2252 KB Output is correct
6 Correct 5 ms 2380 KB Output is correct
7 Correct 4 ms 2380 KB Output is correct
8 Correct 4 ms 2556 KB Output is correct
9 Correct 4 ms 2556 KB Output is correct
10 Correct 4 ms 2556 KB Output is correct
11 Correct 5 ms 2608 KB Output is correct
12 Correct 4 ms 2608 KB Output is correct
13 Correct 4 ms 2620 KB Output is correct
14 Correct 4 ms 2620 KB Output is correct
15 Correct 4 ms 2620 KB Output is correct
16 Correct 4 ms 2620 KB Output is correct
17 Correct 4 ms 2620 KB Output is correct
18 Correct 4 ms 2620 KB Output is correct
19 Correct 4 ms 2620 KB Output is correct
20 Correct 4 ms 2620 KB Output is correct
21 Execution timed out 2067 ms 2620 KB Time limit exceeded
22 Halted 0 ms 0 KB -