結果
問題 | No.1105 Many Triplets |
ユーザー | merom686 |
提出日時 | 2020-07-03 21:56:23 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,699 bytes |
コンパイル時間 | 793 ms |
コンパイル使用メモリ | 88,800 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-17 00:42:23 |
合計ジャッジ時間 | 1,453 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 1 ms
6,944 KB |
testcase_03 | AC | 1 ms
6,940 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,940 KB |
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 | AC | 2 ms
6,940 KB |
testcase_21 | AC | 2 ms
6,940 KB |
testcase_22 | AC | 1 ms
6,944 KB |
testcase_23 | AC | 1 ms
6,944 KB |
testcase_24 | AC | 1 ms
6,940 KB |
testcase_25 | AC | 1 ms
6,944 KB |
testcase_26 | AC | 1 ms
6,944 KB |
testcase_27 | AC | 1 ms
6,940 KB |
ソースコード
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cstdio> #include <cstring> #include <cmath> using namespace std; using ll = long long; struct ModInt { ModInt() : i(0) {} ModInt(ll k) : i(k % Mod) {} ModInt operator+(ModInt m) const { ModInt r; r.i = i + m.i; if (r.i >= Mod) r.i -= Mod; return r; } ModInt operator-(ModInt m) const { ModInt r; r.i = i - m.i; if (r.i < 0) r.i += Mod; return r; } ModInt operator*(ModInt m) const { ModInt r; r.i = (ll)i * m.i % Mod; return r; } ModInt &operator+=(ModInt m) { i += m.i; if (i >= Mod) i -= Mod; return *this; } ModInt &operator-=(ModInt m) { i -= m.i; if (i < 0) i += Mod; return *this; } ModInt &operator*=(ModInt m) { i = (ll)i * m.i % Mod; return *this; } ModInt operator-() const { ModInt r; r.i = i == 0 ? 0 : Mod - i; return r; } ModInt pow(ll k) const { ModInt r = 1, t = *this; for (; k != 0; k /= 2) { if (k & 1) r *= t; t *= t; } return r; } ////Modが素数のときのみ //ModInt inv() const { // return pow(Mod - 2); //} //ModInt operator/(ModInt m) const { // return *this * m.inv(); //} //ModInt &operator/=(ModInt m) { // return *this *= m.inv(); //} constexpr static inline int Mod = 1000000007; int i; }; template <class T, int N> struct ColumnVector { struct SquareMatrix { static SquareMatrix E() { SquareMatrix r; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { r.a[i][j] = i == j; } } return r; } ColumnVector operator*(const ColumnVector &v) const { ColumnVector r; for (int i = 0; i < N; i++) { T t = 0; for (int k = 0; k < N; k++) { t += a[i][k] * v.a[k]; } r.a[i] = t; } return r; } SquareMatrix operator*(const SquareMatrix &x) const { SquareMatrix r; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { T t = 0; for (int k = 0; k < N; k++) { t += a[i][k] * x.a[k][j]; } r.a[i][j] = t; } } return r; } SquareMatrix pow(ll k) const { SquareMatrix r = E(), t = *this; for (; k != 0; k /= 2) { if (k & 1) r = r * t; t = t * t; } return r; } void print() const { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { cout << a[i][j].i << " \n"[j == N - 1]; } } } T a[N][N]; }; void print() const { for (int i = 0; i < N; i++) { cout << a[i].i << " \n"[i == N - 1]; } } T a[N]; }; int main() { int n; cin >> n; ColumnVector<ModInt, 3> v; decltype(v)::SquareMatrix x; int p[3] = { 1, ModInt::Mod - 1, 0 }; for (int i = 0; i < 3; i++) { cin >> v.a[i].i; for (int j = 0; j < 3; j++) { x.a[i][(j + i) % 3] = p[j]; } } v = x.pow(n - 1) * v; cout << v.a[0].i << ' ' << v.a[1].i << ' ' << v.a[2].i << endl; return 0; }