結果

問題 No.2272 多項式乗算 mod 258280327
ユーザー 👑 p-adicp-adic
提出日時 2023-04-09 16:16:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,197 bytes
コンパイル時間 612 ms
コンパイル使用メモリ 73,304 KB
実行使用メモリ 13,756 KB
最終ジャッジ日時 2024-04-15 05:53:32
合計ジャッジ時間 6,063 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,756 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 2 ms
6,816 KB
testcase_03 AC 1 ms
6,816 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 3 ms
6,944 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 34 ms
6,944 KB
testcase_25 AC 592 ms
6,940 KB
testcase_26 AC 577 ms
6,940 KB
testcase_27 TLE -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

// 誤解法(O(NM)愚直解)チェック
#include <iostream>
#include <stdio.h>
#include <stdint.h>
#include <cassert>
using namespace std;

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 LL BOUND = VALUE
#define CIN( LL , A ) LL A; cin >> A
#define ASSERT( A , MIN , MAX ) assert( ( MIN ) <= A && A <= ( MAX ) )
#define CIN_ASSERT( A , MIN , MAX ) CIN( TYPE_OF( MAX ) , A ); ASSERT( A , MIN , MAX )
#define FOR( VAR , INITIAL , FINAL_PLUS_ONE ) for( TYPE_OF( FINAL_PLUS_ONE ) VAR = INITIAL ; VAR < FINAL_PLUS_ONE ; VAR ++ )
#define FOREQ( VAR , INITIAL , FINAL ) for( TYPE_OF( FINAL ) VAR = INITIAL ; VAR <= FINAL ; VAR ++ )
#define QUIT return 0
#define COUT( ANSWER ) cout << ( ANSWER ) << "\n";
#define RETURN( ANSWER ) COUT( ANSWER ); QUIT

int MAIN()
{
  UNTIE;
  CEXPR( int , power3_max , 531441 ); // 400000を超える最小の3羃3^12
  CEXPR( int , bound_deg , 200000 );
  CEXPR( ll , bound_coef , 1000000000000000000 );
  CEXPR( ll , P , 258280327 );
  CIN_ASSERT( deg_F , 0 , bound_deg );
  ll F[power3_max];
  FOREQ( i , 0 , deg_F ){
    CIN_ASSERT( F_i , 0 , bound_coef );
    F[i] = move( F_i );
  }
  CIN_ASSERT( deg_G , 0 , bound_deg );
  ll G[power3_max];
  FOREQ( i , 0 , deg_G ){
    CIN_ASSERT( G_i , 0 , bound_coef );
    G[i] = move( G_i );
  }
  assert( deg_F > 0 ? F[deg_F] > 0 : true );
  assert( deg_G > 0 ? G[deg_G] > 0 : true );
  if( deg_F == 0 ){
    if( F[0] == 0 ){
      cout << 0 << "\n";
      cout << 0 << "\n";
      QUIT;
    }
  }
  if( deg_G == 0 ){
    if( G[0] == 0 ){
      cout << 0 << "\n";
      cout << 0 << "\n";
      QUIT;
    }
  }
  FOREQ( i , 0 , deg_F ){
    F[i] %= P;
  }
  FOREQ( i , 0 , deg_G ){
    G[i] %= P;
  }
  int deg_FG = deg_F + deg_G;
  cout << deg_FG << "\n";
  FOR( d , 0 , deg_FG ){
    ll answer = 0;
    int i_min = max( 0 , d - deg_G );
    int i_max = min( deg_F , d );
    FOREQ( i , i_min , i_max ){
      ( answer += F[i] * G[d - i] ) %= P;
    }
    cout << answer << " ";
  }
  RETURN( ( F[deg_F] * G[deg_G] ) % P);
}
0