結果

問題 No.2122 黄金比で擬似乱数生成
ユーザー 259_Momone259_Momone
提出日時 2022-11-04 22:49:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,141 bytes
コンパイル時間 2,596 ms
コンパイル使用メモリ 264,528 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-09-26 01:19:53
合計ジャッジ時間 7,046 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 WA -
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/extc++.h>

int main() {
    using namespace std;
    constexpr unsigned long mod{10000};
    unsigned long S, M, L;
    {
        string s;
        cin >> s;
        while(s[0] == '0')s.erase(begin(s));
        S = stoi(s);
    }
    cin >> M >> L;
    const auto m_shuffle{[&M](unsigned long x){
        unsigned long a{}, b{1}, c{x}, d{1}, e{}, f{1};
        unsigned long n{M};
        while(n){
            if(n & 1){
                tie(d, e, f) = make_tuple(a * d + b * e, b * d + c * e, b * e + c * f);
                d %= mod;
                e %= mod;
                f %= mod;
            }
            tie(a, b, c) = make_tuple(a * a + b * b, b * (a + c), b * b + c * c);
            a %= mod;
            b %= mod;
            c %= mod;
            n /= 2;
        }
        if(M & 1)(e += 9999) %= mod;
        return e;
    }};
    vector<optional<unsigned long>> num(10000);
    for(unsigned long i{}; i < L; ++i){
        if(num[S]){
            const auto C{i - num[S].value()};
            i += (L - i) / C;
        }else num[S] = i;
        S = m_shuffle(S);
    }
    printf("%04lu\n", S);
    return 0;
}
0