結果
問題 | No.685 Logical Operations |
ユーザー |
![]() |
提出日時 | 2017-08-29 23:28:49 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,719 bytes |
コンパイル時間 | 1,379 ms |
コンパイル使用メモリ | 168,928 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-06 09:50:13 |
合計ジャッジ時間 | 2,247 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 27 |
ソースコード
#include <bits/stdc++.h>#include <sys/time.h>using namespace std;#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)#define all(x) (x).begin(), (x).end()#define fi first#define se secondusing ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using P = pair<ll, ll>;static const long long mo = 1e9+7;int main(void) {ll n; cin >> n; assert(0<=n&&n<=1000000000000000000ll);string s; while (n) s += char(n % 2), n >>= 1; reverse(all(s));ll dp[100][2][2][2][2] = {};// dp[i][j][h][k][l] =// i桁目まで見て、// n未満が確定していて(j)、// X<Yが確定していて(h)、// AND<XORが確定していて(k)、// XOR<ORが確定している(l)場合の数//// これを気合で配るDPしますdp[0][0][0][0][0] = 1;rep(i, s.length()) {rep(j, 2) rep(h, 2) rep(k, 2) rep(l, 2) if (dp[i][j][h][k][l]) {set<P> t = {P(0,0), P(0,1), P(1,0), P(1,1) };// n未満確定していたらyは何でも選べる、そうでなければsに束縛if (!j) if (s[i] == 0) t.erase(P(0, 1)), t.erase(P(1, 1));// X<Yが確定していれば何でも選べる、そうでなければXに1, Yに0は配れないif (!h) t.erase(P(1, 0));// AND<XORが確定していないと、Xに1、Yに1は選べない。if (!k) t.erase(P(1, 1));for (auto x : t)(dp[i+1][j|(x.se<s[i])][h|(x.fi<x.se)][k|(x.fi^x.se)][l|(x.fi&x.se)] += dp[i][j][h][k][l]) %= mo;}}ll ret = 0;rep(j, 2) rep(h, 2)(ret += dp[s.length()][j][h][1][1]) %= mo;cout << ret << endl;return 0;}