結果

問題 No.3249 AND
ユーザー msksknkn
提出日時 2025-08-30 17:21:05
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 916 bytes
コンパイル時間 7,270 ms
コンパイル使用メモリ 79,876 KB
実行使用メモリ 58,340 KB
最終ジャッジ日時 2025-08-30 17:21:28
合計ジャッジ時間 17,258 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 20 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

package no3249_and;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] stand = new int[30];
		boolean[] ban = new boolean[30];
		int[] two = new int[30];
		two[0] = 1;
		for(int i = 1;i < 30;i++) {
			two[i] = two[i - 1] * 2;
		}
		for(int i = 1;i <= n;i++) {
			int a = sc.nextInt();
			for(int j = 0;j < 30;j++) {
				if((i & two[j]) != 0 && (a & two[j]) == 0) {
					ban[j] = true;
				}if((i & two[j]) != 0 && (a & two[j]) != 0) {
					stand[j] = 1;
				}if((a & two[j]) != 0 && (i & two[j]) == 0) {
					System.out.print(-1);
					return;
				}
			}
		}int ans = 0;
		for(int i = 0;i < 30;i++) {
			if(stand[i] == 1 && ban[i]) {
				System.out.print(-1);
				return;
			}else if(stand[i] == 1) {
				ans += two[i];
			}
		}System.out.print(ans);
	}

}
0