結果

問題 No.3547 Rurumaru Function Problem
コンテスト
ユーザー shin
提出日時 2026-06-13 19:24:37
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
WA  
実行時間 -
コード長 1,253 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,863 ms
コンパイル使用メモリ 83,624 KB
実行使用メモリ 42,752 KB
最終ジャッジ日時 2026-06-13 19:24:45
合計ジャッジ時間 6,931 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.util.Scanner;

public class No3547 {

	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		
		int n = Integer.parseInt(scanner.next());
		int m = Integer.parseInt(scanner.next());
		
		scanner.close();
		
		String nString = Integer.toBinaryString(n);
		String mString = Integer.toBinaryString(m);
		
		int max = Math.max(nString.length(), mString.length());

		nString = "0".repeat(max - nString.length()).concat(nString);
		mString = "0".repeat(max - mString.length()).concat(mString);
		
		System.out.println(nString);
		System.out.println(mString);
		
		String ans = "";
		
		int i = 0;
		for(i = 0;i < max;i++) {
			
			if((max - 1 - i) % 2 == 0) {
				
				if('0' == mString.charAt(i)){
					ans = ans.concat("0");
				}else if('1' == nString.charAt(i)) {
					ans = ans.concat("1");
				}else {
					ans = "-1";
					break;
				}
				
			}else {
				
				if(nString.charAt(i) == mString.charAt(i)) {
					ans = ans.concat("0");
				}else if('0' == nString.charAt(i)) {
					ans = ans.concat("1");
				}else {
					ans = "-1";
					break;
				}
			}
						
		}
		
		if(!"-1".equals(ans)) {
			System.out.println(Integer.parseUnsignedInt(ans, 2));
		}else {
			System.out.println(ans);
		}
		
	}

}
0