結果
| 問題 |
No.685 Logical Operations
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-05-12 17:32:52 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 131 ms / 2,000 ms |
| コード長 | 1,094 bytes |
| コンパイル時間 | 2,717 ms |
| コンパイル使用メモリ | 77,932 KB |
| 実行使用メモリ | 41,708 KB |
| 最終ジャッジ日時 | 2024-06-28 09:38:33 |
| 合計ジャッジ時間 | 6,578 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 27 |
ソースコード
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));
}
}