結果

問題 No.950 行列累乗
ユーザー LeonardoneLeonardone
提出日時 2019-12-13 03:33:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,104 bytes
コンパイル時間 540 ms
コンパイル使用メモリ 65,656 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-08 12:24:31
合計ジャッジ時間 54,242 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1,263 ms
4,376 KB
testcase_02 WA -
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 WA -
testcase_06 AC 481 ms
4,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 19 ms
4,380 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 2 ms
4,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1 ms
4,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2 ms
4,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 1,292 ms
4,376 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 1,291 ms
4,376 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 1,293 ms
4,376 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 1,296 ms
4,380 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 1,293 ms
4,380 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 1,293 ms
4,376 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 1,291 ms
4,376 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 1,292 ms
4,376 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 AC 1,294 ms
4,380 KB
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 AC 2 ms
4,380 KB
testcase_56 WA -
testcase_57 AC 1 ms
4,380 KB
testcase_58 WA -
testcase_59 AC 1,290 ms
4,380 KB
testcase_60 AC 1,289 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

using namespace std;

void copy(long long *d, long long *s) {
    d[0]=s[0];d[1]=s[1];d[2]=s[2];d[3]=s[3];
}

bool equals(long long *a, long long *b) {
    return a[0]==b[0]&&a[1]==b[1]&&a[2]==b[2]&&a[3]==b[3];
}

void mul(long long *a, long long *c, long long p) {
    long long d[4];
    d[0] = (a[0] * c[0] % p + a[1] * c[2] % p) % p;
    d[1] = (a[0] * c[1] % p + a[1] * c[3] % p) % p;
    d[2] = (c[0] * a[2] % p + c[2] * a[3] % p) % p;
    d[3] = (c[1] * a[2] % p + c[3] * a[3] % p) % p;
    copy(a, d);
}

int main() {
    long long p, a[4], b[4], c[4];
    cin >> p;
    for (int i = 0; i < 4; i++) cin >> a[i];
    for (int i = 0; i < 4; i++) cin >> b[i];
    if (equals(a, b)) {
        cout << 1 << endl; return 0;
    }
    copy(c,a);
    for (int i=1; i <= 1e7; i++) {
        mul(a, c, p);
        if (equals(a, b)) {
            cout << i << endl;
            return 0;
        }
        if (equals(a, c)) {
            break;
        }
        // cout << a[0] << "," << a[1] << "," << a[2] << "," << a[3] << endl;
    }
    cout << (-1) << endl;
    
    return 0;
}
0