結果

問題 No.1105 Many Triplets
ユーザー itohdakitohdak
提出日時 2020-07-04 00:22:41
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,469 bytes
コンパイル時間 2,437 ms
コンパイル使用メモリ 214,772 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 06:38:33
合計ジャッジ時間 3,548 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

vector<vector<ll>> matmul(vector<vector<ll>>& A,
                           vector<vector<ll>>& B) {
  int n = A.size();
  int m = B.size();
  int l = B[0].size();
  vector<vector<ll>> ret(n, vector<ll>(l));
  rep(i, n) rep(k, l) rep(j, m) ret[i][k] += A[i][j] * B[j][k];
  return ret;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  vector<vector<ll>> A(3, vector<ll>(1));
  cin >> n >> A[0][0] >> A[1][0] >> A[2][0];
  n--;
  vector<vector<ll>> M = {{ 1, -1,  0},
                          { 0,  1, -1},
                          {-1,  0,  1}};
  vector<vector<vector<ll>>> MM(60, vector<vector<ll>>(3, vector<ll>(3)));
  copy(all(M), begin(MM[0]));
  for(int i=1; i<60; i++) {
    MM[i] = matmul(MM[i-1], MM[i-1]);
    rep(j, 3) rep(k, 3) (MM[i][j][k] += mod) %= mod;
  }
  vector<vector<ll>> K = {{1, 0, 0},
                          {0, 1, 0},
                          {0, 0, 1}};
  rep(i, 60) if(n>>i&1) {
    K = matmul(K, MM[i]);
    rep(j, 3) rep(k, 3) (K[j][k] += mod) %= mod;
  }
  A = matmul(K, A);
  rep(i, 3) {
    cout << (A[i][0]+mod)%mod << ' ';
  }
  cout << "\n";
  return 0;
}
0