結果

問題 No.685 Logical Operations
ユーザー square1001square1001
提出日時 2018-05-29 18:12:29
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 928 bytes
コンパイル時間 489 ms
コンパイル使用メモリ 65,456 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-12 20:26:08
合計ジャッジ時間 1,534 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
using namespace std;
const unsigned mod = 1000000007;
unsigned long long N; unsigned dp[66][16]; bool vis[66][16];
unsigned solve(int digit, int fx, int fy, int f10, int f11) {
	if (digit == -1) return f10 && f11 ? 1 : 0;
	int h = fx + fy * 2 + f10 * 4 + f11 * 8;
	if (vis[digit][h]) return dp[digit][h];
	unsigned ret = solve(digit - 1, fx || ((N >> digit) & 1), fy || ((N >> digit) & 1), f10, f11);
	bool vx = fy == 1 || ((N >> digit) & 1);
	bool vy = fx == 1 || ((N >> digit) & 1);
	if (vy) ret += solve(digit - 1, fx || ((N >> digit) & 1), fy, 1, f11);
	if (vx) ret += solve(digit - 1, fx, fy || ((N >> digit) & 1), 1, f11);
	if (vx && vy && f10) ret += solve(digit - 1, fx, fy, 1, 1);
	while (ret >= mod) ret -= mod;
	vis[digit][h] = true;
	dp[digit][h] = ret;
	return ret;
}
int main() {
	cin >> N;
	unsigned  ret = solve(60, 0, 0, 0, 0);
	cout << 1ull * ret * (mod / 2 + 1) % mod << '\n';
	return 0;
}
0