結果
問題 | No.685 Logical Operations |
ユーザー |
|
提出日時 | 2018-05-11 23:40:44 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,630 bytes |
コンパイル時間 | 648 ms |
コンパイル使用メモリ | 72,576 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-28 09:03:57 |
合計ジャッジ時間 | 1,469 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 27 |
ソースコード
#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;}