結果
問題 | No.2396 等差二項展開 |
ユーザー | 👑 p-adic |
提出日時 | 2023-02-25 18:48:46 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 893 ms / 6,000 ms |
コード長 | 5,335 bytes |
コンパイル時間 | 1,396 ms |
コンパイル使用メモリ | 90,636 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-15 03:32:26 |
合計ジャッジ時間 | 9,601 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,820 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,820 KB |
testcase_04 | AC | 2 ms
6,820 KB |
testcase_05 | AC | 2 ms
6,820 KB |
testcase_06 | AC | 2 ms
6,820 KB |
testcase_07 | AC | 2 ms
6,820 KB |
testcase_08 | AC | 2 ms
6,816 KB |
testcase_09 | AC | 2 ms
6,820 KB |
testcase_10 | AC | 2 ms
6,820 KB |
testcase_11 | AC | 2 ms
6,820 KB |
testcase_12 | AC | 2 ms
6,816 KB |
testcase_13 | AC | 2 ms
6,816 KB |
testcase_14 | AC | 2 ms
6,820 KB |
testcase_15 | AC | 8 ms
6,816 KB |
testcase_16 | AC | 107 ms
6,816 KB |
testcase_17 | AC | 467 ms
6,820 KB |
testcase_18 | AC | 750 ms
6,820 KB |
testcase_19 | AC | 893 ms
6,820 KB |
testcase_20 | AC | 3 ms
6,816 KB |
testcase_21 | AC | 2 ms
6,820 KB |
testcase_22 | AC | 2 ms
6,820 KB |
testcase_23 | AC | 388 ms
6,820 KB |
testcase_24 | AC | 610 ms
6,820 KB |
testcase_25 | AC | 746 ms
6,816 KB |
testcase_26 | AC | 549 ms
6,816 KB |
testcase_27 | AC | 611 ms
6,816 KB |
testcase_28 | AC | 671 ms
6,816 KB |
testcase_29 | AC | 612 ms
6,816 KB |
testcase_30 | AC | 441 ms
6,816 KB |
ソースコード
// フォーマットチェック #pragma GCC optimize ( "O3" ) #pragma GCC optimize( "unroll-loops" ) #pragma GCC target ( "sse4.2,fma,avx2,popcnt,lzcnt,bmi2" ) #include <iostream> #include <vector> #include <string> #include <stdio.h> #include <stdint.h> #include <cassert> using namespace std; using uint = unsigned int; using ll = long long; #define MAIN main #define TYPE_OF( VAR ) remove_const<remove_reference<decltype( VAR )>::type >::type #define UNTIE ios_base::sync_with_stdio( false ); cin.tie( nullptr ) #define CEXPR( LL , BOUND , VALUE ) constexpr const LL BOUND = VALUE #define GETLINE( S ) string S; getline( cin , S ); int VARIABLE_FOR_INDEX_FOR_STOI_FOR_ ## S = 0; int VARIABLE_FOR_SIZE_FOR_STOI_FOR_ ## S = S.size() #define FOR( VAR , INITIAL , FINAL_PLUS_ONE ) for( TYPE_OF( FINAL_PLUS_ONE ) VAR = INITIAL ; VAR < FINAL_PLUS_ONE ; VAR ++ ) #define QUIT return 0 #define RETURN( ANSWER ) cout << ( ANSWER ) << "\n"; QUIT #define POWER( ANSWER , ARGUMENT , EXPONENT ) \ TYPE_OF( ARGUMENT ) ANSWER{ 1 }; \ { \ TYPE_OF( ARGUMENT ) ARGUMENT_FOR_SQUARE_FOR_POWER = ( ARGUMENT ); \ TYPE_OF( EXPONENT ) EXPONENT_FOR_SQUARE_FOR_POWER = ( EXPONENT ); \ while( EXPONENT_FOR_SQUARE_FOR_POWER != 0 ){ \ if( EXPONENT_FOR_SQUARE_FOR_POWER % 2 == 1 ){ \ ANSWER *= ARGUMENT_FOR_SQUARE_FOR_POWER; \ } \ ARGUMENT_FOR_SQUARE_FOR_POWER *= ARGUMENT_FOR_SQUARE_FOR_POWER; \ EXPONENT_FOR_SQUARE_FOR_POWER /= 2; \ } \ } \ // 入力フォーマットチェック用 // #define CHECK_REDUNDANT_INPUT string VARIABLE_FOR_CHECK_REDUNDANT_INPUT = ""; cin >> VARIABLE_FOR_CHECK_REDUNDANT_INPUT; assert( VARIABLE_FOR_CHECK_REDUNDANT_INPUT == "" ); assert( ! cin ) #define CHECK_REDUNDANT_INPUT string VARIABLE_FOR_CHECK_REDUNDANT_INPUT = ""; getline( cin , VARIABLE_FOR_CHECK_REDUNDANT_INPUT ); assert( VARIABLE_FOR_CHECK_REDUNDANT_INPUT == "" ); assert( ! cin ) // |N| <= BOUNDを満たすNをSから構築 #define STOI( S , N , BOUND ) TYPE_OF( BOUND ) N = 0; { bool VARIABLE_FOR_POSITIVITY_FOR_STOI = true; assert( VARIABLE_FOR_INDEX_FOR_STOI_FOR_ ## S < VARIABLE_FOR_SIZE_FOR_STOI_FOR_ ## S ); if( S.substr( VARIABLE_FOR_INDEX_FOR_STOI_FOR_ ## S , 1 ) == "-" ){ VARIABLE_FOR_POSITIVITY_FOR_STOI = false; VARIABLE_FOR_INDEX_FOR_STOI_FOR_ ## S ++; assert( VARIABLE_FOR_INDEX_FOR_STOI_FOR_ ## S < VARIABLE_FOR_SIZE_FOR_STOI_FOR_ ## S ); } assert( S.substr( VARIABLE_FOR_INDEX_FOR_STOI_FOR_ ## S , 1 ) != " " ); string VARIABLE_FOR_LETTER_FOR_STOI{}; int VARIABLE_FOR_DIGIT_FOR_STOI{}; while( VARIABLE_FOR_INDEX_FOR_STOI_FOR_ ## S < VARIABLE_FOR_SIZE_FOR_STOI_FOR_ ## S ? ( VARIABLE_FOR_LETTER_FOR_STOI = S.substr( VARIABLE_FOR_INDEX_FOR_STOI_FOR_ ## S , 1 ) ) != " " : false ){ VARIABLE_FOR_DIGIT_FOR_STOI = stoi( VARIABLE_FOR_LETTER_FOR_STOI ); assert( N < BOUND / 10 ? true : N == BOUND / 10 && VARIABLE_FOR_DIGIT_FOR_STOI <= BOUND % 10 ); N = N * 10 + VARIABLE_FOR_DIGIT_FOR_STOI; VARIABLE_FOR_INDEX_FOR_STOI_FOR_ ## S ++; } if( ! VARIABLE_FOR_POSITIVITY_FOR_STOI ){ N *= -1; } if( VARIABLE_FOR_INDEX_FOR_STOI_FOR_ ## S < VARIABLE_FOR_SIZE_FOR_STOI_FOR_ ## S ){ VARIABLE_FOR_INDEX_FOR_STOI_FOR_ ## S ++; } } // 1行で入力される変数の個数が適切か確認(半角空白の個数+1を調べる) #define COUNT_VARIABLE( S , VARIABLE_NUMBER ) { int size = S.size(); int count = 0; for( int i = 0 ; i < size ; i++ ){ if( S.substr( i , 1 ) == " " ){ count++; } } assert( count + 1 == VARIABLE_NUMBER ); } inline CEXPR( uint , bound_L , 100 ); class Polynomial { public: vector<ll> m_f; static ll g_M; static uint g_L; static ll g_B; inline Polynomial() : m_f( g_L ) {}; inline Polynomial( const ll& c ) : m_f( g_L ) { m_f[0] = c; }; inline Polynomial( const Polynomial& g ) : m_f( g.m_f ) {}; inline Polynomial& operator*=( const Polynomial& g ); }; ll Polynomial::g_M = 1; uint Polynomial::g_L = 1; ll Polynomial::g_B = 1; inline Polynomial& Polynomial::operator*=( const Polynomial& g ) { vector<ll> answer( g_L * 2 ); FOR( i , 0 , g_L ){ const ll& fi = m_f[i]; FOR( j , 0 , g_L ){ ( answer[i + j] += fi * g.m_f[j] ) %= g_B; if( answer[i + j] < 0 ){ cout << "here" << endl; } } } FOR( k , 0 , g_L ){ ( answer[k] += answer[ k + g_L ] * g_M ) %= g_B; if( answer[k] < 0 ){ cout << "here" << endl; } } m_f = move( answer ); return *this; } inline Polynomial operator*( const Polynomial& f , const Polynomial& g ) { return Polynomial( f ).operator*=( g ); } int MAIN() { UNTIE; // 入力1行目を全て取得 GETLINE( NMLKB_str ); // その中の変数の個数が5であることを確認 COUNT_VARIABLE( NMLKB_str , 5 ); CEXPR( ll , bound_NM , 1000000000000000000 ); STOI( NMLKB_str , N , bound_NM ); STOI( NMLKB_str , M , bound_NM ); CEXPR( uint , bound_L , 1000 ); STOI( NMLKB_str , L , bound_L ); Polynomial::g_L = L; STOI( NMLKB_str , K , L - 1 ); CEXPR( ll , bound_B , 1000000000 ); STOI( NMLKB_str , B , bound_B ); // 余計な入力がないことを確認 CHECK_REDUNDANT_INPUT; Polynomial::g_B = B; Polynomial::g_M = M % B; Polynomial f{}; f.m_f[0] = 1; if( L == 1 ){ f.m_f[0] += Polynomial::g_M; } else { f.m_f[1] = 1; } POWER( answer , f , N ); RETURN( answer.m_f[K] ); }