답안 #315992

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
315992 2020-10-24T17:15:52 Z phathnv Boat (APIO16_boat) C++11
9 / 100
485 ms 6392 KB
#include <bits/stdc++.h>

#define mp make_pair
#define X first
#define Y second
#define taskname "Boat"

using namespace std;

typedef long long ll;
typedef pair <int, int> ii;

const int N = 502;
const int MOD = 1e9 + 7;

int n, a[N], b[N];
int nX, x[2 * N], inv[N], dp[2][N * 2][N], sumDp[N * 2][N];

void readInput(){
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> a[i] >> b[i];
}

void compress(){
    for(int i = 1; i <= n; i++){
        x[++nX] = a[i];
        x[++nX] = ++b[i];
    }
    sort(x + 1, x + 1 + nX);
    nX = unique(x + 1, x + 1 + nX) - (x + 1);
    for(int i = 1; i <= n; i++){
        a[i] = lower_bound(x + 1, x + 1 + nX, a[i]) - x;
        b[i] = lower_bound(x + 1, x + 1 + nX, b[i]) - x;
    }
}

int powMod(int x, int k){
    if (k == 0)
        return 1;
    int res = powMod(x, k >> 1);
    res = (ll) res * res % MOD;
    if (k & 1)
        res = (ll) res * x % MOD;
    return res;
}

void prepare(){
    for(int i = 1; i <= n; i++)
        b[i]--;
    inv[0] = 1;
    for(int i = 1; i <= n; i++)
        inv[i] = powMod(i, MOD - 2);
}

void add(int &x, int y){
    x += y;
    x -= (x >= MOD) * MOD;
}

void solve(){
    for(int i = 0; i < n; i++){
        int id = i & 1;
        for(int j = 1; j < nX; j++){
            int len = min(n, x[j + 1] - x[j]);
            for(int k = 1; k <= len; k++)
                dp[id ^ 1][j][k] = 0;
        }

        int sum = 1;
        for(int j = 1; j < nX; j++){
            int len = min(n, x[j + 1] - x[j]);
            if (a[i + 1] <= j && j <= b[i + 1])
                add(dp[id ^ 1][j][1], (ll) sum * len % MOD);
            for(int k = 1; k <= len; k++){
                add(sum, sumDp[j][k]);
                if (a[i + 1] <= j && j <= b[i + 1] && k < len)
                    add(dp[id ^ 1][j][k + 1], (ll) sumDp[j][k] * (len - k) % MOD * inv[k + 1] % MOD);
            }
        }
        for(int j = 1; j < nX; j++){
            int len = min(n, x[j + 1] - x[j]);
            for(int k = 1; k <= len; k++)
                add(sumDp[j][k], dp[id ^ 1][j][k]);
        }
    }

    int res = 0;
    for(int j = 1; j < nX; j++){
        int len = min(n, x[j + 1] - x[j]);
        for(int k = 1; k <= len; k++)
            add(res, sumDp[j][k]);
    }
    cout << res;
}

int main(){
    if (fopen(taskname".inp", "r")){
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }
    readInput();
    compress();
    prepare();
    solve();
    return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:99:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   99 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
boat.cpp:100:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  100 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 475 ms 6268 KB Output is correct
2 Correct 473 ms 6264 KB Output is correct
3 Correct 469 ms 6264 KB Output is correct
4 Correct 468 ms 6264 KB Output is correct
5 Correct 472 ms 6260 KB Output is correct
6 Correct 465 ms 6272 KB Output is correct
7 Correct 457 ms 6264 KB Output is correct
8 Correct 462 ms 6264 KB Output is correct
9 Correct 467 ms 6264 KB Output is correct
10 Correct 466 ms 6392 KB Output is correct
11 Correct 469 ms 6264 KB Output is correct
12 Correct 479 ms 6272 KB Output is correct
13 Correct 485 ms 6264 KB Output is correct
14 Correct 467 ms 6272 KB Output is correct
15 Correct 462 ms 6264 KB Output is correct
16 Correct 74 ms 1408 KB Output is correct
17 Correct 84 ms 1408 KB Output is correct
18 Correct 77 ms 1448 KB Output is correct
19 Correct 85 ms 1536 KB Output is correct
20 Correct 82 ms 1408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 475 ms 6268 KB Output is correct
2 Correct 473 ms 6264 KB Output is correct
3 Correct 469 ms 6264 KB Output is correct
4 Correct 468 ms 6264 KB Output is correct
5 Correct 472 ms 6260 KB Output is correct
6 Correct 465 ms 6272 KB Output is correct
7 Correct 457 ms 6264 KB Output is correct
8 Correct 462 ms 6264 KB Output is correct
9 Correct 467 ms 6264 KB Output is correct
10 Correct 466 ms 6392 KB Output is correct
11 Correct 469 ms 6264 KB Output is correct
12 Correct 479 ms 6272 KB Output is correct
13 Correct 485 ms 6264 KB Output is correct
14 Correct 467 ms 6272 KB Output is correct
15 Correct 462 ms 6264 KB Output is correct
16 Correct 74 ms 1408 KB Output is correct
17 Correct 84 ms 1408 KB Output is correct
18 Correct 77 ms 1448 KB Output is correct
19 Correct 85 ms 1536 KB Output is correct
20 Correct 82 ms 1408 KB Output is correct
21 Correct 36 ms 5752 KB Output is correct
22 Correct 38 ms 5760 KB Output is correct
23 Correct 36 ms 5632 KB Output is correct
24 Correct 40 ms 5632 KB Output is correct
25 Correct 38 ms 5632 KB Output is correct
26 Correct 30 ms 5504 KB Output is correct
27 Correct 31 ms 5632 KB Output is correct
28 Correct 34 ms 5624 KB Output is correct
29 Correct 30 ms 5504 KB Output is correct
30 Incorrect 436 ms 6144 KB Output isn't correct
31 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 1536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 475 ms 6268 KB Output is correct
2 Correct 473 ms 6264 KB Output is correct
3 Correct 469 ms 6264 KB Output is correct
4 Correct 468 ms 6264 KB Output is correct
5 Correct 472 ms 6260 KB Output is correct
6 Correct 465 ms 6272 KB Output is correct
7 Correct 457 ms 6264 KB Output is correct
8 Correct 462 ms 6264 KB Output is correct
9 Correct 467 ms 6264 KB Output is correct
10 Correct 466 ms 6392 KB Output is correct
11 Correct 469 ms 6264 KB Output is correct
12 Correct 479 ms 6272 KB Output is correct
13 Correct 485 ms 6264 KB Output is correct
14 Correct 467 ms 6272 KB Output is correct
15 Correct 462 ms 6264 KB Output is correct
16 Correct 74 ms 1408 KB Output is correct
17 Correct 84 ms 1408 KB Output is correct
18 Correct 77 ms 1448 KB Output is correct
19 Correct 85 ms 1536 KB Output is correct
20 Correct 82 ms 1408 KB Output is correct
21 Correct 36 ms 5752 KB Output is correct
22 Correct 38 ms 5760 KB Output is correct
23 Correct 36 ms 5632 KB Output is correct
24 Correct 40 ms 5632 KB Output is correct
25 Correct 38 ms 5632 KB Output is correct
26 Correct 30 ms 5504 KB Output is correct
27 Correct 31 ms 5632 KB Output is correct
28 Correct 34 ms 5624 KB Output is correct
29 Correct 30 ms 5504 KB Output is correct
30 Incorrect 436 ms 6144 KB Output isn't correct
31 Halted 0 ms 0 KB -