結果

問題 No.685 Logical Operations
ユーザー はむこはむこ
提出日時 2017-08-29 23:28:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,719 bytes
コンパイル時間 1,261 ms
コンパイル使用メモリ 154,848 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-06 06:51:11
合計ジャッジ時間 2,280 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,384 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 second
using 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;
}
0