結果
問題 |
No.1136 Four Points Tour
|
ユーザー |
![]() |
提出日時 | 2022-09-29 03:56:17 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,543 bytes |
コンパイル時間 | 2,022 ms |
コンパイル使用メモリ | 207,644 KB |
最終ジャッジ日時 | 2025-02-07 18:08:49 |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 41 |
ソースコード
#include <bits/stdc++.h> #define all(x) begin(x), end(x) using namespace std; using i32 = int; using i64 = long long; using ld = long double; template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {return a < b and (a = b, true);} template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {return a > b and (a = b, true);} const i64 supl = LONG_LONG_MAX / 2 - 100; const i32 supi = INT_MAX / 2 - 100; const i32 mod = 1000000007; vector<vector<i64>> mul(vector<vector<i64>>& a, vector<vector<i64>>& b) { assert(a[0].size() == b.size()); vector res(a.size(), vector(b[0].size(), 0LL)); for (size_t i = 0 ; i < a.size() ; i++) { for (size_t j = 0 ; j < b[0].size() ; j++) { for (size_t k = 0 ; k < a[0].size() ; k++) { res[i][j] += (a[i][k] * b[k][j]) % mod; res[i][j] %= mod; } } } return res; } void main_() { i64 n; cin >> n; const i32 lg = 64; vector dob(lg, vector(4, vector(4, 0LL))); dob[0] = { { 0, 1, 1, 1 }, { 1, 0, 1, 1 }, { 1, 1, 0, 1 }, { 1, 1, 1, 0 } }; for (i32 i = 0 ; i + 1 < lg ; i++) { dob[i + 1] = mul(dob[i], dob[i]); } vector mat(4, vector(4, 0LL)); for (i32 i = 0 ; i < 4 ; i++) { mat[i][i] = 1; } for (i32 i = 0 ; i < lg ; i++) { if (n & (1LL << i)) { mat = mul(mat, dob[i]); } } cout << mat[0][0] << endl; } int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); main_(); return 0; }