結果

問題 No.1105 Many Triplets
ユーザー Y17Y17
提出日時 2020-07-04 01:17:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,244 bytes
コンパイル時間 1,802 ms
コンパイル使用メモリ 175,968 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 06:54:57
合計ジャッジ時間 2,829 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 int long long
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 (b<a) { a=b; return 1; } return 0; }

#define MOD 1000000007

typedef vector<int> vec;
typedef vector<vec> mat;

mat mul(mat a, mat b){
	mat c(a.size(), vec(b[0].size(), 0));
	for(int i = 0;i < a.size();i++){
		for(int k = 0;k < b.size();k++){
			for(int j = 0;j < b[0].size();j++){
				c[i][j] = (c[i][j] + a[i][k]*b[k][j]%MOD) % MOD;
			}
		}
	}
	return c;
}

mat pow_mat(mat a, int n){
	mat b(a.size(), vec(a.size()));
	for(int i = 0;i < a.size();i++){
		b[i][i] = 1;
	}

	while(n > 0){
		if(n & 1) b = mul(b, a);
		a = mul(a, a);
		n >>= 1;
	}
	return b;
}

signed main(){
	int n;
	cin >> n;
	int a, b, c;
	cin >> a >> b >> c;
	mat x(3, vec(3, 0));


	x[0][0] = x[1][1] = x[2][2] = 1;
	x[0][1] = x[1][2] = x[2][0] = MOD-1;

	x = pow_mat(x, n-1);

	int ans[3]= {
		(x[0][0] * a % MOD + x[0][1]*b % MOD + x[0][2]*c % MOD) % MOD,
		(x[1][0] * a % MOD + x[1][1]*b % MOD + x[1][2]*c % MOD) % MOD,
		(x[2][0] * a % MOD + x[2][1]*b % MOD + x[2][2]*c % MOD) % MOD
	};
	cout << ans[0] << " " << ans[1] << " " << ans[2] << endl;
	return 0;
}
0