結果

問題 No.685 Logical Operations
ユーザー pekempeypekempey
提出日時 2018-05-11 23:40:44
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,630 bytes
コンパイル時間 669 ms
コンパイル使用メモリ 71,944 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 17:53:01
合計ジャッジ時間 1,710 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

const int mod = 1e9 + 7;

struct Modint {
  int n;
  Modint(int n = 0) : n(n) {}
};

Modint operator+(Modint a, Modint b) { return (a.n += b.n) >= mod ? a.n - mod : a.n; }
Modint operator-(Modint a, Modint b) { return (a.n -= b.n) < 0 ? a.n + mod : a.n; }
Modint operator*(Modint a, Modint b) { return 1LL * a.n * b.n % mod; }
Modint &operator+=(Modint &a, Modint b) { return a = a + b; }
Modint &operator-=(Modint &a, Modint b) { return a = a - b; }
Modint &operator*=(Modint &a, Modint b) { return a = a * b; }

Modint dp[80][2][2][2][2];

int main() {
  dp[0][0][0][0][0] = 1;
  long long n;
  cin >> n;

  for (int i = 0; i < 60; i++) {
    int v = n >> (59 - i) & 1;
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 2; k++) {
        for (int l = 0; l < 2; l++) {
          for (int m = 0; m < 2; m++) {
            for (int x = 0; x < 2; x++) {
              for (int y = 0; y < 2; y++) {
                if (!j && x > v) continue;
                if (!k && y > v) continue;
                int And = x & y;
                int Xor = x ^ y;
                int Or  = x | y;
                if (!l && And > Xor) continue;
                if (!m && Xor > Or) continue;
                dp[i + 1][j || x < v][k || y < v][l || And < Xor][m || Xor < Or] += dp[i][j][k][l][m];
              }
            }
          }
        }
      }
    }
  }
  Modint ans;
  for (int j = 0; j < 2; j++) {
    for (int k = 0; k < 2; k++) {
      ans += dp[60][j][k][1][1];
    }
  }
  ans *= (mod + 1) / 2;
  cout << ans.n << endl;
}
0