結果

問題 No.2215 Slide Subset Sum
ユーザー 👑 p-adicp-adic
提出日時 2023-02-11 10:11:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 320 ms / 3,000 ms
コード長 7,870 bytes
コンパイル時間 3,932 ms
コンパイル使用メモリ 228,040 KB
実行使用メモリ 322,688 KB
最終ジャッジ日時 2024-07-08 01:06:29
合計ジャッジ時間 11,425 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
5,248 KB
testcase_01 AC 51 ms
5,376 KB
testcase_02 AC 149 ms
5,376 KB
testcase_03 AC 140 ms
5,376 KB
testcase_04 AC 192 ms
9,600 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 282 ms
148,736 KB
testcase_18 AC 274 ms
128,000 KB
testcase_19 AC 237 ms
7,808 KB
testcase_20 AC 249 ms
163,456 KB
testcase_21 AC 265 ms
39,552 KB
testcase_22 AC 255 ms
175,872 KB
testcase_23 AC 320 ms
289,280 KB
testcase_24 AC 312 ms
290,816 KB
testcase_25 AC 296 ms
258,176 KB
testcase_26 AC 278 ms
177,152 KB
testcase_27 AC 10 ms
5,376 KB
testcase_28 AC 15 ms
12,160 KB
testcase_29 AC 17 ms
9,856 KB
testcase_30 AC 76 ms
5,376 KB
testcase_31 AC 111 ms
107,648 KB
testcase_32 AC 23 ms
7,296 KB
testcase_33 AC 172 ms
25,984 KB
testcase_34 AC 131 ms
74,368 KB
testcase_35 AC 21 ms
5,376 KB
testcase_36 AC 58 ms
49,408 KB
testcase_37 AC 310 ms
322,688 KB
testcase_38 AC 30 ms
14,976 KB
testcase_39 AC 51 ms
5,376 KB
testcase_40 AC 39 ms
5,376 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 309 ms
164,608 KB
testcase_43 AC 33 ms
5,376 KB
testcase_44 AC 33 ms
5,376 KB
testcase_45 AC 290 ms
242,688 KB
testcase_46 AC 287 ms
242,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ( "O3" )
#pragma GCC optimize( "unroll-loops" )
#pragma GCC target ( "sse4.2,fma,avx2,popcnt,lzcnt,bmi2" )
#include <bits/stdc++.h>
using namespace std;

using uint = unsigned int;
using ll = long long;

#define ATT __attribute__( ( target( "sse4.2,fma,avx2,popcnt,lzcnt,bmi2" ) ) )
#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 GETLINE( A ) string A; getline( cin , A )
#define GETLINE_SEPARATE( A , SEPARATOR ) string A; getline( cin , A , SEPARATOR )
#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 FOREQINV( VAR , INITIAL , FINAL ) for( TYPE_OF( INITIAL ) VAR = INITIAL ; VAR >= FINAL ; VAR -- )
#define FOR_ITR( ARRAY , ITR , END ) for( auto ITR = ARRAY .begin() , END = ARRAY .end() ; ITR != END ; ITR ++ )
#define REPEAT( HOW_MANY_TIMES ) FOR( VARIABLE_FOR_REPEAT , 0 , HOW_MANY_TIMES )
#define QUIT return 0
#define COUT( ANSWER ) cout << ( ANSWER ) << "\n";
#define RETURN( ANSWER ) COUT( ANSWER ); QUIT
#define DOUBLE( PRECISION , ANSWER ) cout << fixed << setprecision( PRECISION ) << ( 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 POWER_MOD( ANSWER , ARGUMENT , EXPONENT , MODULO )		\
  TYPE_OF( ARGUMENT ) ANSWER{ 1 };					\
  {									\
    TYPE_OF( ARGUMENT ) ARGUMENT_FOR_SQUARE_FOR_POWER = ( MODULO + ( ( ARGUMENT ) % MODULO ) ) % MODULO; \
    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 = ( ANSWER * ARGUMENT_FOR_SQUARE_FOR_POWER ) % MODULO;	\
      }									\
      ARGUMENT_FOR_SQUARE_FOR_POWER = ( ARGUMENT_FOR_SQUARE_FOR_POWER * ARGUMENT_FOR_SQUARE_FOR_POWER ) % MODULO; \
      EXPONENT_FOR_SQUARE_FOR_POWER /= 2;				\
    }									\
  }									\

#define FACTORIAL_MOD( ANSWER , ANSWER_INV , INVERSE , MAX_I , LENGTH , MODULO ) \
  static ll ANSWER[LENGTH];						\
  static ll ANSWER_INV[LENGTH];						\
  static ll INVERSE[LENGTH];						\
  {									\
    ll VARIABLE_FOR_PRODUCT_FOR_FACTORIAL = 1;				\
    ANSWER[0] = VARIABLE_FOR_PRODUCT_FOR_FACTORIAL;			\
    FOREQ( i , 1 , MAX_I ){						\
      ANSWER[i] = ( VARIABLE_FOR_PRODUCT_FOR_FACTORIAL *= i ) %= MODULO; \
    }									\
    ANSWER_INV[0] = ANSWER_INV[1] = INVERSE[1] = VARIABLE_FOR_PRODUCT_FOR_FACTORIAL = 1; \
    FOREQ( i , 2 , MAX_I ){						\
      ANSWER_INV[i] = ( VARIABLE_FOR_PRODUCT_FOR_FACTORIAL *= INVERSE[i] = MODULO - ( ( ( MODULO / i ) * INVERSE[MODULO % i] ) % MODULO ) ) %= MODULO; \
    }									\
  }									\

