結果

問題 No.2187 三立法和 mod 333
ユーザー 👑 p-adicp-adic
提出日時 2022-12-18 23:58:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,529 bytes
コンパイル時間 1,025 ms
コンパイル使用メモリ 78,992 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-18 01:07:31
合計ジャッジ時間 17,195 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#pragma GCC optimize ( "O3" )
#pragma GCC target ( "avx" )
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdint.h>
#include <cassert>
#include <vector>
using namespace std;

using ll = long long;

#define TYPE_OF( VAR ) remove_const<remove_reference<decltype( VAR )>::type >::type
#define CEXPR( LL , BOUND , VALUE ) constexpr const 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 FOR_ITR( ARRAY , ITR , END ) for( auto ITR = ARRAY .begin() , END = ARRAY .end() ; ITR != END ; ITR ++ ) 
#define QUIT return 0 
#define RETURN( ANSWER ) cout << ( ANSWER ) << "\n"; QUIT 

#include <cassert>

#define MAIN main

// 通常の二分探索(単調関数-目的値が区間内に一意実数解を持つ場合にそれを超えない最大の整数を返す)
#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 COMPUTE( VAR ) VAR ## 4 = VAR * VAR; VAR ## 3 = VAR ## 4 * VAR; VAR ## 4 *= VAR ## 4

#define COUNT_SOLUTION( NUM , VAR1 , VAR2 )				\
  diff4 = bound_sum - VAR1 ## 4 - VAR2 ## 4;				\
  if( diff4 > 0 ){							\
    BS( z_max , 1 , bound_xyz , z_max * z_max * z_max * z_max , diff4 ); \
    diff3 = ( A - bound_A - VAR1 ## 3 - VAR2 ## 3 ) % bound_A + bound_A; \
    vector<ll>& z_min_minus_curr = z_min_minus[diff3];			\
    FOR_ITR( z_min_minus_curr , itr , end ){				\
      answer ## NUM += ( z_max + *itr ) / bound_A;				\
    }									\
  } else {								\
    break;								\
  }									\

int MAIN()
{
  CEXPR( ll , bound_A , 333 );
  CIN_ASSERT( A , 1 , bound_A );
  CEXPR( ll , bound_xyz , 4444 );
  CEXPR( ll , bound_sum , bound_xyz * bound_xyz * bound_xyz * bound_xyz );
  static vector<ll> z_min_minus[bound_A] = {};
  FOREQ( i , 1 , bound_A ){
    z_min_minus[ ( i * i * i ) % bound_A ].push_back( int( bound_A - i ) );
  }
  ll x = 1;
  ll y , x3 , y3 , x4 , y4 , diff3 , diff4;
  ll answer1 = 0;
  ll answer2 = 0;
  while( true ){
    COMPUTE( x );
    COUNT_SOLUTION( 1 , x , x );
    y = x + 1;
    while( true ){
      COMPUTE( y );
      COUNT_SOLUTION( 2 , x , y );
      y++;
    }
    x++;
  }
  RETURN( answer1 + answer2 * 2 );
}
0