結果

問題 No.645 Count Permutation
ユーザー pekempeypekempey
提出日時 2018-02-02 23:14:21
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,268 bytes
コンパイル時間 1,217 ms
コンパイル使用メモリ 79,372 KB
実行使用メモリ 31,876 KB
最終ジャッジ日時 2023-08-30 02:27:48
合計ジャッジ時間 2,837 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 7 ms
6,016 KB
testcase_12 AC 5 ms
5,060 KB
testcase_13 AC 6 ms
5,752 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 29 ms
16,340 KB
testcase_16 AC 24 ms
14,200 KB
testcase_17 AC 57 ms
30,688 KB
testcase_18 AC 19 ms
12,232 KB
testcase_19 AC 59 ms
31,776 KB
testcase_20 AC 58 ms
31,848 KB
testcase_21 AC 47 ms
25,880 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 58 ms
31,876 KB
testcase_25 AC 32 ms
18,312 KB
testcase_26 AC 49 ms
27,168 KB
testcase_27 AC 27 ms
16,008 KB
testcase_28 AC 19 ms
11,704 KB
testcase_29 AC 45 ms
25,080 KB
testcase_30 AC 47 ms
25,176 KB
testcase_31 AC 52 ms
27,336 KB
testcase_32 AC 17 ms
10,428 KB
testcase_33 AC 16 ms
10,228 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>(63));

  Modint bad;

  dp[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= 62; j++) {
      // update
      dp[i + 1][min(61, 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