답안 #970330

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
970330 2024-04-26T11:12:06 Z duckindog Boat (APIO16_boat) C++17
100 / 100
486 ms 2648 KB
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 500 + 10,
          M = 1'000'000'007;
int n;
int a[N], b[N];

int f[1'010][N];
void add(auto& x, const auto& y) { 
  x += y;
  if (x >= M) x -= M;
}

int powder(int a, int b) { 
  int ret = 1;
  while (b) { 
    if (b & 1) ret = 1ll * ret * a % M;
    a = 1ll * a * a % M;
    b >>= 1;
  }
  return ret;
}

int inv[N];

int32_t main() { 
  cin.tie(0)->sync_with_stdio(0);
 
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i] >> b[i];

  for (int i = 2; i <= n + 1; ++i) inv[i] = powder(i, M - 2);

  vector<int> rrh(a + 1, a + n + 1);
  for (int i = 1; i <= n; ++i) rrh.push_back(b[i] + 1);
  sort(rrh.begin(), rrh.end());
  rrh.resize(unique(rrh.begin(), rrh.end()) - rrh.begin());
  
  for (int i = 0; i < rrh.size(); ++i) f[i][0] = 1;
  for (int i = 1; i < rrh.size(); ++i) { 
    for (int j = 1; j <= n; ++j) { 
      auto& ret = f[i][j];
      ret = f[i - 1][j];
      if (a[j] > rrh[i - 1] || rrh[i - 1] > b[j]) continue;
      
      int len = rrh[i] - rrh[i - 1];
      int mul = len, cnt = 1;

      for (int t = j - 1; t >= 0; --t) {
        add(ret, 1ll * f[i - 1][t] * mul % M);
        if (a[t] <= rrh[i - 1] && rrh[i - 1] <= b[t]) { 
          mul = 1ll * mul * (len + cnt) % M * inv[cnt + 1] % M;
          cnt += 1;
        }
      }
    }
  }
  
  int answer = 0;
  for (int i = 1; i <= n; ++i) add(answer, f[rrh.size() - 1][i]);

  cout << answer << "\n";
}

Compilation message

