結果

問題 No.801 エレベーター
ユーザー emthrmemthrm
提出日時 2019-03-17 22:47:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 539 ms / 2,000 ms
コード長 2,975 bytes
コンパイル時間 1,685 ms
コンパイル使用メモリ 132,836 KB
実行使用メモリ 74,056 KB
最終ジャッジ日時 2023-09-22 08:57:38
合計ジャッジ時間 11,067 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 6 ms
4,380 KB
testcase_04 AC 6 ms
4,380 KB
testcase_05 AC 6 ms
4,380 KB
testcase_06 AC 6 ms
4,376 KB
testcase_07 AC 7 ms
4,380 KB
testcase_08 AC 6 ms
4,376 KB
testcase_09 AC 6 ms
4,380 KB
testcase_10 AC 6 ms
4,376 KB
testcase_11 AC 6 ms
4,384 KB
testcase_12 AC 6 ms
4,376 KB
testcase_13 AC 532 ms
73,992 KB
testcase_14 AC 533 ms
73,996 KB
testcase_15 AC 537 ms
73,704 KB
testcase_16 AC 535 ms
73,972 KB
testcase_17 AC 534 ms
73,724 KB
testcase_18 AC 535 ms
73,724 KB
testcase_19 AC 535 ms
73,792 KB
testcase_20 AC 535 ms
73,720 KB
testcase_21 AC 539 ms
74,056 KB
testcase_22 AC 539 ms
73,760 KB
testcase_23 AC 490 ms
73,724 KB
testcase_24 AC 491 ms
73,456 KB
testcase_25 AC 491 ms
73,772 KB
testcase_26 AC 496 ms
73,780 KB
testcase_27 AC 491 ms
73,780 KB
testcase_28 AC 390 ms
74,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f, MOD = 1000000007;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*-----------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, m, k; cin >> n >> m >> k;
  vector<int> l(m), r(m); REP(i, m) cin >> l[i] >> r[i];
  vector<vector<int> > shita(n + 1), ue(n + 1);
  REP(i, m) {
    shita[l[i]].emplace_back(i);
    if (r[i] + 1 <= n) ue[r[i] + 1].emplace_back(i);
  }
  vector<vector<int> > up(n + 1), down(n + 1);
  REP(i, m) {
    up[r[i]].emplace_back(i);
    down[l[i] - 1].emplace_back(i);
  }
  vector<vector<long long> > dp(k + 1, vector<long long>(n + 1, 0));
  dp[0][1] = 1;
  REP(i, k) {
    vector<long long> cum(n + 1, 0);
    FOR(j, 1, n + 1) (cum[j] += (cum[j - 1] + dp[i][j]) % MOD) %= MOD;
    int cnt = 0;
    long long tmp = 0;
    FOR(j, 1, n + 1) {
      cnt += shita[j].size() - ue[j].size();
      (tmp += dp[i][j] * cnt % MOD) %= MOD;
      // cout << i + 1 << ' ' << j << " | " << shita[j].size() << '\n';
      for (int e : ue[j]) {
        tmp -= (cum[r[e]] - cum[l[e] - 1]) % MOD;
        (tmp += MOD) %= MOD;
      }
      (dp[i + 1][j] += tmp) %= MOD;
      // cout << i + 1 << ' ' << j << " : " << dp[i + 1][j] << '\n';
    }
    vector<long long> muc(n + 1, 0);
    muc[n] = dp[i][n];
    for (int j = n - 1; j > 0; --j) (muc[j] += (muc[j + 1] + dp[i][j]) % MOD) %= MOD;
    cnt = 0;
    tmp = 0;
    for (int j = n; j > 0; --j) {
      cnt += up[j].size() - down[j].size();
      (tmp += dp[i][j] * cnt % MOD) %= MOD;
      for (int e : down[j]) {
        tmp -= (muc[l[e]] - (r[e] + 1 <= n ? muc[r[e] + 1] : 0)) % MOD;
        (tmp += MOD) %= MOD;
      }
      (dp[i + 1][j] += tmp) %= MOD;
    }
    cnt = 0;
    FOR(j, 1, n + 1) {
      cnt += shita[j].size() - ue[j].size();
      dp[i + 1][j] -= dp[i][j] * cnt % MOD;
      (dp[i + 1][j] += MOD) %= MOD;
    }
  }
  cout << dp[k][n] << '\n';
  return 0;

  // vector<vector<long long> > to(n + 1, vector<long long>(n + 1, 0));
  // FOR(i, 1, n + 1) FOR(j, 1, n + 1) {

  // }
  // vector<vector<long long> > dp(k + 1, vector<long long>(n + 1, 0));
  // dp[0][1] = 1;
  // REP(i, k) FOR(j, 1, n + 1) {
  //   REP(x, m) if (l[x] <= j && j <= r[x]) {
  //     FOR(y, l[x], r[x] + 1) (dp[i + 1][y] += dp[i][j]) %= MOD;
  //   }
  // }
  // cout << dp[k][n] << '\n';
  return 0;
}
0