結果

問題 No.645 Count Permutation
ユーザー pekempeypekempey
提出日時 2018-02-02 23:10:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,259 bytes
コンパイル時間 1,129 ms
コンパイル使用メモリ 78,884 KB
実行使用メモリ 30,508 KB
最終ジャッジ日時 2023-08-30 02:26:55
合計ジャッジ時間 2,768 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 WA -
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 6 ms
5,748 KB
testcase_12 AC 4 ms
4,912 KB
testcase_13 AC 6 ms
5,664 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 WA -
testcase_16 AC 20 ms
13,396 KB
testcase_17 AC 48 ms
29,132 KB
testcase_18 AC 17 ms
11,716 KB
testcase_19 AC 50 ms
30,432 KB
testcase_20 AC 50 ms
30,456 KB
testcase_21 WA -
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 WA -
testcase_25 AC 27 ms
17,556 KB
testcase_26 AC 41 ms
25,724 KB
testcase_27 AC 23 ms
15,200 KB
testcase_28 AC 17 ms
11,448 KB
testcase_29 AC 39 ms
23,960 KB
testcase_30 AC 39 ms
24,096 KB
testcase_31 AC 42 ms
25,968 KB
testcase_32 AC 14 ms
9,880 KB
testcase_33 AC 14 ms
9,860 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

const int mod = 1e9 + 7;

struct Modint {
  int n;
  Modint(int n = 0) : n(n) {}
};

Modint operator+(Modint a, Modint b) { return Modint((a.n += b.n) >= mod ? a.n - mod : a.n); }
Modint operator-(Modint a, Modint b) { return Modint((a.n -= b.n) < 0 ? a.n + mod : a.n); }
Modint operator*(Modint a, Modint b) { return Modint(1LL * a.n * b.n % mod); }
Modint &operator+=(Modint &a, Modint b) { return a = a + b; }
Modint &operator-=(Modint &a, Modint b) { return a = a - b; }
Modint &operator*=(Modint &a, Modint b) { return a = a * b; }

int main() {
  int n;
  long long L, R;
  cin >> n >> L >> R;

  vector<vector<Modint>> dp(n + 1, vector<Modint>(62));

  Modint bad;

  dp[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= 60; j++) {
      // update
      dp[i + 1][j + 1] += dp[i][j];

      // keep
      if (i != n - 1) {
        dp[i + 1][j] += dp[i][j] * i;
      } else {
        bad += dp[i][j] * i;
      }
    }
  }

  Modint ans;

  if (L == 0) {
    ans += bad;
  }

  for (int i = 1; i <= 61; i++) {
    long long way = 1LL << (i - 1);
    if (L <= way && way <= R) {
      ans += dp[n][i];
    }
  }
  cout << ans.n << endl;
}
0