// 通常の二分探索(単調関数-目的値が一意実数解を持つ場合にそれを超えない最大の整数を返す)
#define BS( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , TARGET )		\
  ll ANSWER = MAXIMUM;							\
  {									\
    ll VARIABLE_FOR_BINARY_SEARCH_L = MINIMUM;				\
    ll VARIABLE_FOR_BINARY_SEARCH_U = ANSWER;				\
    ll VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH = ( TARGET ) - ( EXPRESSION ); \
    if( VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH == 0 ){		\
      VARIABLE_FOR_BINARY_SEARCH_L = ANSWER;				\
    } else {								\
      ANSWER = ( VARIABLE_FOR_BINARY_SEARCH_L + VARIABLE_FOR_BINARY_SEARCH_U ) / 2; \
    }									\
    while( VARIABLE_FOR_BINARY_SEARCH_L != ANSWER ){			\
      VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH = ( TARGET ) - ( EXPRESSION ); \
      if( VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH == 0 ){		\
	break;								\
      } else {								\
	if( VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH > 0 ){		\
	  VARIABLE_FOR_BINARY_SEARCH_L = ANSWER;			\
	} else {							\
	  VARIABLE_FOR_BINARY_SEARCH_U = ANSWER;			\
	}								\
	ANSWER = ( VARIABLE_FOR_BINARY_SEARCH_L + VARIABLE_FOR_BINARY_SEARCH_U ) / 2; \
      }									\
    }									\
  }									\
									\


// 二進法の二分探索(単調関数-目的値が一意実数解を持つ場合にそれを超えない最大の整数を返す)
#define BS2( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , TARGET )		\
  ll ANSWER = MINIMUM;							\
  {									\
    ll VARIABLE_FOR_POWER_FOR_BINARY_SEARCH_2 = 1;			\
    ll VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH = ( MAXIMUM ) - ANSWER; \
    while( VARIABLE_FOR_POWER_FOR_BINARY_SEARCH_2 <= VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH ){ \
      VARIABLE_FOR_POWER_FOR_BINARY_SEARCH_2 *= 2;			\
    }									\
    VARIABLE_FOR_POWER_FOR_BINARY_SEARCH_2 /= 2;			\
    ll VARIABLE_FOR_ANSWER_FOR_BINARY_SEARCH_2 = ANSWER;		\
    while( VARIABLE_FOR_POWER_FOR_BINARY_SEARCH_2 != 0 ){		\
      ANSWER = VARIABLE_FOR_ANSWER_FOR_BINARY_SEARCH_2 + VARIABLE_FOR_POWER_FOR_BINARY_SEARCH_2; \
      VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH = ( TARGET ) - ( EXPRESSION ); \
      if( VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH == 0 ){		\
	VARIABLE_FOR_ANSWER_FOR_BINARY_SEARCH_2 = ANSWER;		\
	break;								\
      } else if( VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH > 0 ){	\
	VARIABLE_FOR_ANSWER_FOR_BINARY_SEARCH_2 = ANSWER;		\
      }									\
      VARIABLE_FOR_POWER_FOR_BINARY_SEARCH_2 /= 2;			\
    }									\
    ANSWER = VARIABLE_FOR_ANSWER_FOR_BINARY_SEARCH_2;			\
  }									\
									\


template <typename T> inline T Absolute( const T& a ){ return a > 0 ? a : -a; }
template <typename T> inline T Residue( const T& a , const T& p ){ return a >= 0 ? a % p : p - 1 - ( ( - ( a + 1 ) ) % p ); }

inline CEXPR( ll , P , 998244353 );
int K = 1;
void red( vector<ll>& f )
{
  int size = f.size();
  while( size > K ){
    size--;
    ll& f_curr = f[size - K];
    if( ( f_curr += f[size] ) >= P ){
      f_curr -= P;
    }
    f.pop_back();
  }
  return;
}
void mul( vector<ll>& f , int& Ai )
{
  int size = f.size();
  f.resize( size + Ai );
  FOREQINV( i , size - 1 , 0 ){
    ll& f_curr = f[i + Ai];
    if( ( f_curr += f[i] ) >= P ){
      f_curr -= P;
    }
  }
  red( f );
  return;
}

ATT int main()
{
  UNTIE;
  CIN( int , N );
  CIN( int , M );
  cin >> K;
  vector<int> A( M );
  FOR( i , 0 , M ){
    cin >> A[i];
  }
  vector<vector<ll> > a( M );
  a.back() = vector<ll>( 1 , 1 );
  FOREQINV( i , M - 1 , 1 ){
    mul( a[i-1] = a[i] , A[i] );
  }
  vector<ll> temp( a[0] );
  mul( temp , A[0] );
  CEXPR( ll , P_minus , P - 1 );
  ll answer = temp[0];
  COUT( answer > 0 ? --answer : P_minus );
  temp = vector<ll>( 1 , 1 );
  int i = 0;
  N -= M;
  REPEAT( N ){
    CIN( int , Ai );
    A[i] = Ai;
    mul( temp , Ai );
    vector<ll>& f = a[i];
    int size_temp = temp.size();
    int size_f = f.size();
    ( answer = temp[0] * f[0] ) %= P;
    FOR( j , K - size_f + 1 , size_temp ){
      ( answer += temp[j] * f[K - j] ) %= P;
    }
    COUT( answer > 0 ? --answer : P_minus );
    if( ++i == M ){
      a.back() = vector<ll>( 1 , 1 );
      FOREQINV( i , M - 1 , 1 ){
	mul( a[i-1] = a[i] , A[i] );
      }
      temp = vector<ll>( 1 , 1 );
      i = 0;
    }
  }
  QUIT;
}
0