結果

問題 No.939 and or
ユーザー k_6101k_6101
提出日時 2019-12-05 02:08:40
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,710 bytes
コンパイル時間 2,540 ms
コンパイル使用メモリ 87,664 KB
実行使用メモリ 54,704 KB
最終ジャッジ日時 2024-05-08 20:49:43
合計ジャッジ時間 6,833 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
41,448 KB
testcase_01 AC 99 ms
40,100 KB
testcase_02 WA -
testcase_03 AC 103 ms
40,596 KB
testcase_04 AC 114 ms
41,032 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 100 ms
39,832 KB
testcase_09 AC 108 ms
41,024 KB
testcase_10 AC 110 ms
41,216 KB
testcase_11 WA -
testcase_12 AC 112 ms
40,780 KB
testcase_13 WA -
testcase_14 AC 109 ms
40,948 KB
testcase_15 AC 111 ms
41,192 KB
testcase_16 AC 103 ms
40,696 KB
testcase_17 WA -
testcase_18 AC 113 ms
41,356 KB
testcase_19 AC 99 ms
39,836 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 116 ms
41,384 KB
testcase_23 AC 112 ms
40,752 KB
testcase_24 WA -
testcase_25 AC 112 ms
41,136 KB
testcase_26 WA -
testcase_27 AC 114 ms
41,500 KB
testcase_28 AC 116 ms
41,200 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;
import java.util.TreeSet;

import static java.util.Comparator.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        Solver solver = new Solver(System.in, out);
        solver.solve();
        out.close();
    }
}
class Solver {
	Scanner sc;
	PrintWriter out;
    public Solver(InputStream in, PrintWriter out) {
    	sc = new Scanner(in);
    	this.out = out;
    }
    // ==================================================================
    public void solve() {
    	int A = Integer.parseInt(sc.next());
    	int B = Integer.parseInt(sc.next());
    	if(A > B) {
    		out.println(0);
    		return;
    	}
    	char[] ca = Integer.toBinaryString(A).toCharArray();
    	char[] cb = Integer.toBinaryString(B).toCharArray();
    	int offset = cb.length - ca.length;
    	if(ca[0] != cb[offset]) {
    		out.println(0);
    		return;
    	}
    	int cnt = -1, flg = 0;
    	if(offset > 0)	flg = 1;
    	for (int i = 1; i < ca.length; i++) {
    		if(ca[i] == 1 && cb[i+offset] == 0) {
        		out.println(0);
        		return;
    		}
			if(flg == 0 && ca[i] != cb[i+offset]) {
				flg = 1;
			} else if(ca[i] != cb[i+offset]) {
				if(cnt == -1)	cnt = 2;
				else			cnt *= 2;
			}
		}
    	out.println(cnt);
    }
    // ==================================================================
}
0