結果
| 問題 |
No.2447 行列累乗根
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2023-04-02 22:13:43 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,885 bytes |
| コンパイル時間 | 993 ms |
| コンパイル使用メモリ | 83,876 KB |
| 最終ジャッジ日時 | 2025-02-11 22:27:59 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 28 |
ソースコード
// 誤解法(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 CIN( LL , A ) LL A; cin >> A
#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"
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;
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;
}