結果

問題 No.1105 Many Triplets
ユーザー soto800soto800
提出日時 2020-07-04 16:54:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,361 bytes
コンパイル時間 1,650 ms
コンパイル使用メモリ 170,980 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 08:24:52
合計ジャッジ時間 2,682 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
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 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
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 <bits/stdc++.h>
using namespace std;

#define lli long long int
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<62)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

/* https://kmjp.hatenablog.jp/entry/2020/05/08/0900 */
lli mo=1000000007;
const int MAT=3;
struct Mat { lli v[MAT][MAT]; Mat(){
    REP(i,0,MAT)REP(j,0,MAT)v[i][j]=0;
    };
};

Mat mulmat(Mat& a,Mat& b,int n=MAT) {
    lli mo2=4*mo*mo;
    int x,y,z; Mat r;
    REP(x,0,n) REP(y,0,n) r.v[x][y]=0;
    REP(x,0,n) REP(z,0,n) REP(y,0,n) {
        r.v[x][y] += a.v[x][z]*b.v[z][y];
        if(r.v[x][y]>mo2) r.v[x][y] -= mo2;
    }
    REP(x,0,n) REP(y,0,n) r.v[x][y]%=mo;
    return r;
}

Mat powmat(lli p,Mat a,int n=MAT) {
    int i,x,y; Mat r;
    REP(x,0,n) REP(y,0,n) r.v[x][y]=0;
    REP(i,0,n) r.v[i][i]=1;
    while(p) {
        if(p%2) r=mulmat(r,a,n);
        a=mulmat(a,a,n);
        p>>=1;
    }
    return r;
}

lli modpow(lli a, lli n = mo-2) {
    lli r=1;
    while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
    return r;
}

int M,K;

void solve() {
    int i,j,k,l,r,x,y; string s;
    
    lli n;
    cin>>n;
    Mat A;
    A.v[0][0]=1;
    A.v[0][1]=mo-1;
    A.v[0][2]=0;
    A.v[1][0]=0;
    A.v[1][1]=1;
    A.v[1][2]=mo-1;
    A.v[2][0]=mo-1;
    A.v[2][1]=0;
    A.v[2][2]=1;
    
    Mat B=powmat(n-1,A);

    vector<lli> vv(3);
    REP(i,0,3)cin>>vv[i];

    REP(i,0,3){
        LOG2(i,vv[i]);
        lli num = 0;
        REP(j,0,3){
            num = num + vv[j]*B.v[i][j];
            LOG(num);
            num %= mo;
        }
        cout<<num<<" ";
    }
    cout<<endl;
}

int main(){

    solve();

    return 0;
}
0