結果

問題 No.1105 Many Triplets
ユーザー SSRSSSRS
提出日時 2020-07-03 21:47:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,276 bytes
コンパイル時間 1,774 ms
コンパイル使用メモリ 178,648 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 00:28:33
合計ジャッジ時間 3,995 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 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 1 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;
long long MOD = 1000000007;
vector<vector<long long>> matrix_multiplication(vector<vector<long long>> &A, vector<vector<long long>> &B){
  int N = A.size();
  int M = B.size();
  int K = B[0].size();
  vector<vector<long long>> ans(N, vector<long long>(K, 0));
  for (int i = 0; i < N; i++){
    for (int j = 0; j < M; j++){
      for (int k = 0; k < K; k++){
        ans[i][k] += A[i][j] * B[j][k];
        ans[i][k] %= MOD;
      }
    }
  }
  return ans;
}
vector<vector<long long>> matrix_exponentiation(vector<vector<long long>> A, long long M){
  int N = A.size();
  vector<vector<long long>> ans(N, vector<long long>(N, 0));
  for (int i = 0; i < N; i++){
    ans[i][i] = 1;
  }
  while (M > 0){
    if (M % 2 == 1){
      ans = matrix_multiplication(ans, A);
    }
    A = matrix_multiplication(A, A);
    M /= 2;
  }
  return ans;
}
int main(){
  long long N;
  cin >> N;
  long long A, B, C;
  cin >> A >> B >> C;
  vector<vector<long long>> M = {{1, MOD - 1, 0}, {0, 1, MOD - 1}, {MOD - 1, 0, 1}};
  M = matrix_exponentiation(M, N - 1);
  vector<vector<long long>> F = {{A}, {B}, {C}};
  vector<vector<long long>> ans = matrix_multiplication(M, F);
  cout << ans[0][0] << ' ' << ans[1][0] << ' ' << ans[2][0] << endl;
}
0