結果

問題 No.801 エレベーター
ユーザー MayimgMayimg
提出日時 2019-03-18 00:39:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 992 bytes
コンパイル時間 2,195 ms
コンパイル使用メモリ 202,968 KB
実行使用メモリ 38,652 KB
最終ジャッジ日時 2023-09-22 16:17:14
合計ジャッジ時間 4,790 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 103 ms
38,400 KB
testcase_14 AC 103 ms
38,468 KB
testcase_15 AC 103 ms
38,204 KB
testcase_16 AC 104 ms
38,100 KB
testcase_17 AC 104 ms
38,148 KB
testcase_18 AC 103 ms
38,180 KB
testcase_19 AC 102 ms
38,652 KB
testcase_20 AC 103 ms
38,084 KB
testcase_21 AC 103 ms
38,404 KB
testcase_22 AC 103 ms
38,480 KB
testcase_23 AC 97 ms
38,152 KB
testcase_24 AC 96 ms
38,136 KB
testcase_25 AC 97 ms
38,180 KB
testcase_26 AC 97 ms
38,428 KB
testcase_27 AC 96 ms
38,088 KB
testcase_28 AC 102 ms
38,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
inline void add(int &x, int y) {
  x += y;
  if (x >= mod) x -= mod;
}
inline void sub(int &x, int y) {
  x -= y;
  if (x < 0) x += mod;
}
inline int subb(int x, int y) {
  x -= y;
  if (x < 0) x += mod;
  return x;
}
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> l(m), r(m);
  for (int i = 0; i < m; i++) {
    cin >> l[i] >> r[i];
  }
  vector<vector<int>> dp(k + 1, vector<int>(n + 2));
  dp[0][1] = 1; dp[0][2] = -1;
  for (int i = 0; i <= k; i++) {
    for (int j = 1; j <= n; j++) {
      add(dp[i][j], dp[i][j - 1]);
    }
    if (i == k) break;
    for (int j = 1; j <= n; j++) {
      add(dp[i][j], dp[i][j - 1]);
    }
    for (int j = 0; j < m; j++) {
      int x = subb(dp[i][r[j]], dp[i][l[j] - 1]);
      add(dp[i + 1][l[j]], x);
      sub(dp[i + 1][r[j] + 1], x);
    }
  } 
  cout << dp[k][n] << endl;
  return 0;
}
0