結果

問題 No.2444 一次変換と体積
ユーザー maeshunmaeshun
提出日時 2023-08-25 23:09:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,804 bytes
コンパイル時間 3,417 ms
コンパイル使用メモリ 233,916 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-25 23:09:51
合計ジャッジ時間 4,484 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 WA -
testcase_07 AC 1 ms
4,380 KB
testcase_08 RE -
testcase_09 WA -
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 WA -
testcase_13 AC 1 ms
4,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define rep(i, n) for(int i=0;i<(n);++i)
#define rep1(i, n) for(int i=1;i<=(n);i++)
#define ll long long
using mint = modint;
using P = pair<ll,ll>;
using lb = long double;
using T = tuple<ll, ll, ll>;
#ifdef LOCAL
#  include <debug_print.hpp>
#  define dbg(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#  define dbg(...) (static_cast<void>(0))
#endif

template<typename T>
struct Matrix {
  int h, w;
  vector<vector<T>> d;
  Matrix() {}
  //初期化のときは Matrix<> a(h, w)
  Matrix(int h, int w, T val=0): h(h), w(w), d(h, vector<T>(w,val)) {}
  Matrix& unit() {
    assert(h == w);
    rep(i,h) d[i][i] = 1;
    return *this;
  }
  const vector<T>& operator[](int i) const { return d[i];}
  vector<T>& operator[](int i) { return d[i];}
  Matrix operator*(const Matrix& a) const {
    assert(w == a.h);
    Matrix r(h, a.w);
    rep(i,h)rep(k,w)rep(j,a.w) {
      r[i][j] += d[i][k]*a[k][j];
    }
    return r;
  }
  //Matcix<> newa = a.pow(k)と使う
  Matrix pow(long long t) const {
    assert(h == w);
    if (!t) return Matrix(h,h).unit();
    if (t == 1) return *this;
    Matrix r = pow(t>>1);
    r = r*r;
    if (t&1) r = r*(*this);
    return r;
  }
};

int main()
{
    int n, b;
    cin >> n >> b;
    mint::set_mod(b);
    Matrix<mint> a(3,3);
    rep(i,3)rep(j,3){
        int c;
        cin >> c;
        a[i][j] = c;
    }
    Matrix<mint> A = a.pow(n);
    mint ans = 0;
    ans += A[0][0] * (A[1][1]*A[2][2]-A[1][2]*A[2][1]);
    ans -= A[0][1] * (A[1][0]*A[2][2]-A[2][0]*A[1][2]);
    ans += A[0][2] * (A[1][0]*A[2][1]-A[2][0]*A[1][1]);
    if(ans.val()==0){
        cout << 0 << endl;
    }
    else{
        cout << (1/ans).val() << endl;
    }
    return 0;
}
0