結果
問題 |
No.1136 Four Points Tour
|
ユーザー |
![]() |
提出日時 | 2020-07-29 23:20:06 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,366 bytes |
コンパイル時間 | 1,756 ms |
コンパイル使用メモリ | 175,592 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-30 13:05:15 |
合計ジャッジ時間 | 3,104 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 41 |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=(0);i<(n);i++) using namespace std; typedef long long ll; template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } const ll MOD = 1e9 + 7; typedef vector<vector<ll>> mat; void print(mat A){ rep(i, A.size()){ rep(j, A[i].size()){ cout << A[i][j] << (j == A[i].size()-1 ? "\n" : " "); } } } mat mmul(mat A, mat B){ int n = A.size(); int l = A[0].size(); int m = B[0].size(); mat C(n, vector<ll>(m, 0)); for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ for(int k = 0; k < l; k++){ C[i][j] += A[i][k] * B[k][j]; C[i][j] %= MOD; } } } return C; } mat mE(int n){ mat A(n, vector<ll>(n, 0)); for(int i = 0; i < n; i++){ A[i][i] = 1LL; } return A; } mat mpow(mat A, ll x){ int n = A.size(); if(x == 0) return mE(n); if(x % 2 == 1) return mmul(A, mpow(A, x - 1)); mat B = mpow(A, x / 2); return mmul(B, B); } int main(){ cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; mat x = mat(4, vector<ll>(1, 0)); x[0][0] = 1; x[1][0] = 0; x[2][0] = 0; x[3][0] = 0; mat A = mat(4, vector<ll>(4, 0)); rep(i, 4) rep(j, 4) A[i][j] = (i == j ? 0 : 1); A = mpow(A, n); x = mmul(A, x); cout << x[0][0] << endl; }