답안 #967732

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
967732 2024-04-22T17:20:55 Z duckindog Boat (APIO16_boat) C++17
0 / 100
509 ms 524288 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 500 + 10,
          M = 1'000'000'000 + 7;
int n;
int a[N], b[N];
int f[2][1'000'000 + 10];

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;
  for (int i = 1; i <= n; ++i) {
    for (int j = a[i]; j <= b[i]; ++j) rrh.push_back(j);
  }

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

  f[0][0] = 1;
  for (int j = 1; j <= rrh.size(); ++j) f[0][j] = 1;

  for (int i = 1; i <= n; ++i) { 
    int id = i & 1, p = id ^ 1;
    for (int j = 0; j <= rrh.size(); ++j) f[id][j] = 0;
    
    int it = lower_bound(rrh.begin(), rrh.end(), a[i]) - rrh.begin() + 1;
    
    for (int j = 0; j <= rrh.size(); ++j) f[id][j] = f[p][j];
    for (int j = it; j <= b[i] - a[i] + it; ++j) f[id][j] = (f[p][j - 1] + f[id][j]) % M;
    for (int j = 1; j <= rrh.size(); ++j) {
      f[id][j] = (f[id][j] + f[id][j - 1] - f[p][j - 1] + M) % M;
    }
  }

  cout << f[n & 1][rrh.size()] - 1 << "\n";
}

Compilation message

boat.cpp: In function 'int32_t main()':
boat.cpp:26:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |   for (int j = 1; j <= rrh.size(); ++j) f[0][j] = 1;
      |                   ~~^~~~~~~~~~~~~
boat.cpp:30:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for (int j = 0; j <= rrh.size(); ++j) f[id][j] = 0;
      |                     ~~^~~~~~~~~~~~~
boat.cpp:34:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for (int j = 0; j <= rrh.size(); ++j) f[id][j] = f[p][j];
      |                     ~~^~~~~~~~~~~~~
boat.cpp:36:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for (int j = 1; j <= rrh.size(); ++j) {
      |                     ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 509 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -