結果

問題 No.1751 Fortune Nim
ユーザー sapphire__15sapphire__15
提出日時 2021-11-06 11:22:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 803 bytes
コンパイル時間 686 ms
コンパイル使用メモリ 77,860 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-30 06:29:10
合計ジャッジ時間 3,888 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 53 ms
4,380 KB
testcase_09 AC 50 ms
4,380 KB
testcase_10 AC 43 ms
4,376 KB
testcase_11 AC 64 ms
4,376 KB
testcase_12 AC 39 ms
4,380 KB
testcase_13 AC 64 ms
4,380 KB
testcase_14 AC 48 ms
4,384 KB
testcase_15 AC 50 ms
4,384 KB
testcase_16 AC 57 ms
4,380 KB
testcase_17 AC 49 ms
4,380 KB
testcase_18 AC 65 ms
4,376 KB
testcase_19 AC 45 ms
4,380 KB
testcase_20 AC 71 ms
4,384 KB
testcase_21 AC 54 ms
4,380 KB
testcase_22 AC 71 ms
4,376 KB
testcase_23 AC 63 ms
4,376 KB
testcase_24 AC 74 ms
4,376 KB
testcase_25 AC 74 ms
4,380 KB
testcase_26 AC 74 ms
4,380 KB
testcase_27 AC 74 ms
4,384 KB
testcase_28 AC 73 ms
4,376 KB
testcase_29 AC 74 ms
4,380 KB
testcase_30 AC 73 ms
4,380 KB
testcase_31 AC 74 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/modint>
#include <iostream>
#include <vector>

using mint = atcoder::modint998244353;
using namespace std;

// calculate 3^(-x)
mint calc3pow(long long x) {
    return mint(3).pow(x).inv();
}

int main() {
    int n; cin >> n;
    vector<int> a(n);
    long long sum = 0, xor_sum = 0;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
        xor_sum ^= a[i];
    }
    if(xor_sum == 0) {
        mint ans = (1 - calc3pow(sum)) / 2;
        cout << ans.val() << endl;
    } else {
        long long init = 0;
        for(int i = 0; i < n; i++) {
            if(init < a[i] - (a[i]^xor_sum)) {
                init = a[i] - (a[i]^xor_sum);
            }
        }
        mint ans = (1 + calc3pow(sum - init + 1)) / 2;
        cout << ans.val() << endl;
    }
}
0