結果
| 問題 | No.3226 2×2行列累乗 |
| コンテスト | |
| ユーザー |
ジュ・ビオレ・グレイス
|
| 提出日時 | 2025-07-18 02:05:22 |
| 言語 | D (dmd 2.112.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 852 bytes |
| 記録 | |
| コンパイル時間 | 2,454 ms |
| コンパイル使用メモリ | 122,752 KB |
| 実行使用メモリ | 5,888 KB |
| 最終ジャッジ日時 | 2026-07-13 09:46:36 |
| 合計ジャッジ時間 | 5,467 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 3 |
| other | RE * 27 |
コンパイルメッセージ
/home/linuxbrew/.linuxbrew/opt/dmd/include/dlang/dmd/core/checkedint.d(814): Warning: cannot inline function `core.checkedint.mulu!().mulu`
ulong mulu()(ulong x, uint y, ref bool overflow)
^
ソースコード
import std.stdio, std.algorithm, std.array, std.conv, std.typecons;
void main() {
long A, B, C, D, S, T, N, K;
readfln("%d %d %d %d %d %d %d %d", A, B, C, D, S, T, N, K);
auto mat = Matrix(A%K, B%K, C%K, D%K);
// calculate M^N
auto matN = Matrix(1, 0, 0, 1);
auto mat_pow = mat;
auto pow = 1UL;
while (pow <= N) {
if ((pow & N) != 0) matN = multiply(mat_pow, matN, K);
pow *= 2;
mat_pow = multiply(mat_pow, mat_pow, K);
}
auto R = matN[0]*S + matN[1]*T, U = matN[2]*S + matN[3]*T;
auto R2 = R % K, U2 = U % K;
if (R2 < 0) R2 += K;
if (U2 < 0) U2 += K;
writefln("%d %d", R2, U2);
}
// 0 1
// 2 3
alias Matrix = Tuple!(long, long, long, long);
Matrix multiply(Matrix a, Matrix b, long K) {
return Matrix( (a[0]*b[0] + a[1]*b[2]) % K, (a[0]*b[1] + a[1]*b[3]) % K, (a[2]*b[0] + a[3]*b[2]) % K, (a[2]*b[1] + a[3]*b[3]) % K);
}
ジュ・ビオレ・グレイス