結果
問題 | No.737 PopCount |
ユーザー | 0x19f |
提出日時 | 2018-09-28 23:02:30 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 1,000 ms |
コード長 | 1,823 bytes |
コンパイル時間 | 1,968 ms |
コンパイル使用メモリ | 183,980 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-12 07:12:59 |
合計ジャッジ時間 | 2,763 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 15 |
ソースコード
#include <bits/stdc++.h> #define REP(i, a, n) for (ll i = ((ll) a); i < ((ll) n); i++) using namespace std; typedef long long ll; const ll MOD = 1000000007; int main(void) { ll N; cin >> N; vector<ll> S; for (ll n = N; n > 0; n /= 2) S.push_back(n % 2); reverse(S.begin(), S.end()); { ll x = 0; REP(i, 0, S.size()) x = x * 2 + S[i]; assert(x == N); } #define update(x, y, c, d) (((x) = (((x) + ((y) * 2 % MOD)) % MOD + ((c) * (d)) % MOD) % MOD)) % MOD vector<vector<vector<ll>>> dp(S.size() + 1, vector<vector<ll>>(S.size() + 1, vector<ll>(2, 0))); vector<vector<vector<ll>>> cnt(S.size() + 1, vector<vector<ll>>(S.size() + 1, vector<ll>(2, 0))); vector<vector<vector<bool>>> ok(S.size() + 1, vector<vector<bool>>(S.size() + 1, vector<bool>(2, false))); cnt[0][0][1] = 1; ok[0][0][1] = true; REP(i, 0, S.size()) REP(j, 0, S.size() + 1) { if (ok[i][j][0]) { update(dp[i + 1][j][0], dp[i][j][0], cnt[i][j][0], 0); cnt[i + 1][j][0] += cnt[i][j][0]; ok[i + 1][j][0] = true; } if (ok[i][j][0] && j + 1 <= S.size()) { update(dp[i + 1][j + 1][0], dp[i][j][0], cnt[i][j][0], 1); cnt[i + 1][j + 1][0] += cnt[i][j][0]; ok[i + 1][j + 1][0] = true; } if (ok[i][j][1]) { update(dp[i + 1][j][S[i] == 0], dp[i][j][1], cnt[i][j][1], 0); cnt[i + 1][j][S[i] == 0] += cnt[i][j][1]; ok[i + 1][j][S[i] == 0] = true; } if (ok[i][j][1] && j + 1 <= S.size() && S[i] == 1) { update(dp[i + 1][j + 1][1], dp[i][j][1], cnt[i][j][1], 1); cnt[i + 1][j + 1][1] += cnt[i][j][1]; ok[i + 1][j + 1][1] = true; } } ll ans = 0; REP(i, 0, S.size() + 1) ans = (ans + (dp[S.size()][i][0] * i) % MOD) % MOD; REP(i, 0, S.size() + 1) ans = (ans + (dp[S.size()][i][1] * i) % MOD) % MOD; cout << ans << endl; }