結果

問題 No.685 Logical Operations
ユーザー 37zigen37zigen
提出日時 2018-05-12 17:29:53
言語 Java21
(openjdk 21)
結果
AC  
実行時間 123 ms / 2,000 ms
コード長 1,192 bytes
コンパイル時間 1,951 ms
コンパイル使用メモリ 74,304 KB
実行使用メモリ 56,384 KB
最終ジャッジ日時 2023-09-10 18:26:24
合計ジャッジ時間 6,500 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
56,252 KB
testcase_01 AC 122 ms
56,384 KB
testcase_02 AC 120 ms
55,724 KB
testcase_03 AC 120 ms
55,748 KB
testcase_04 AC 122 ms
55,656 KB
testcase_05 AC 121 ms
55,656 KB
testcase_06 AC 121 ms
56,140 KB
testcase_07 AC 119 ms
55,780 KB
testcase_08 AC 121 ms
55,468 KB
testcase_09 AC 119 ms
54,432 KB
testcase_10 AC 120 ms
55,824 KB
testcase_11 AC 119 ms
55,980 KB
testcase_12 AC 120 ms
56,112 KB
testcase_13 AC 120 ms
55,660 KB
testcase_14 AC 119 ms
56,160 KB
testcase_15 AC 120 ms
55,764 KB
testcase_16 AC 119 ms
55,872 KB
testcase_17 AC 120 ms
56,016 KB
testcase_18 AC 122 ms
55,768 KB
testcase_19 AC 120 ms
55,860 KB
testcase_20 AC 121 ms
55,912 KB
testcase_21 AC 119 ms
55,564 KB
testcase_22 AC 120 ms
56,144 KB
testcase_23 AC 123 ms
55,940 KB
testcase_24 AC 119 ms
55,688 KB
testcase_25 AC 121 ms
55,688 KB
testcase_26 AC 119 ms
55,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	long mo = 1_000_000_000 + 7;

	void run() {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long[][] dp = new long[2][2];
		for (int i = 60; i >= 0; --i) {
			long[][] ndp = new long[2][2];
			if ((1L << i) > N)
				continue;
			if (N < 1L << (i + 1)) {
				ndp[0][0] += 1;
			} else {
				ndp[0][1] += 1;
			}
			for (int j = 0; j <= 1; ++j) {
				for (int k = 0; k <= 1; ++k) {
					for (int x = 0; x <= 1; ++x) {
						for (int y = 0; y <= 1; ++y) {
							if (k == 0 && y == 1 && ((1L << i) & N) == 0)
								continue;
							int idx1 = j, idx2 = k;
							if (y == 0 && ((1L << i) & N) > 0)
								idx2 = 1;
							if (x == 1 && y == 1)
								idx1 = 1;
							ndp[idx1][idx2] = (ndp[idx1][idx2] + dp[j][k]) % mo;
						}
					}
				}
			}
			for (int j = 0; j < ndp.length; ++j)
				for (int k = 0; k < ndp[j].length; ++k)
					dp[j][k] = ndp[j][k];
		}
		System.out.println((dp[1][1] + dp[1][0]) % mo);

	}

	public static void main(String[] args) {
		new Main().run();
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}
0