結果

問題 No.3673 未来予知
コンテスト
ユーザー harurun
提出日時 2026-09-03 17:01:57
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 2,438 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 8,060 ms
コンパイル使用メモリ 462,508 KB
実行使用メモリ 9,796 KB
最終ジャッジ日時 2026-09-04 23:12:57
合計ジャッジ時間 9,583 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include "testlib.h"

#include <bits/stdc++.h>
using namespace std;

using u32 = uint32_t;
using u64 = uint64_t;

u32 nextState(u32 x) {
    x ^= x << 13;
    x ^= x >> 17;
    x ^= x << 5;
    return x;
}

array<u32, 32> nextSymbolic(array<u32, 32> x) {
    array<u32, 32> y = x;
    for (int i = 13; i < 32; ++i) y[i] ^= x[i - 13];
    x = y;

    y = x;
    for (int i = 0; i + 17 < 32; ++i) y[i] ^= x[i + 17];
    x = y;

    y = x;
    for (int i = 5; i < 32; ++i) y[i] ^= x[i - 5];
    return y;
}

int handValue(char c) {
    if (c == 'R') return 0;
    if (c == 'S') return 1;
    if (c == 'P') return 2;
    return 3;  // X
}

u32 recoverInitialState(const string& t) {
    array<u32, 32> symbolic{};
    for (int bit = 0; bit < 32; ++bit) symbolic[bit] = u32(1) << bit;

    vector<u64> equations;
    equations.reserve(2 * t.size());

    for (char c : t) {
        symbolic = nextSymbolic(symbolic);
        const int value = handValue(c);
        equations.push_back(u64(symbolic[0]) | (u64(value & 1) << 32));
        equations.push_back(u64(symbolic[1]) | (u64((value >> 1) & 1) << 32));
    }

    array<int, 32> pivotRow;
    pivotRow.fill(-1);

    int row = 0;
    for (int col = 0; col < 32; ++col) {
        int selected = -1;
        for (int i = row; i < static_cast<int>(equations.size()); ++i) {
            if ((equations[i] >> col) & 1ULL) {
                selected = i;
                break;
            }
        }
        if (selected == -1) continue;

        swap(equations[row], equations[selected]);
        pivotRow[col] = row;

        for (int i = 0; i < static_cast<int>(equations.size()); ++i) {
            if (i != row && ((equations[i] >> col) & 1ULL)) {
                equations[i] ^= equations[row];
            }
        }
        ++row;
    }

    u32 initial = 0;
    for (int col = 0; col < 32; ++col) {
        if (pivotRow[col] != -1 && ((equations[pivotRow[col]] >> 32) & 1ULL)) {
            initial |= u32(1) << col;
        }
    }
    return initial;
}


int main(int argc, char* argv[]){
    registerValidation(argc, argv);

    string T = inf.readToken("[RSPX]{100}");
    inf.readEoln();

    int N = inf.readInt(1, 200'000);
    inf.readEoln();
    inf.readEof();

    
    u32 state = recoverInitialState(T);

    string S;
    for(int i = 0; i < 100; ++i){
        state = nextState(state);
        S.append(1, "RSPX"[state % 4]);
    }
    ensuref(S == T, "violation T");
}
0