結果

問題 No.3249 AND
ユーザー kotatsugame
提出日時 2025-08-30 00:58:42
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 412 bytes
コンパイル時間 560 ms
コンパイル使用メモリ 67,264 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2025-08-30 00:58:46
合計ジャッジ時間 2,297 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<cassert>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;cin>>N;
	vector<int>B(N);
	int X=0;
	for(int i=0;i<N;i++)
	{
		cin>>B[i];
		X|=B[i];
	}
	for(int i=0;i<N;i++)if((i+1&X)!=B[i])
	{
		cout<<-1<<endl;
		return 0;
	}
	if(X==0)
	{
		for(int i=0;i<N;i++)X|=i+1;
		int k=0;
		while(X>>k&1)k++;
		X=1<<k;
	}
	cout<<X<<endl;
}
0