結果

問題 No.939 and or
コンテスト
ユーザー htensai
提出日時 2019-12-18 14:12:09
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
WA  
実行時間 -
コード長 1,205 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,795 ms
コンパイル使用メモリ 82,456 KB
実行使用メモリ 45,120 KB
最終ジャッジ日時 2026-03-27 22:31:38
合計ジャッジ時間 3,948 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 5 WA * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] first = br.readLine().split(" ", 2);
        int a = Integer.parseInt(first[0]);
        int b = Integer.parseInt(first[1]);
        if ((a & b) != a) {
            System.out.println(0);
            return;
        }
        int x = a ^ b;
        int count = 0;
        while (x > 0) {
            if (x % 2 == 1) {
                count++;
            }
            x /= 2;
        }
        long[][] comb = new long[count][count];
        for (int i = 0; i < count; i++) {
            for (int j = 0; j <= i; j++) {
                if (j == 0 || j == i) {
                    comb[i][j] = 1;
                } else {
                    comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
                }
            }
        }
        long total = 0;
        for (int i = 1; i < count; i++) {
            int base = count - i;
            for (int j = 0; j <= base; j++) {
                total += comb[base][j];
            }
        }
        System.out.println(total);
    }
}
0