結果
| 問題 |
No.8105 Міжнародний підрядок саміт
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2023-04-02 11:23:14 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
RE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 5,393 bytes |
| コンパイル時間 | 12,331 ms |
| コンパイル使用メモリ | 283,828 KB |
| 最終ジャッジ日時 | 2025-02-11 22:16:32 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 1 RE * 3 |
ソースコード
#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 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 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 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
template <typename T> inline T Absolute( const T& a ){ return a > 0 ? a : -a; }
inline CEXPR( int , bound_N , 13 );
struct CombSum
{
int m_val[bound_N+1];
constexpr CombSum() : m_val()
{
FOREQ( N , 1 , bound_N ){
if( ( N & 1 ) == 1 ){
m_val[N] = 1 << ( N - 1 );
} else {
int& m_val_N = m_val[N];
int comb = 1;
FOREQ( p , 1 , N ){
( comb *= ( N - p + 1 ) ) /= p;
if( ( p & 1 ) == 1 ){
m_val_N += comb;
}
}
}
}
}
};
int main()
{
UNTIE;
CEXPR( int , bound_T , 6000 );
CIN_ASSERT( T , 1 , bound_T );
CEXPR( int , bound_Pl , 100000000 );
CEXPR( int , bound_Pr , 1000000000 );
CEXPR( ll , bound_Ai , 1000000000 );
CEXPR( ll , bound_evenness , ll( 1 ) << 62 );
CEXPR( int , lim_x_shift , bound_N * ( bound_N - 1 ) + 1 );
CEXPR( int , bound_x , lim_x_shift >> 1 );
CEXPR( int , lim_B , 1 << bound_N );
static set<int> x[lim_B][bound_N+1] = {};
static int xl[lim_B][bound_N+1][lim_x_shift+1];
static int xr[lim_B][bound_N+1][lim_x_shift+1];
int Card[lim_B];
FOR( B , 1 , lim_B ){
set<int> ( &xB )[bound_N+1] = x[B];
int B_copy = B;
int A[bound_N] = {};
int B_card = 0;
FOR( d , 0 , bound_N ){
if( ( B_copy & 1 ) == 1 ){
A[B_card++] = d;
}
B_copy >>= 1;
}
Card[B] = B_card;
int power = 1 << B_card;
FOREQ( B_p , 0 , power ){
B_copy = B_p;
int x_shift = 0;
int p = 0;
FOR( d , 0 , B_card ){
( B_copy & 1 ) == 1 ? ( p++ , x_shift += A[d] ) : x_shift -= A[d];
B_copy >>= 1;
}
xB[p].insert( x_shift );
FOREQ( p , 0 , B_card ){
set<int>& xBp = xB[p];
xBp.insert( -bound_x - 1 );
xBp.insert( bound_x + 1 );
}
}
int ( &xlB )[bound_N+1][lim_x_shift+1] = xl[B];
int ( &xrB )[bound_N+1][lim_x_shift+1] = xr[B];
FOREQ( p , 0 , B_card ){
set<int>& xBp = xB[p];
int ( &xlBp )[lim_x_shift+1] = xlB[p];
int ( &xrBp )[lim_x_shift+1] = xrB[p];
int size = xBp.size();
auto begin = xBp.begin();
auto itr = begin;
int y = *( itr++ );
itr++;
int y_shift[2] = { 0 };
int i_prev = 0;
int i_curr = 1;
FOR( i , 1 , size ){
int& y_shift_prev = y_shift[i_prev];
int& y_shift_curr = y_shift[i_curr];
y_shift_curr = *itr + bound_x;
FOR( z , y_shift_prev , y_shift_curr ){
xlBp[z] = y;
}
swap( i_prev , i_curr );
y = *( itr++ );
}
itr = begin;
y = *( ++itr );
y_shift[0] = -1;
i_prev = 0;
i_curr = 1;
FOR( i , 1 , size ){
int& y_shift_prev = y_shift[i_prev];
int& y_shift_curr = y_shift[i_curr];
y_shift_curr = y + bound_x;
FOREQ( z , y_shift_prev + 1 , y_shift_curr ){
xrBp[z] = y;
}
swap( i_prev , i_curr );
y = *( ++itr );
}
}
}
constexpr CombSum comb_sum{};
REPEAT( T ){
CIN_ASSERT( N , 1 , bound_N );
CIN_ASSERT( P , bound_Pl , bound_Pr );
CIN_ASSERT( A0 , 1 , bound_Ai );
CIN_ASSERT( A1 , A0 , bound_Ai );
ll d = A1 - A0;
FOR( i , 2 , N ){
cin >> A1;
}
ll answer;
if( d == 0 ){
answer = comb_sum.m_val[N] * A0;
} else {
answer = 0;
if( d < 0 ){
d *= -1;
A0 -= d * ( N - 1 );
}
int power_N = 1 << N;
FOR( B , 1 , power_N ){
int ( &xlB )[bound_N+1][lim_x_shift+1] = xl[B];
int ( &xrB )[bound_N+1][lim_x_shift+1] = xr[B];
int& B_card = Card[B];
ll evenness = bound_evenness;
FOREQ( p , 0 , B_card ){
int ( &xlBp )[lim_x_shift+1] = xlB[p];
int ( &xrBp )[lim_x_shift+1] = xrB[p];
ll A0_factor = ( B_card - ( p << 1 ) ) * A0;
ll y = A0_factor / d - ( ( A0_factor < 0 && A0_factor % d != 0 ) ? 1 : 0 ) + bound_x;
if( y >= lim_x_shift ){
y = lim_x_shift - 1;
} else if( y < 0 ){
y = 0;
}
int& yl = xlBp[y];
if( yl >= -bound_x ){
ll evenness_curr = Absolute( -A0_factor + yl * d );
if( evenness > evenness_curr ){
evenness = evenness_curr;
}
}
int& yr = xrBp[y];
if( yr <= bound_x ){
ll evenness_curr = Absolute( -A0_factor + yr * d );
if( evenness > evenness_curr ){
evenness = evenness_curr;
}
}
}
answer += evenness;
}
}
COUT( answer % P );
}
QUIT;
}