結果

問題 No.685 Logical Operations
ユーザー e869120e869120
提出日時 2018-05-18 21:30:33
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 962 bytes
コンパイル時間 689 ms
コンパイル使用メモリ 64,680 KB
実行使用メモリ 4,564 KB
最終ジャッジ日時 2023-09-10 22:55:19
合計ジャッジ時間 1,854 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
using namespace std;

long long N, dp[66][2][2][2][2], mod = 1000000007;

long long solve(long long dig, long long t1, long long t2, long long a, long long b) {
	if (dig == -1) {
		if (a == 1 && b == 1) return 1;
		return 0;
	}
	if (dp[dig][t1][t2][a][b] >= 1) return dp[dig][t1][t2][a][b] - 1;

	long long B1 = 1, B2 = 1;
	if (t1 == 0 && (N / (1LL << dig)) % 2 == 0) B1 = 0;
	if (t2 == 0 && (N / (1LL << dig)) % 2 == 0) B2 = 0;

	long long sum = 0;

	for (int i = 0; i <= B1; i++) {
		for (int j = 0; j <= B2; j++) {
			int n1 = t1, n2 = t2; if (i != B1) n1 = 1; if (j != B2) n2 = 1;
			int c1 = a, c2 = b; if ((i&j) < (i^j)) c1 = 1; if ((i^j) < (i | j)) c2 = 1;
			if (c1 == 0 && (i&j) > (i^j)) continue;
			if (c2 == 0 && (i^j) > (i | j)) continue;
			sum += solve(dig - 1, n1, n2, c1, c2); sum %= mod;
		}
	}
	dp[dig][t1][t2][a][b] = sum + 1;
	return sum;
}

int main() {
	cin >> N;
	cout << solve(3, 0, 0, 0, 0) / 2 << endl;
	return 0;
}
0