結果

問題 No.3673 未来予知
コンテスト
ユーザー harurun
提出日時 2026-09-02 02:56:42
言語 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
結果
TLE  
実行時間 -
コード長 2,112 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,426 ms
コンパイル使用メモリ 459,836 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2026-09-04 23:08:14
合計ジャッジ時間 5,581 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge4_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 TLE * 1 -- * 1
other -- * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <immintrin.h>

using namespace std;

inline static int encode(char c){
    switch(c){
        case 'R': return 0;
        case 'S': return 1;
        case 'P': return 2;
        case 'X': return 3;
        default: return -1;
    }
}

int expecteddd[100];

const char s[] = "XRSP";

__attribute__((target("avx512f")))
uint32_t find_initial_state(){
    const __m512i offsets = _mm512_setr_epi32(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);

    const __m512i mask3 = _mm512_set1_epi32(3);

    constexpr uint64_t LIMIT = uint64_t{1} << 32;

    for(uint64_t base = 0; base < LIMIT; base += 16){
        __m512i state = _mm512_add_epi32(_mm512_set1_epi32(static_cast<uint32_t>(base)), offsets);

        __mmask16 active = 0xFFFF;

        for(int j = 0; j < 100; ++j){
            state = _mm512_xor_si512(state, _mm512_slli_epi32(state, 13));

            state = _mm512_xor_si512(state, _mm512_srli_epi32(state, 17));

            state = _mm512_xor_si512(state, _mm512_slli_epi32(state, 5));

            __m512i r = _mm512_and_si512(state, mask3);
            __m512i e = _mm512_set1_epi32(expecteddd[j]);

            __mmask16 equal = _mm512_cmpeq_epi32_mask(r, e);

            active &= equal;

            if(active == 0){
                break;
            }
        }

        if(active != 0){
            unsigned lane = __builtin_ctz(static_cast<unsigned>(active));

            return static_cast<uint32_t>(base + lane);
        }
    }

    return 0;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    string T;
    cin >> T;

    for(int j = 0; j < 100; ++j){
        expecteddd[j] = encode(T[j]);
    }

    uint32_t initial_state = find_initial_state();

    int N;
    cin >> N;

    uint32_t state = initial_state;

    for(int i = 0; i < 100; i++){
        state ^= state << 13;
        state ^= state >> 17;
        state ^= state << 5;
    }

    for(int i = 0; i < N; i++){
        state ^= state << 13;
        state ^= state >> 17;
        state ^= state << 5;

        cout << s[state & 3];
    }

    cout << '\n';
}
0