結果
| 問題 |
No.3249 AND
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2025-09-01 14:19:41 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 24 ms / 2,000 ms |
| コード長 | 760 bytes |
| コンパイル時間 | 403 ms |
| コンパイル使用メモリ | 42,084 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-09-05 11:41:37 |
| 合計ジャッジ時間 | 1,938 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 23 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:27:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
27 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:28:37: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
28 | for (int i = 1; i <= n; i++) scanf("%d", bs + i);
| ~~~~~^~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 3249.cc: No.3249 AND - yukicoder
*/
#include<cstdio>
#include<algorithm>
using namespace std;
/* constant */
const int MAX_N = 1000000;
/* typedef */
/* global variables */
int bs[MAX_N + 1];
/* subroutines */
/* main */
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", bs + i);
int x = 0;
for (int i = 1; i <= n; i++) x |= bs[i];
if (x == 0) {
int x = 1;
while (x <= n) x <<= 1;
printf("%d\n", x);
return 0;
}
for (int i = 1; i <= n; i++) {
if ((bs[i] & i) != bs[i]) { puts("-1"); return 0; }
x &= (~i | bs[i]);
}
bool f = true;
for (int i = 1; f && i <= n; i++) f = (bs[i] == (i & x));
printf("%d\n", f ? x : -1);
return 0;
}
tnakao0123