結果
| 問題 | No.3249 AND | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2025-08-07 23:05:52 | 
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                            (最新) 
                                AC
                                 
                            (最初) | 
| 実行時間 | - | 
| コード長 | 1,250 bytes | 
| コンパイル時間 | 824 ms | 
| コンパイル使用メモリ | 87,252 KB | 
| 実行使用メモリ | 6,272 KB | 
| 最終ジャッジ日時 | 2025-08-29 23:56:41 | 
| 合計ジャッジ時間 | 2,259 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 20 WA * 1 | 
ソースコード
#include <iostream>
#include <vector>
#include <numeric>
int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    int n;
    std::cin >> n;
    std::vector<int> b(n);
    for (int i = 0; i < n; ++i) {
        std::cin >> b[i];
    }
    long long x = 0;
    for (int k = 0; k < 20; ++k) { // Max value is 2e5, 2^17 < 2e5 < 2^18. 20 bits is safe.
        int required_x_k = -1; // -1: undecided, 0: must be 0, 1: must be 1
        for (int i = 1; i <= n; ++i) {
            bool i_k = (i >> k) & 1;
            bool b_k = (b[i - 1] >> k) & 1;
            if (!i_k && b_k) { // if i's bit is 0, b's bit must be 0
                std::cout << -1 << std::endl;
                return 0;
            }
            if (i_k) { // This i gives us info about x_k
                if (required_x_k == -1) {
                    required_x_k = b_k;
                } else if (required_x_k != b_k) {
                    std::cout << -1 << std::endl;
                    return 0;
                }
            }
        }
        if (required_x_k == 1) {
            x |= (1LL << k);
        }
    }
    if (x == 0) {
        std::cout << -1 << std::endl;
    } else {
        std::cout << x << std::endl;
    }
    return 0;
}
            
            
            
        