結果

問題 No.1253 雀見椪
ユーザー 👑 NachiaNachia
提出日時 2020-10-09 21:40:38
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 930 ms / 2,000 ms
コード長 1,289 bytes
コンパイル時間 1,450 ms
コンパイル使用メモリ 166,872 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 15:49:29
合計ジャッジ時間 11,433 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 49 ms
4,380 KB
testcase_04 AC 927 ms
4,376 KB
testcase_05 AC 925 ms
4,376 KB
testcase_06 AC 902 ms
4,380 KB
testcase_07 AC 919 ms
4,376 KB
testcase_08 AC 918 ms
4,384 KB
testcase_09 AC 920 ms
4,376 KB
testcase_10 AC 916 ms
4,380 KB
testcase_11 AC 914 ms
4,376 KB
testcase_12 AC 930 ms
4,376 KB
testcase_13 AC 916 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

const ULL M = 1000000007;
ULL powm(ULL a, ULL i) {
	if (i == 0) return 1;
	ULL ans = powm(a * a % M, i / 2);
	if (i & 1) ans = ans * a % M;
	return ans;
}
ULL invm(ULL a) { return powm(a, M - 2); }

struct Matrix {
	ULL A[8][8] = {};
};

Matrix MatrixId() {
	Matrix ans;
	rep(i, 8) ans.A[i][i] = 1;
	return ans;
}
Matrix operator*(Matrix a, Matrix b) {
	Matrix ans;
	rep(i, 8) rep(j, 8) rep(k, 8) ans.A[i][j] = (ans.A[i][j] + a.A[i][k] * b.A[k][j]) % M;
	return ans;
}
Matrix operator^(Matrix a, ULL i) {
	if (i == 0) return MatrixId();
	Matrix ans =(a * a) ^ (i / 2);
	if (i & 1) ans = ans * a;
	return ans;
}

Matrix Janken(ULL goo, ULL choki, ULL pah) {
	Matrix ans;
	rep(i, 8) {
		ans.A[i][i | 1] = (ans.A[i][i | 1] + goo) % M;
		ans.A[i][i | 2] = (ans.A[i][i | 2] + choki) % M;
		ans.A[i][i | 4] = (ans.A[i][i | 4] + pah) % M;;
	}
	return ans;
}

int main() {
	int T; cin >> T;
	while (T--) {
		ULL N; cin >> N;
		ULL P[3];
		rep(i, 3) { ULL a, b; cin >> a >> b; P[i] = a * invm(b) % M; }
		Matrix X = Janken(P[0], P[1], P[2]) ^ N;
		ULL ans = X.A[0][1] + X.A[0][2] + X.A[0][4] + X.A[0][7];
		ans %= M;
		cout << ans << endl;
	}
	return 0;
}
0