結果

問題 No.2755 行列の共役類
ユーザー 👑 p-adicp-adic
提出日時 2023-03-24 11:03:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 3,440 bytes
コンパイル時間 946 ms
コンパイル使用メモリ 75,800 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-09 07:14:02
合計ジャッジ時間 11,003 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 AC 9 ms
5,248 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 10 ms
6,816 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 12 ms
6,820 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 13 ms
6,816 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 19 ms
6,816 KB
testcase_21 AC 13 ms
6,816 KB
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 25 ms
5,248 KB
testcase_28 AC 17 ms
5,248 KB
testcase_29 RE -
testcase_30 AC 21 ms
6,820 KB
testcase_31 AC 17 ms
5,248 KB
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 RE -
testcase_53 AC 448 ms
6,816 KB
testcase_54 RE -
testcase_55 RE -
testcase_56 AC 570 ms
6,816 KB
testcase_57 RE -
testcase_58 AC 588 ms
6,820 KB
testcase_59 RE -
testcase_60 AC 897 ms
5,248 KB
testcase_61 RE -
testcase_62 AC 486 ms
5,248 KB
testcase_63 RE -
testcase_64 RE -
testcase_65 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

// C=1の時のみ有効
#pragma GCC optimize ( "O3" )
#pragma GCC optimize( "unroll-loops" )
#pragma GCC target ( "sse4.2,fma,avx2,popcnt,lzcnt,bmi2" )
#include <iostream>
#include <stdio.h>
#include <stdint.h>
#include <cassert>
#include <string>
using namespace std;

#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 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 QUIT return 0
#define COUT( ANSWER ) cout << ( ANSWER ) << "\n"
#define RETURN( ANSWER ) COUT( ANSWER ); QUIT

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

#define POWER_MOD( ANSWER , ARGUMENT , EXPONENT , MODULO )		\
  int ANSWER{ 1 };							\
  {									\
    int 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 CONVERT1( i , P )			\
  int P ## 00 = i / B;			\
  coprime = true;				\
  FOR( n , 0 , num ){				\
    if( P ## 00 % prime[n] == 0 ){		\
      coprime = false;				\
      break;					\
    }						\
  }						\

#define CONVERT2( i , P )			\
  int P ## 01 = i % B;				\

int MAIN()
{
  UNTIE;
  CEXPR( int , bound_B , 600 );
  CIN_ASSERT( B , 1 , bound_B );
  CIN( int , C );
  // assert( 1 <= C && B % C == 0 );
  assert( C == 1 );
  int B_copy = B;
  int prime[4];
  int euler = 1;
  int num = 0;
  FOR( i , 2 , B_copy ){
    if( i * i > B_copy ){
      break;
    }
    if( B_copy % i == 0 ){
      prime[num++] = i;
      B_copy /= i;
      euler *= i - 1;
      while( B_copy % i == 0 ){
	B_copy /= i;
	euler *= i;
      }
    }
  }
  if( B_copy > 1 ){
    prime[num++] = B_copy;
    euler *= B_copy - 1;
  }
  int inv[bound_B];
  FOR( i , 1 , B ){
    POWER_MOD( i_inv , i , euler - 1 , B );
    inv[i] = i_inv;
  }
  CEXPR( int , bound_Bd , bound_B * bound_B );
  bool found[bound_Bd] = {};
  int B2 = B * B;
  int answer = 0;
  bool coprime;
  CEXPR( int , bound_answer , 100 );
  FOR( i , 0 , B2 ){
    if( ! found[i] ){
      CONVERT1( i , P );
      if( coprime ){
	answer++;
	if( answer > bound_answer ){
	  cout << bound_answer;
	  RETURN( "+" );
	}
	CONVERT2( i , P );
	FOR( j , 0 , B2 ){
	  CONVERT1( j , R );
	  if( coprime ){
	    CONVERT2( j , R );
	    int& detR_inv = inv[R00];
	    int Rinv01 = Residue( - detR_inv * R01 , B );
	    int Rinv00 = detR_inv;
	    int Q01 = ( Rinv00 * P01 + Rinv01 ) % B;
	    int Q00 = ( Rinv00 * P00 ) % B;
	    Q01 = ( Q00 * R01 + Q01 ) % B;
	    Q00 = ( Q00 * R00 ) % B;
	    int k = Q00 * B + Q01;
	    found[k] = true;
	  }
	}
      }
    }
  }
  RETURN( answer );
}
0