結果
問題 |
No.645 Count Permutation
|
ユーザー |
![]() |
提出日時 | 2025-01-27 22:37:04 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 880 bytes |
コンパイル時間 | 1,547 ms |
コンパイル使用メモリ | 160,556 KB |
実行使用メモリ | 20,992 KB |
最終ジャッジ日時 | 2025-01-27 22:37:13 |
合計ジャッジ時間 | 7,467 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 7 WA * 3 RE * 24 |
コンパイルメッセージ
main.cpp: In function ‘int main(int, const char**)’: main.cpp:22:29: warning: iteration 63 invokes undefined behavior [-Waggressive-loop-optimizations] 22 | (dp[j + 1][i] += dp[j][i + 1]) %= mod; | ~~~~~~~~~~~^ main.cpp:18:27: note: within this loop 18 | for (int j = 0; j < LG; j++) | ~~^~~~
ソースコード
#include <bits/stdc++.h> using namespace std; #define endl '\n' typedef long long ll; const int mod = 1e9 + 7; const int N = 1e5 + 10; const int LG = 64; ll n, l, r; ll dp[LG][N]; int main(int argc, char const *argv[]) { ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); cin >> n >> l >> r; dp[0][n] = 1; for (int i = n - 1; i >= 1; i--) { for (int j = 0; j < LG; j++) { (dp[j][i] += dp[j][i + 1] * (n - 1 - i)) %= mod; if (j < LG) (dp[j + 1][i] += dp[j][i + 1]) %= mod; } } ll c0 = n - 1; for (int i = 1; i <= n - 1; i++) (c0 *= i) %= mod; ll ans = (l ? 0 : c0); for (int i = 1; i < LG; i++) { if ((1ll << i) < l || r < (1ll << i)) continue; (ans += dp[i][1]) %= mod; } cout << ans << endl; return 0; }