boat.cpp:11:10: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   11 | void add(auto& x, const auto& y) {
      |          ^~~~
boat.cpp:11:25: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   11 | void add(auto& x, const auto& y) {
      |                         ^~~~
boat.cpp: In function 'int32_t main()':
boat.cpp:41:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |   for (int i = 0; i < rrh.size(); ++i) f[i][0] = 1;
      |                   ~~^~~~~~~~~~~~
boat.cpp:42:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |   for (int i = 1; i < rrh.size(); ++i) {
      |                   ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 3 ms 2396 KB Output is correct
4 Correct 3 ms 2396 KB Output is correct
5 Correct 2 ms 2396 KB Output is correct
6 Correct 2 ms 2396 KB Output is correct
7 Correct 2 ms 2396 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 2 ms 2396 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 2 ms 2648 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 2 ms 2396 KB Output is correct
14 Correct 2 ms 2396 KB Output is correct
15 Correct 2 ms 2396 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 852 KB Output is correct
20 Correct 2 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 3 ms 2396 KB Output is correct
4 Correct 3 ms 2396 KB Output is correct
5 Correct 2 ms 2396 KB Output is correct
6 Correct 2 ms 2396 KB Output is correct
7 Correct 2 ms 2396 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 2 ms 2396 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 2 ms 2648 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 2 ms 2396 KB Output is correct
14 Correct 2 ms 2396 KB Output is correct
15 Correct 2 ms 2396 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 852 KB Output is correct
20 Correct 2 ms 600 KB Output is correct
21 Correct 214 ms 2268 KB Output is correct
22 Correct 216 ms 2300 KB Output is correct
23 Correct 188 ms 2264 KB Output is correct
24 Correct 202 ms 2248 KB Output is correct
25 Correct 206 ms 2260 KB Output is correct
26 Correct 416 ms 2216 KB Output is correct
27 Correct 428 ms 2384 KB Output is correct
28 Correct 417 ms 2140 KB Output is correct
29 Correct 412 ms 2140 KB Output is correct
30 Correct 3 ms 2396 KB Output is correct
31 Correct 3 ms 2396 KB Output is correct
32 Correct 3 ms 2396 KB Output is correct
33 Correct 3 ms 2396 KB Output is correct
34 Correct 3 ms 2392 KB Output is correct
35 Correct 3 ms 2396 KB Output is correct
36 Correct 4 ms 2396 KB Output is correct
37 Correct 3 ms 2392 KB Output is correct
38 Correct 3 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 860 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 3 ms 860 KB Output is correct
6 Correct 4 ms 860 KB Output is correct
7 Correct 4 ms 860 KB Output is correct
8 Correct 4 ms 860 KB Output is correct
9 Correct 4 ms 860 KB Output is correct
10 Correct 4 ms 860 KB Output is correct
11 Correct 3 ms 860 KB Output is correct
12 Correct 2 ms 1116 KB Output is correct
13 Correct 2 ms 860 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 2 ms 856 KB Output is correct
20 Correct 2 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 3 ms 2396 KB Output is correct
4 Correct 3 ms 2396 KB Output is correct
5 Correct 2 ms 2396 KB Output is correct
6 Correct 2 ms 2396 KB Output is correct
7 Correct 2 ms 2396 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 2 ms 2396 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 2 ms 2648 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 2 ms 2396 KB Output is correct
14 Correct 2 ms 2396 KB Output is correct
15 Correct 2 ms 2396 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 852 KB Output is correct
20 Correct 2 ms 600 KB Output is correct
21 Correct 214 ms 2268 KB Output is correct
22 Correct 216 ms 2300 KB Output is correct
23 Correct 188 ms 2264 KB Output is correct
24 Correct 202 ms 2248 KB Output is correct
25 Correct 206 ms 2260 KB Output is correct
26 Correct 416 ms 2216 KB Output is correct
27 Correct 428 ms 2384 KB Output is correct
28 Correct 417 ms 2140 KB Output is correct
29 Correct 412 ms 2140 KB Output is correct
30 Correct 3 ms 2396 KB Output is correct
31 Correct 3 ms 2396 KB Output is correct
32 Correct 3 ms 2396 KB Output is correct
33 Correct 3 ms 2396 KB Output is correct
34 Correct 3 ms 2392 KB Output is correct
35 Correct 3 ms 2396 KB Output is correct
36 Correct 4 ms 2396 KB Output is correct
37 Correct 3 ms 2392 KB Output is correct
38 Correct 3 ms 2396 KB Output is correct
39 Correct 2 ms 860 KB Output is correct
40 Correct 2 ms 860 KB Output is correct
41 Correct 2 ms 860 KB Output is correct
42 Correct 2 ms 860 KB Output is correct
43 Correct 3 ms 860 KB Output is correct
44 Correct 4 ms 860 KB Output is correct
45 Correct 4 ms 860 KB Output is correct
46 Correct 4 ms 860 KB Output is correct
47 Correct 4 ms 860 KB Output is correct
48 Correct 4 ms 860 KB Output is correct
49 Correct 3 ms 860 KB Output is correct
50 Correct 2 ms 1116 KB Output is correct
51 Correct 2 ms 860 KB Output is correct
52 Correct 2 ms 860 KB Output is correct
53 Correct 2 ms 860 KB Output is correct
54 Correct 2 ms 604 KB Output is correct
55 Correct 2 ms 604 KB Output is correct
56 Correct 2 ms 604 KB Output is correct
57 Correct 2 ms 856 KB Output is correct
58 Correct 2 ms 600 KB Output is correct
59 Correct 240 ms 2460 KB Output is correct
60 Correct 230 ms 2452 KB Output is correct
61 Correct 207 ms 2396 KB Output is correct
62 Correct 231 ms 2396 KB Output is correct
63 Correct 225 ms 2456 KB Output is correct
64 Correct 479 ms 2452 KB Output is correct
65 Correct 486 ms 2456 KB Output is correct
66 Correct 480 ms 2460 KB Output is correct
67 Correct 481 ms 2456 KB Output is correct
68 Correct 479 ms 2396 KB Output is correct
69 Correct 205 ms 2456 KB Output is correct
70 Correct 192 ms 2392 KB Output is correct
71 Correct 188 ms 2456 KB Output is correct
72 Correct 200 ms 2396 KB Output is correct
73 Correct 207 ms 2452 KB Output is correct
74 Correct 47 ms 820 KB Output is correct
75 Correct 43 ms 604 KB Output is correct
76 Correct 47 ms 604 KB Output is correct
77 Correct 46 ms 600 KB Output is correct
78 Correct 46 ms 820 KB Output is correct