結果

問題 No.1105 Many Triplets
ユーザー milanis48663220milanis48663220
提出日時 2020-07-03 22:17:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,487 bytes
コンパイル時間 1,114 ms
コンパイル使用メモリ 93,160 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 04:19:18
合計ジャッジ時間 1,909 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
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 WA -
testcase_07 AC 2 ms
4,348 KB
testcase_08 WA -
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 <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

template <typename T>
struct matrix{
    int n, m;
    vector<vector<T>> dat;
    matrix(int n_, int m_){
        n = n_; m = m_;
        for(int i = 0; i < n; i++){
            dat.push_back(vector<T>(m));
        }
    }
};

template <typename T>
bool prod(matrix<T> a, matrix<T> b, matrix<T> &ans){
    if(a.m != b.n) return false;
    for(int i = 0; i < a.n; i++){
        for(int j = 0; j < a.m; j++){
            ans.dat[i][j] = 0;
            for(int k = 0; k < b.m; k++){
                ans.dat[i][j] += (a.dat[i][k]*b.dat[k][j])%MOD;
                ans.dat[i][j] %= MOD;
            }
        }
    }
    return true;
}

template <typename T>
void copy_mat(matrix<T> a, matrix<T> &b){
    for(int i = 0; i < a.n; i++){
        for(int j = 0; j < a.m; j++){
            b.dat[i][j] = a.dat[i][j];
        }
    }
}

template <typename T>
void pow(matrix<T> a, ll n, matrix<T> &ans){
    matrix<T> buf(a.n, a.n);
    matrix<T> tmp(a.n, a.n);
    copy_mat(a, tmp);

    for(int i = 0; i < a.n; i++) {
        for(int j = 0; j < a.n; j++){
            ans.dat[i][j] = 0;
        }
        ans.dat[i][i] = 1;
    }
    
    for(int i = 0; i <= 60; i++){
        ll m = (ll)1 << i;
        if(m&n){
            prod(tmp, ans, buf);
            copy_mat(buf, ans);
        }
        prod(tmp, tmp, buf);
        copy_mat(buf, tmp);
    }
}

template <typename T>
void print_mat(matrix<T> a){
    for(int i = 0; i < a.n; i++){
        for(int j = 0; j < a.m; j++){
            cout << a.dat[i][j] << ' ';
        }
        cout << endl;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    ll N, a, b, c; cin >> N >> a >> b >> c;
    matrix<ll> mat(3, 3), buf(3, 3);
    mat.dat[0][0] = 1; mat.dat[0][1] = -1; mat.dat[0][2] = 0;
    mat.dat[1][0] = 0; mat.dat[1][1] = 1; mat.dat[1][2] = -1;
    mat.dat[2][0] = -1; mat.dat[2][1] = 0; mat.dat[2][2] = 1;
    pow<ll>(mat, N-1, buf);
    ll A = (buf.dat[0][0]*a)%MOD+(buf.dat[0][1]*b)%MOD+(buf.dat[0][2]*c)%MOD;
    A = (A+MOD)%MOD;
    ll B = (buf.dat[1][0]*a)%MOD+(buf.dat[1][1]*b)%MOD+(buf.dat[1][2]*c)%MOD;
    B = (B+MOD)%MOD;
    ll C = (buf.dat[2][0]*a)%MOD+(buf.dat[2][1]*b)%MOD+(buf.dat[2][2]*c)%MOD;
    C = (C+MOD)%MOD;
    cout << A << ' ' << B << ' ' << C << endl;
}
0