結果
問題 | No.2122 黄金比で擬似乱数生成 |
ユーザー |
👑 |
提出日時 | 2022-08-03 02:08:44 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 6 ms / 2,000 ms |
コード長 | 3,393 bytes |
コンパイル時間 | 812 ms |
コンパイル使用メモリ | 70,400 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-18 22:04:41 |
合計ジャッジ時間 | 1,643 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
コンパイルメッセージ
main.cpp: In function 'void ShuffleMemorise(ll&, const std::__cxx11::list<long long int>&, const ll&)': main.cpp:187:20: warning: 'num' may be used uninitialized [-Wmaybe-uninitialized] 187 | const ll d = ( I - num ) % period; | ~~~~^~~~~~~ main.cpp:167:6: note: 'num' was declared here 167 | ll num; | ^~~
ソースコード
#include <iostream>#include <list>#include <string>#include <stdio.h>#include <stdint.h>using namespace std;using ll = long long;#define MODULO 10000void Solve();int main(){Solve();return 0;}list<ll> AdicExp( ll& power );void Shuffle( ll& n , const list<ll>& adic_exp );void ShuffleMemorise( ll& n , const list<ll>& adic_exp , const ll& I );void Solve(){string S;ll P;ll I;cin >> S;cin >> P;cin >> I;ll answer = stoll( S );if( P == 0 ){if( I != 0 ){answer = 0;}} else {// 素数pと正整数dに対するGL( 2 , p ^ d )の位数// = ( p ^ d - p ^ ( d - 1 ) ) ^ 2 * ( p ^ d ) ^ 2 + p ^ ( d - 1 ) * ( p ^ d - p ^ ( d - 1 ) ) ^ 2 * p ^ d// = p ^ ( 4 * d - 2 ) * ( p - 1 ) ^ 2 + p ^ ( 4 * d - 3 ) * ( p - 1 ) ^ 2// = p ^ ( 4 * d - 3 ) * ( p - 1 ) ^ 2 * ( p + 1 )// GL( 2 , 2 ^ 4 )の位数 = 2 ^ ( 4 * 4 - 3 ) * ( 2 - 1 ) ^ 2 * ( 2 + 1 ) = 2 ^ 13 * 3// GL( 2 , 5 ^ 4 )の位数 = 5 ^ ( 4 * 4 - 3 ) * ( 5 - 1 ) ^ 2 * ( 5 + 1 ) = 5 ^ 13 * 4 ^ 2 * 6 = 2 ^ 5 * 3 * 5 ^ 13// lcm( GL( 2 , 2 ^ 4 )の位数 , GL( 2 , 5 ^ 4 )の位数 ) = 2 ^ 13 * 3 * 5 ^ 13 = 3 * 10 ^ 13;ll power = ( P - 1 ) % 30000000000000;const list<ll> adic_exp = AdicExp( power );if( I < MODULO ){for( ll i = 0 ; i < I ; i++ ){Shuffle( answer , adic_exp );}} else {ShuffleMemorise( answer , adic_exp , I );}}const string answer_str = to_string( MODULO + answer ).substr( 1 );cout << answer_str << endl;return;}list<ll> AdicExp( ll& power ){list<ll> a{};while( power != 0 ){a.push_back( power % 2 );power /= 2;}return a;}void Shuffle( ll& n , const list<ll>& adic_exp ){if( n == 0 ){return;}ll M00 = 1 , M01 = 0;ll M10 = 0 , M11 = 1;ll P00 = n , P01 = 1;ll P10 = 1 , P11 = 0;for( auto itr = adic_exp.begin() , end = adic_exp.end() ; itr != end ; itr++ ){if( *itr == 1 ){const ll N00 = M00 , N01 = M01;const ll N10 = M10 , N11 = M11;M00 = ( P00 * N00 + P01 * N10 ) % MODULO , M01 = ( P00 * N01 + P01 * N11 ) % MODULO;M10 = ( P10 * N00 + P11 * N10 ) % MODULO , M11 = ( P10 * N01 + P11 * N11 ) % MODULO;}const ll Q00 = P00 , Q01 = P01;const ll Q10 = P10 , Q11 = P11;P00 = ( Q00 * Q00 + Q01 * Q10 ) % MODULO , P01 = ( ( Q00 + Q11 ) * Q01 ) % MODULO;P10 = ( Q10 * ( Q00 + Q11 ) ) % MODULO , P11 = ( Q10 * Q01 + Q11 * Q11 ) % MODULO;}if( adic_exp.empty() ? true : adic_exp.front() == 0 ){if( M00 == 0 ){M00 = MODULO - 1;} else {M00 -= 1;}}n = M00;return;}void ShuffleMemorise( ll& n , const list<ll>& adic_exp , const ll& I ){list<ll> answer_memory{};for( ll i = 0 ; i < MODULO ; i++ ){answer_memory.push_back( n );Shuffle( n , adic_exp );}const ll& last_input = answer_memory.back();answer_memory.push_back( n );bool not_found = true;ll num;auto itr = answer_memory.begin();for( ll i = 0 ; i <= MODULO && not_found ; i++ ){if( *itr == last_input ){not_found = false;num = i;} else {itr++;}}const ll period = MODULO - num - 1;const ll d = ( I - num ) % period;for( ll i = 0 ; i < d ; i++ ){itr++;}n = *itr;return;}