結果

問題 No.1298 OR XOR
ユーザー Muna-akkiMuna-akki
提出日時 2020-11-27 21:37:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 164 ms / 2,000 ms
コード長 702 bytes
コンパイル時間 2,174 ms
コンパイル使用メモリ 73,944 KB
実行使用メモリ 57,004 KB
最終ジャッジ日時 2023-10-01 05:02:51
合計ジャッジ時間 5,449 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 159 ms
56,504 KB
testcase_01 AC 120 ms
56,012 KB
testcase_02 AC 118 ms
55,684 KB
testcase_03 AC 121 ms
55,572 KB
testcase_04 AC 121 ms
55,548 KB
testcase_05 AC 122 ms
55,456 KB
testcase_06 AC 161 ms
57,004 KB
testcase_07 AC 164 ms
56,524 KB
testcase_08 AC 162 ms
56,956 KB
testcase_09 AC 160 ms
56,712 KB
testcase_10 AC 161 ms
56,840 KB
testcase_11 AC 160 ms
56,768 KB
testcase_12 AC 160 ms
56,908 KB
testcase_13 AC 160 ms
56,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		if(N==1) {
			System.out.println("-1 -1 -1");
			return;
		}
		int A = 1;
		int B = 1;
		int C = N;
		int count = 0;
		int S = N;
		while(true) {
			S /= 2;
			count++;
			if(S==0) {
				break;
			}
		}
		//A+B=Cとする
		//Nのビットで初めて0でないものが出てくるのはどこか
		for(int i=0 ; i<count ; i++) {
			if(N>>i==1) {
				A = 1<<i;
				B = N-A;
				if(B==0 || A==0) {
					continue;
				}
				System.out.println(A + " " + B + " " + C);
				return;
			}
			
		}
		System.out.println("-1 -1 -1");
		
  	}
}
0