結果

問題 No.2447 行列累乗根
ユーザー 👑 p-adicp-adic
提出日時 2023-04-07 14:52:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,316 bytes
コンパイル時間 1,101 ms
コンパイル使用メモリ 84,720 KB
実行使用メモリ 13,888 KB
最終ジャッジ日時 2024-04-14 07:28:47
合計ジャッジ時間 8,799 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// 誤解法(exp(log/3))チェック
#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>
#include <iomanip>
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 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 REPEAT( HOW_MANY_TIMES ) FOR( VARIABLE_FOR_REPEAT ## HOW_MANY_TIMES , 0 , HOW_MANY_TIMES )
#define QUIT return 0
#define COUT( ANSWER ) cout << ( ANSWER ) << "\n"

template <typename T>
class TwoByTwoMatrix
{

public:
  T m_M00;
  T m_M01;
  T m_M10;
  T m_M11;

public:
  inline TwoByTwoMatrix( const T& M00 , const T& M01 , const T& M10 , const T& M11 ) noexcept;
  inline TwoByTwoMatrix<T>& operator=( const TwoByTwoMatrix<T>& mat ) noexcept;
  inline TwoByTwoMatrix<T>& operator+=( const TwoByTwoMatrix<T>& mat );
  inline TwoByTwoMatrix<T>& operator-=( const TwoByTwoMatrix<T>& mat );

  inline TwoByTwoMatrix<T> operator*( const TwoByTwoMatrix<T>& mat );
  inline TwoByTwoMatrix<T> operator/( const T& t );

};

template <typename T> inline TwoByTwoMatrix<T>::TwoByTwoMatrix( const T& M00 , const T& M01 , const T& M10 , const T& M11 ) noexcept : m_M00( M00 ) , m_M01( M01 ) , m_M10( M10 ) , m_M11( M11 ) {}

template <typename T> inline TwoByTwoMatrix<T>& TwoByTwoMatrix<T>::operator=( const TwoByTwoMatrix<T>& mat ) noexcept
{

  if( &mat != this ){

    m_M00 = mat.m_M00;
    m_M01 = mat.m_M01;
    m_M10 = mat.m_M10;
    m_M11 = mat.m_M11;

  }

  return *this;

}

template <typename T> inline TwoByTwoMatrix<T>& TwoByTwoMatrix<T>::operator+=( const TwoByTwoMatrix<T>& mat )
{

  m_M00 += mat.m_M00;
  m_M01 += mat.m_M01;
  m_M10 += mat.m_M10;
  m_M11 += mat.m_M11;
  return *this;

}

template <typename T> inline TwoByTwoMatrix<T>& TwoByTwoMatrix<T>::operator-=( const TwoByTwoMatrix<T>& mat )
{

  m_M00 -= mat.m_M00;
  m_M01 -= mat.m_M01;
  m_M10 -= mat.m_M10;
  m_M11 -= mat.m_M11;
  return *this;

}

template <typename T> inline TwoByTwoMatrix<T> TwoByTwoMatrix<T>::operator*( const TwoByTwoMatrix<T>& mat )
{
  return TwoByTwoMatrix<T>
    (
     m_M00 * mat.m_M00 + m_M01 * mat.m_M10 , m_M00 * mat.m_M01 + m_M01 * mat.m_M11 ,
     m_M10 * mat.m_M00 + m_M11 * mat.m_M10 , m_M10 * mat.m_M01 + m_M11 * mat.m_M11
     );
}

template <typename T> inline TwoByTwoMatrix<T> TwoByTwoMatrix<T>::operator/( const T& t )
{
  return TwoByTwoMatrix<T>
    (
     m_M00 / t , m_M01 / t ,
     m_M10 / t , m_M11 / t
     );
}

// マクローリン展開の収束域から外れるので機能しない
template <typename T> inline TwoByTwoMatrix<T> log( const TwoByTwoMatrix<T>& mat )
{
  TwoByTwoMatrix<T> answer{ 0 , 0 , 0 , 0 };
  TwoByTwoMatrix<T> power{ 1 , 0 , 0 , 1 };
  TwoByTwoMatrix<T> mat_shift{ mat.m_M00 - 1 , mat.m_M01 , mat.m_M10 , mat.m_M11 - 1 };
  FOR( i , 1 , 15 ){
    power = power * mat_shift;
    if( i % 2  == 0 ){
      answer -= power / i;
    } else {
      answer += power / i;
    }
  }
  return answer;
}

template <typename T> inline TwoByTwoMatrix<T> exp( const TwoByTwoMatrix<T>& mat )
{
  TwoByTwoMatrix<T> answer{ 0 , 0 , 0 , 0 };
  TwoByTwoMatrix<T> div_power{ 1 , 0 , 0 , 1 };
  FOR( i , 0 , 15 ){
    answer += div_power;
    div_power = ( div_power * mat ) / ( i + 1 );
  }
  return answer;
}

int MAIN()
{
  UNTIE;
  CEXPR( int , bound_T , 100000 );
  CIN_ASSERT( T , 1 , bound_T );
  REPEAT( T ){
    CIN( double , M00 );
    CIN( double , M01 );
    CIN( double , M10 );
    CIN( double , M11 );
    TwoByTwoMatrix<double> M{ M00 , M01 , M10 , M11 };
    TwoByTwoMatrix<double> Mcbrt = exp( log( M ) / 3 );
    cout << fixed << setprecision( 5 );
    cout << Mcbrt.m_M00 << " " << Mcbrt.m_M01 << "\n";
    cout << Mcbrt.m_M10 << " " << Mcbrt.m_M11 << "\n";
  }
  QUIT;
}
0