結果
問題 | No.2444 一次変換と体積 |
ユーザー | hiromi_ayase |
提出日時 | 2023-08-25 23:44:48 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,738 bytes |
コンパイル時間 | 4,803 ms |
コンパイル使用メモリ | 312,116 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-06 18:41:42 |
合計ジャッジ時間 | 5,664 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | AC | 1 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 1 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | WA | - |
testcase_13 | AC | 2 ms
6,940 KB |
testcase_14 | WA | - |
testcase_15 | AC | 1 ms
6,940 KB |
testcase_16 | AC | 2 ms
6,944 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 1 ms
6,944 KB |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; #define FAST_IO \ ios::sync_with_stdio(false); \ cin.tie(0); const i64 INF = 1001001001001001001; using Modint = atcoder::static_modint<998244353>; template <typename T, int H, int W> struct Matrix { using Array = array<array<T, W>, H>; Array A; Matrix() : A() { for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) (*this)[i][j] = T(); } int height() const { return H; } int width() const { return W; } inline const array<T, W> &operator[](int k) const { return A[k]; } inline array<T, W> &operator[](int k) { return A[k]; } static Matrix I() { assert(H == W); Matrix mat; for (int i = 0; i < H; i++) mat[i][i] = 1; return (mat); } Matrix &operator+=(const Matrix &B) { for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) A[i][j] += B[i][j]; return (*this); } Matrix &operator-=(const Matrix &B) { for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) A[i][j] -= B[i][j]; return (*this); } Matrix &operator*=(const Matrix &B) { assert(H == W); Matrix C; for (int i = 0; i < H; i++) for (int k = 0; k < H; k++) for (int j = 0; j < H; j++) C[i][j] += A[i][k] * B[k][j]; A.swap(C.A); return (*this); } Matrix &operator^=(long long k) { Matrix B = Matrix::I(); while (k > 0) { if (k & 1) B *= *this; *this *= *this; k >>= 1LL; } A.swap(B.A); return (*this); } Matrix operator+(const Matrix &B) const { return (Matrix(*this) += B); } Matrix operator-(const Matrix &B) const { return (Matrix(*this) -= B); } Matrix operator*(const Matrix &B) const { return (Matrix(*this) *= B); } Matrix operator^(const long long k) const { return (Matrix(*this) ^= k); } bool operator==(const Matrix &B) const { for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) if (A[i][j] != B[i][j]) return false; return true; } bool operator!=(const Matrix &B) const { for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) if (A[i][j] != B[i][j]) return true; return false; } friend ostream &operator<<(ostream &os, const Matrix &p) { for (int i = 0; i < H; i++) { os << "["; for (int j = 0; j < W; j++) { os << p[i][j] << (j + 1 == W ? "]\n" : ","); } } return (os); } T determinant(int n = -1) { if (n == -1) n = H; Matrix B(*this); T ret = 1; for (int i = 0; i < n; i++) { int idx = -1; for (int j = i; j < n; j++) { if (B[j][i] != 0) { idx = j; break; } } if (idx == -1) return 0; if (i != idx) { ret *= T(-1); swap(B[i], B[idx]); } ret *= B[i][i]; T inv = T(1) / B[i][i]; for (int j = 0; j < n; j++) { B[i][j] *= inv; } for (int j = i + 1; j < n; j++) { T a = B[j][i]; if (a == 0) continue; for (int k = i; k < n; k++) { B[j][k] -= B[i][k] * a; } } } return (ret); } }; using mint = atcoder::modint; using M = Matrix<mint, 3, 3>; int main() { FAST_IO int n, b; cin >> n >> b; mint::set_mod(b); M m; for (auto i : views::iota(0, 3)) { for (auto j : views::iota(0, 3)) { int x; cin >> x; m[i][j] = x; } } m = m^n; mint det = 0; for (auto i : views::iota(0,3)){ int j = (i + 1) % 3; int k = (i + 2) % 3; mint cur = m[0][i] * (m[1][j] * m[2][k] - m[1][k] * m[2][j]); det += cur; } cout << det.val() << endl; }