結果

問題 No.3249 AND
ユーザー jiangxinyang
提出日時 2025-08-07 14:16:09
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,262 bytes
コンパイル時間 1,697 ms
コンパイル使用メモリ 195,532 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-08-29 23:56:26
合計ジャッジ時間 2,884 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 20 WA * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:48:15: warning: extra tokens at end of #undef directive
   48 | #undef getchar()
      |               ^

ソースコード

diff #

#include <bits/stdc++.h>
#define fp(i, a, b) for (int i(a), ed(b); i <= ed; ++i)
#define fb(i, a, b) for (int i(a), ed(b); i >= ed; --i)
#define go(u, i) for (int i(head[u]); i; i = e[i].nxt)
using namespace std;
typedef long long Int;
typedef pair<int, int> pii;
////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename T1, typename T2>
inline void chkmin(T1& a, T2 b) {
    if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chkmax(T1& a, T2 b) {
    if (a < b) a = b;
}
namespace FastIO {
char buf[1 << 21], *p1 = buf, *p2 = buf;
#define getchar() (p1 == p2 && (p1 = buf, p2 = (p1 + fread(buf, 1, 1 << 21, stdin))) == p1 ? EOF : *p1++)
template <typename T>
inline T read() {
    T x = 0, w = 0;
    char ch = getchar();
    while (ch < '0' || ch > '9') w |= (ch == '-'), ch = getchar();
    while ('0' <= ch && ch <= '9') x = x * 10 + (ch ^ '0'), ch = getchar();
    return w ? -x : x;
}
template <typename T>
inline void write(T x) {
    if (!x) return;
    write<T>(x / 10), putchar((x % 10) ^ '0');
}
template <typename T>
inline void print(T x) {
    if (x > 0)
        write<T>(x);
    else if (x < 0)
        putchar('-'), write<T>(-x);
    else
        putchar('0');
}
template <typename T>
inline void print(T x, char en) {
    print<T>(x), putchar(en);
}
};  // namespace FastIO
using namespace FastIO;
#undef getchar()
const int maxn = 2e5 + 10, maxm = 20, mod = 998244353;
int n, b[maxn];
bool h1[maxm], h2[maxm];
int main() {
    n = FastIO::read<int>();
    fp(i, 1, n) b[i] = FastIO::read<int>();
    for (int i = 1; i <= n; i++) {
        for (int t = 0; t < maxm; t++) {
            bool bit_i = (i >> t) & 1;
            bool bit_b = (b[i] >> t) & 1;
            if (b[i] >> t & 1) {
                h1[t] = 1;
            } else if ((i >> t & 1) && !(b[i] >> t & 1))
                h2[t] = 1;
        }
    }
    int x = 0;
    for (int t = 0; t < maxm; t++) {
        if (h1[t]) x |= 1 << t;
    }
    if (x == 0) {
        FastIO::print(-1, '\n');
        return 0;
    }
    for (int i = 1; i <= n; i++) {
        if ((i & x) != b[i]) {
            FastIO::print(-1, '\n');
            return 0;
        }
    }
    FastIO::print(x, '\n');
    return 0;
}
0