結果
問題 | No.645 Count Permutation |
ユーザー | milanis48663220 |
提出日時 | 2023-09-09 20:40:44 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 94 ms / 2,000 ms |
コード長 | 2,462 bytes |
コンパイル時間 | 1,525 ms |
コンパイル使用メモリ | 134,904 KB |
実行使用メモリ | 32,112 KB |
最終ジャッジ日時 | 2023-09-09 20:40:53 |
合計ジャッジ時間 | 4,233 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 1 ms
4,376 KB |
testcase_02 | AC | 3 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | AC | 2 ms
4,380 KB |
testcase_05 | AC | 2 ms
4,380 KB |
testcase_06 | AC | 1 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,376 KB |
testcase_10 | AC | 2 ms
4,380 KB |
testcase_11 | AC | 10 ms
5,884 KB |
testcase_12 | AC | 7 ms
5,052 KB |
testcase_13 | AC | 9 ms
5,752 KB |
testcase_14 | AC | 3 ms
4,376 KB |
testcase_15 | AC | 43 ms
16,180 KB |
testcase_16 | AC | 35 ms
14,144 KB |
testcase_17 | AC | 88 ms
30,612 KB |
testcase_18 | AC | 29 ms
12,444 KB |
testcase_19 | AC | 92 ms
32,112 KB |
testcase_20 | AC | 94 ms
31,772 KB |
testcase_21 | AC | 72 ms
25,892 KB |
testcase_22 | AC | 2 ms
4,380 KB |
testcase_23 | AC | 2 ms
4,376 KB |
testcase_24 | AC | 92 ms
32,108 KB |
testcase_25 | AC | 50 ms
18,372 KB |
testcase_26 | AC | 76 ms
27,028 KB |
testcase_27 | AC | 42 ms
15,856 KB |
testcase_28 | AC | 29 ms
12,032 KB |
testcase_29 | AC | 70 ms
24,888 KB |
testcase_30 | AC | 71 ms
25,572 KB |
testcase_31 | AC | 77 ms
27,356 KB |
testcase_32 | AC | 24 ms
10,044 KB |
testcase_33 | AC | 24 ms
10,120 KB |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <cmath> #include <numeric> #include <functional> #include <cassert> #include <atcoder/modint> #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template<typename T> vector<vector<T>> vec2d(int n, int m, T v){ return vector<vector<T>>(n, vector<T>(m, v)); } template<typename T> vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){ return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v))); } template<typename T> void print_vector(vector<T> v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } void test(int n){ vector<int> p(n); iota(p.begin(), p.end(), 0); map<vector<int>, int> cnt; do{ auto q = p; for(int i = 0; i < n-1; i++){ if(q[i] > q[i+1]){ swap(q[i], q[i+1]); } } if(cnt.count(q)){ cnt[q]++; }else{ cnt[q] = 1; } }while(next_permutation(p.begin(), p.end())); for(auto [q, c]: cnt){ print_vector(q); cout << c << endl; } } using mint = atcoder::modint1000000007; ostream& operator<<(ostream& os, const mint& m){ os << m.val(); return os; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n; ll l, r; cin >> n >> l >> r; auto dp = vec2d(n+1, 63, mint(0)); dp[0][0] = 1; for(int i = 0; i < n; i++){ for(int j = 0; j < 62; j++){ if(i+1 != n) dp[i+1][j] += dp[i][j]*i; dp[i+1][j+1] += dp[i][j]; } } mint ans = 0; for(int x = 1; x < 62; x++){ ll c = 1ll<<(x-1); if(l <= c && c <= r) ans += dp[n][x]; } if(l == 0){ mint f = n-1; for(int x = 1; x <= n-1; x++) f *= x; ans += f; } cout << ans << endl; }