답안 #41609

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
41609 2018-02-19T19:40:47 Z gabrielsimoes Boat (APIO16_boat) C++14
100 / 100
230 ms 1204 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll MOD = 1000000007;
const int MAXN = 510;

ll fastpow(ll a, ll b) {
  ll result = 1;
  ll cur = a;
  while (b) {
    if (b & 1) result = (result * cur) % MOD;
    cur = (cur * cur) % MOD;
    b >>= 1;
  }
  return result;
}

int n;
int va[MAXN], vb[MAXN];
ll dp[MAXN], sum[MAXN];
vector<int> splits;
vector<ll> v;
ll inv[MAXN], bin[MAXN];

int main() {
  for (int i = 1; i < MAXN; i++) inv[i] = fastpow(i, MOD - 2);

  scanf("%d", &n);

  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &va[i], &vb[i]);
    vb[i]++;
    splits.push_back(va[i]);
    splits.push_back(vb[i]);
  }

  sort(splits.begin(), splits.end());
  splits.resize(unique(splits.begin(), splits.end()) - splits.begin());

  for (int i = 1; i <= n; i++) {
    va[i] = (lower_bound(splits.begin(), splits.end(), va[i]) - splits.begin());
    vb[i] = (lower_bound(splits.begin(), splits.end(), vb[i]) - splits.begin());
  }

  for (int split = 1; split < splits.size(); split++) {
    ll splitSize = splits[split] - splits[split - 1];

    sum[0] = 1;
    for (int i = 1; i <= n; i++) sum[i] = (sum[i - 1] + dp[i]) % MOD;
    v.clear();

    bin[0] = 1;
    for (int i = 1; i <= n; i++) {
      if (i <= splitSize + i - 2)
        bin[i] = ((((splitSize + i - 2) * inv[i]) % MOD) * bin[i - 1]) % MOD;
      else
        bin[i] = 0;
    }
    bin[1] = splitSize;

    for (int i = 1; i <= n; i++) {
      if (va[i] < split && vb[i] >= split) {
        v.push_back(sum[i - 1]);

        for (auto p = v.rbegin(); p != v.rend(); p++) {
          int cnt = (p - v.rbegin()) + 1;
          dp[i] = (dp[i] + (*p) * bin[cnt]) % MOD;
        }
      }
    }
  }

  ll ans = 0;
  for (int i = 1; i <= n; i++) ans = (ans + dp[i]) % MOD;

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

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:46:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int split = 1; split < splits.size(); split++) {
                             ^
boat.cpp:29:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
                  ^
boat.cpp:32:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &va[i], &vb[i]);
                                   ^
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 248 KB Output is correct
2 Correct 8 ms 352 KB Output is correct
3 Correct 10 ms 428 KB Output is correct
4 Correct 8 ms 496 KB Output is correct
5 Correct 9 ms 608 KB Output is correct
6 Correct 7 ms 608 KB Output is correct
7 Correct 7 ms 608 KB Output is correct
8 Correct 7 ms 608 KB Output is correct
9 Correct 7 ms 608 KB Output is correct
10 Correct 7 ms 608 KB Output is correct
11 Correct 7 ms 620 KB Output is correct
12 Correct 7 ms 620 KB Output is correct
13 Correct 7 ms 620 KB Output is correct
14 Correct 7 ms 620 KB Output is correct
15 Correct 8 ms 620 KB Output is correct
16 Correct 3 ms 620 KB Output is correct
17 Correct 3 ms 620 KB Output is correct
18 Correct 3 ms 620 KB Output is correct
19 Correct 3 ms 620 KB Output is correct
20 Correct 3 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 248 KB Output is correct
2 Correct 8 ms 352 KB Output is correct
3 Correct 10 ms 428 KB Output is correct
4 Correct 8 ms 496 KB Output is correct
5 Correct 9 ms 608 KB Output is correct
6 Correct 7 ms 608 KB Output is correct
7 Correct 7 ms 608 KB Output is correct
8 Correct 7 ms 608 KB Output is correct
9 Correct 7 ms 608 KB Output is correct
10 Correct 7 ms 608 KB Output is correct
11 Correct 7 ms 620 KB Output is correct
12 Correct 7 ms 620 KB Output is correct
13 Correct 7 ms 620 KB Output is correct
14 Correct 7 ms 620 KB Output is correct
15 Correct 8 ms 620 KB Output is correct
16 Correct 3 ms 620 KB Output is correct
17 Correct 3 ms 620 KB Output is correct
18 Correct 3 ms 620 KB Output is correct
19 Correct 3 ms 620 KB Output is correct
20 Correct 3 ms 620 KB Output is correct
21 Correct 96 ms 752 KB Output is correct
22 Correct 94 ms 752 KB Output is correct
23 Correct 80 ms 752 KB Output is correct
24 Correct 91 ms 752 KB Output is correct
25 Correct 93 ms 916 KB Output is correct
26 Correct 199 ms 916 KB Output is correct
27 Correct 204 ms 916 KB Output is correct
28 Correct 200 ms 916 KB Output is correct
29 Correct 199 ms 916 KB Output is correct
30 Correct 9 ms 916 KB Output is correct
31 Correct 9 ms 916 KB Output is correct
32 Correct 9 ms 980 KB Output is correct
33 Correct 9 ms 980 KB Output is correct
34 Correct 9 ms 1004 KB Output is correct
35 Correct 8 ms 1012 KB Output is correct
36 Correct 8 ms 1012 KB Output is correct
37 Correct 8 ms 1012 KB Output is correct
38 Correct 8 ms 1012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1012 KB Output is correct
2 Correct 2 ms 1012 KB Output is correct
3 Correct 2 ms 1012 KB Output is correct
4 Correct 2 ms 1012 KB Output is correct
5 Correct 3 ms 1012 KB Output is correct
6 Correct 4 ms 1012 KB Output is correct
7 Correct 3 ms 1012 KB Output is correct
8 Correct 3 ms 1012 KB Output is correct
9 Correct 3 ms 1012 KB Output is correct
10 Correct 4 ms 1012 KB Output is correct
11 Correct 3 ms 1012 KB Output is correct
12 Correct 2 ms 1012 KB Output is correct
13 Correct 2 ms 1080 KB Output is correct
14 Correct 2 ms 1080 KB Output is correct
15 Correct 3 ms 1080 KB Output is correct
16 Correct 2 ms 1080 KB Output is correct
17 Correct 2 ms 1080 KB Output is correct
18 Correct 2 ms 1080 KB Output is correct
19 Correct 2 ms 1080 KB Output is correct
20 Correct 3 ms 1080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 248 KB Output is correct
2 Correct 8 ms 352 KB Output is correct
3 Correct 10 ms 428 KB Output is correct
4 Correct 8 ms 496 KB Output is correct
5 Correct 9 ms 608 KB Output is correct
6 Correct 7 ms 608 KB Output is correct
7 Correct 7 ms 608 KB Output is correct
8 Correct 7 ms 608 KB Output is correct
9 Correct 7 ms 608 KB Output is correct
10 Correct 7 ms 608 KB Output is correct
11 Correct 7 ms 620 KB Output is correct
12 Correct 7 ms 620 KB Output is correct
13 Correct 7 ms 620 KB Output is correct
14 Correct 7 ms 620 KB Output is correct
15 Correct 8 ms 620 KB Output is correct
16 Correct 3 ms 620 KB Output is correct
17 Correct 3 ms 620 KB Output is correct
18 Correct 3 ms 620 KB Output is correct
19 Correct 3 ms 620 KB Output is correct
20 Correct 3 ms 620 KB Output is correct
21 Correct 96 ms 752 KB Output is correct
22 Correct 94 ms 752 KB Output is correct
23 Correct 80 ms 752 KB Output is correct
24 Correct 91 ms 752 KB Output is correct
25 Correct 93 ms 916 KB Output is correct
26 Correct 199 ms 916 KB Output is correct
27 Correct 204 ms 916 KB Output is correct
28 Correct 200 ms 916 KB Output is correct
29 Correct 199 ms 916 KB Output is correct
30 Correct 9 ms 916 KB Output is correct
31 Correct 9 ms 916 KB Output is correct
32 Correct 9 ms 980 KB Output is correct
33 Correct 9 ms 980 KB Output is correct
34 Correct 9 ms 1004 KB Output is correct
35 Correct 8 ms 1012 KB Output is correct
36 Correct 8 ms 1012 KB Output is correct
37 Correct 8 ms 1012 KB Output is correct
38 Correct 8 ms 1012 KB Output is correct
39 Correct 3 ms 1012 KB Output is correct
40 Correct 2 ms 1012 KB Output is correct
41 Correct 2 ms 1012 KB Output is correct
42 Correct 2 ms 1012 KB Output is correct
43 Correct 3 ms 1012 KB Output is correct
44 Correct 4 ms 1012 KB Output is correct
45 Correct 3 ms 1012 KB Output is correct
46 Correct 3 ms 1012 KB Output is correct
47 Correct 3 ms 1012 KB Output is correct
48 Correct 4 ms 1012 KB Output is correct
49 Correct 3 ms 1012 KB Output is correct
50 Correct 2 ms 1012 KB Output is correct
51 Correct 2 ms 1080 KB Output is correct
52 Correct 2 ms 1080 KB Output is correct
53 Correct 3 ms 1080 KB Output is correct
54 Correct 2 ms 1080 KB Output is correct
55 Correct 2 ms 1080 KB Output is correct
56 Correct 2 ms 1080 KB Output is correct
57 Correct 2 ms 1080 KB Output is correct
58 Correct 3 ms 1080 KB Output is correct
59 Correct 102 ms 1080 KB Output is correct
60 Correct 93 ms 1096 KB Output is correct
61 Correct 89 ms 1096 KB Output is correct
62 Correct 105 ms 1096 KB Output is correct
63 Correct 98 ms 1096 KB Output is correct
64 Correct 229 ms 1144 KB Output is correct
65 Correct 229 ms 1144 KB Output is correct
66 Correct 230 ms 1144 KB Output is correct
67 Correct 230 ms 1144 KB Output is correct
68 Correct 229 ms 1192 KB Output is correct
69 Correct 89 ms 1204 KB Output is correct
70 Correct 90 ms 1204 KB Output is correct
71 Correct 91 ms 1204 KB Output is correct
72 Correct 98 ms 1204 KB Output is correct
73 Correct 99 ms 1204 KB Output is correct
74 Correct 21 ms 1204 KB Output is correct
75 Correct 20 ms 1204 KB Output is correct
76 Correct 21 ms 1204 KB Output is correct
77 Correct 21 ms 1204 KB Output is correct
78 Correct 22 ms 1204 KB Output is correct