結果

問題 No.3249 AND
コンテスト
ユーザー SnowBeenDiding
提出日時 2025-12-25 02:08:50
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
結果
WA  
実行時間 -
コード長 863 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 5,627 ms
コンパイル使用メモリ 335,196 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-12-25 02:12:32
合計ジャッジ時間 7,609 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 22 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

#include <atcoder/all>
#define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
using namespace atcoder;
using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(12);
    int ans = 0;
    int n;
    cin >> n;
    vector<int> a(n + 1);
    rep(i, 1, n + 1) {
        cin >> a[i];
        ans |= (i & a[i]);
    }
    rep(i, 1, n + 1) {
        if ((ans & i) != a[i]) {
            cout << "-1" << endl;
            return 0;
        }
    }
    if (ans == 0) {
        ans = -1;
        rep(i, 1, 10) {
            bool ok = 1;
            rep(j, 1, n + 1) {
                if ((i & j) != a[j]) ok = 0;
            }
            if (ok) {
                ans = i;
                break;
            }
        }
    }
    cout << ans << endl;
}
0