답안 #970328

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
970328 2024-04-26T11:10:25 Z duckindog Boat (APIO16_boat) C++17
36 / 100
2000 ms 2472 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;
}

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

  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 * powder(cnt + 1, M - 2) % 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:37:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |   for (int i = 0; i < rrh.size(); ++i) f[i][0] = 1;
      |                   ~~^~~~~~~~~~~~
boat.cpp:38:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |   for (int i = 1; i < rrh.size(); ++i) {
      |                   ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Correct 3 ms 2396 KB Output is correct
3 Correct 3 ms 2392 KB Output is correct
4 Correct 3 ms 2408 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 3 ms 2392 KB Output is correct
9 Correct 2 ms 2396 KB Output is correct
10 Correct 3 ms 2392 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 3 ms 2396 KB Output is correct
14 Correct 3 ms 2396 KB Output is correct
15 Correct 2 ms 2472 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 2 ms 728 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Correct 3 ms 2396 KB Output is correct
3 Correct 3 ms 2392 KB Output is correct
4 Correct 3 ms 2408 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 3 ms 2392 KB Output is correct
9 Correct 2 ms 2396 KB Output is correct
10 Correct 3 ms 2392 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 3 ms 2396 KB Output is correct
14 Correct 3 ms 2396 KB Output is correct
15 Correct 2 ms 2472 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 2 ms 728 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Execution timed out 2054 ms 2140 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 860 KB Output is correct
2 Correct 14 ms 860 KB Output is correct
3 Correct 19 ms 860 KB Output is correct
4 Correct 20 ms 860 KB Output is correct
5 Correct 23 ms 604 KB Output is correct
6 Correct 48 ms 856 KB Output is correct
7 Correct 48 ms 600 KB Output is correct
8 Correct 49 ms 852 KB Output is correct
9 Correct 47 ms 600 KB Output is correct
10 Correct 48 ms 860 KB Output is correct
11 Correct 23 ms 860 KB Output is correct
12 Correct 15 ms 860 KB Output is correct
13 Correct 20 ms 600 KB Output is correct
14 Correct 19 ms 856 KB Output is correct
15 Correct 22 ms 860 KB Output is correct
16 Correct 14 ms 604 KB Output is correct
17 Correct 11 ms 692 KB Output is correct
18 Correct 12 ms 692 KB Output is correct
19 Correct 11 ms 692 KB Output is correct
20 Correct 14 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Correct 3 ms 2396 KB Output is correct
3 Correct 3 ms 2392 KB Output is correct
4 Correct 3 ms 2408 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 3 ms 2392 KB Output is correct
9 Correct 2 ms 2396 KB Output is correct
10 Correct 3 ms 2392 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 3 ms 2396 KB Output is correct
14 Correct 3 ms 2396 KB Output is correct
15 Correct 2 ms 2472 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 2 ms 728 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Execution timed out 2054 ms 2140 KB Time limit exceeded
22 Halted 0 ms 0 KB -