結果

問題 No.1105 Many Triplets
ユーザー shibh308shibh308
提出日時 2020-06-02 20:56:53
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,192 bytes
コンパイル時間 2,229 ms
コンパイル使用メモリ 208,452 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-13 03:18:45
合計ジャッジ時間 3,249 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 1 ms
4,352 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 1 ms
4,352 KB
testcase_21 AC 2 ms
4,352 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 1 ms
4,352 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 2 ms
4,352 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

const int64_t mod = 1000000007;

vector<vector<int>> mul(vector<vector<int>>& x, vector<vector<int>>& y){
    vector<vector<int>> z(3, vector<int>(3, 0));
    for(int i = 0; i < 3; ++i)
        for(int j = 0; j < 3; ++j)
            for(int k = 0; k < 3; ++k)
                z[i][j] = (z[i][j] + 1LL * x[i][k] * y[k][j] + mod) % mod;
    return z;
}


signed main(){
    long long n;
    long long a, b, c;

    scanf("%lld%lld%lld%lld", &n, &a, &b, &c);

    --n;

    vector<vector<vector<int>>> ar(63, vector<vector<int>>(3, vector<int>(3)));
    ar[0] = {
            {1, 0, -1},
            {-1, 1, 0},
            {0, -1, 1},
    };

    for(int k = 0; k < 62; ++k)
        ar[k + 1] = mul(ar[k], ar[k]);

    vector<vector<int>> v(3, vector<int>(3, 0));
    v[0][0] = v[1][1] = v[2][2] = 1;

    for(int k = 0; k < 63; ++k)
        if(n & (1uLL << k))
            v = mul(v, ar[k]);

    long long na = (a * v[0][0] + b * v[1][0] + c * v[2][0]) % mod;
    long long nb = (a * v[0][1] + b * v[1][1] + c * v[2][1]) % mod;
    long long nc = (a * v[0][2] + b * v[1][2] + c * v[2][2]) % mod;

    printf("%lld %lld %lld\n", na, nb, nc);

}
0