結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,432 KB
testcase_01 AC 123 ms
55,612 KB
testcase_02 AC 122 ms
56,020 KB
testcase_03 AC 123 ms
55,428 KB
testcase_04 AC 123 ms
55,828 KB
testcase_05 AC 123 ms
55,536 KB
testcase_06 AC 122 ms
56,012 KB
testcase_07 AC 120 ms
55,732 KB
testcase_08 AC 120 ms
55,544 KB
testcase_09 AC 120 ms
55,484 KB
testcase_10 AC 120 ms
55,732 KB
testcase_11 AC 121 ms
55,992 KB
testcase_12 AC 120 ms
55,636 KB
testcase_13 AC 121 ms
56,432 KB
testcase_14 AC 122 ms
55,676 KB
testcase_15 AC 123 ms
55,368 KB
testcase_16 AC 120 ms
56,004 KB
testcase_17 AC 121 ms
55,608 KB
testcase_18 AC 123 ms
55,688 KB
testcase_19 AC 120 ms
55,680 KB
testcase_20 AC 121 ms
55,432 KB
testcase_21 AC 119 ms
55,900 KB
testcase_22 AC 118 ms
56,108 KB
testcase_23 AC 120 ms
55,840 KB
testcase_24 AC 120 ms
55,700 KB
testcase_25 AC 119 ms
55,992 KB
testcase_26 AC 119 ms
55,704 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;
						}
					}
				}
			}
			dp = ndp;
		}
		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