結果

問題 No.1105 Many Triplets
ユーザー DriceDrice
提出日時 2020-07-03 23:26:49
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,300 bytes
コンパイル時間 360 ms
コンパイル使用メモリ 33,836 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 06:23:00
合計ジャッジ時間 1,470 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 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 1 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 1 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 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
long long m[5][5];
long long b[5][5];
long long c[5][5];
long long a[5];
const long long mod = 1e9+7;

void mul(long long x[5][5],long long y[5][5],int n){
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            b[i][j] = 0;
            for(int k = 1; k <= n; k++){
                b[i][j] = (b[i][j]+x[i][k]*y[k][j]%mod)%mod;
                if(b[i][j]<0) b[i][j] += mod;
            }
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++) x[i][j] = b[i][j];
    }
}

void quickMul(int n,long long b){
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){ 
            c[i][j] = m[i][j];
            if(i==j) m[i][j] = 1;
            else m[i][j] = 0;
        }
    }
    while(b){
        if(b&1) mul(m,c,n);
        mul(c,c,n);
        b /= 2;
    }
}

int main(){
    m[1][1] = 1, m[1][2] = -1;
    m[2][2] = 1, m[2][3] = -1;
    m[3][3] = 1, m[3][1] = -1;
    long long n;
    scanf("%lld",&n);
    n--;
    for(int i = 1; i <= 3; i++) scanf("%lld",&a[i]);
    quickMul(3,n);
    for(int i = 1; i <= 3; i++){
        long long cur = 0;
        for(int j = 1; j <= 3; j++) cur = (cur+m[i][j]*a[j]%mod)%mod;
        if(cur<0) cur += mod;
        printf("%lld ",cur);
    }
    printf("\n");
    return 0;
}
0