結果

問題 No.939 and or
ユーザー htensai
提出日時 2019-12-18 14:12:09
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,205 bytes
コンパイル時間 2,264 ms
コンパイル使用メモリ 76,676 KB
実行使用メモリ 51,960 KB
最終ジャッジ日時 2024-07-06 10:08:09
合計ジャッジ時間 5,212 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 5 WA * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

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