結果

問題 No.1105 Many Triplets
ユーザー fastmathfastmath
提出日時 2020-07-03 22:14:59
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,160 bytes
コンパイル時間 1,639 ms
コンパイル使用メモリ 170,260 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 04:11:23
合計ジャッジ時間 2,631 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 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 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 int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cout << #x << ": " << x << '\n';

const int N = 3, MOD = 1000 * 1000 * 1000 + 7;

int mod(int n) {
    n %= MOD;
    if (n < 0)
        return n + MOD;
    else
        return n;
}   
void add(int &a, int b) {
    a = mod(a + b);
}   

void clear(int a[N][N], bool t) {
    for (int i = 0; i < N; ++i)
        for (int j = 0; j < N; ++j)
            a[i][j] = t * (i == j);
}   
void cop(int a[N][N], int b[N][N]) {
    for (int i = 0; i < N; ++i)
        for (int j = 0; j < N; ++j)
            a[i][j] = b[i][j];
}   
int t[N][N];
void add(int a[N][N], int b[N][N]) {
    clear(t, 0);
    for (int i = 0; i < N; ++i)
        for (int j = 0; j < N; ++j)
            for (int k = 0; k < N; ++k)
                add(t[i][j], a[i][k] * b[k][j]);
    cop(a, t);
}   
void print(int a[N][N]) {
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) 
            cout << a[i][j] << ' ';
        cout << '\n';
    }   
    cout << '\n';
}
int ans[N][N], cur[N][N];
void fp(int a[N][N], int p) {
    cop(cur, a);
    clear(ans, 1);
    for (int i = 0; (1ll << i) <= p; ++i) {
        if ((p >> i) & 1) 
            add(ans, cur);
        add(cur, cur);
    }       
    cop(a, ans);
}   


int mat[3][3];
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    
    int n;
    cin >> n;

    vector <int> s(3);
    for (int i = 0; i < 3; ++i)
        cin >> s[i];

    mat[0][0] = 1;
    mat[1][1] = 1;
    mat[2][2] = 1;

    mat[1][0] = -1;
    mat[2][1] = -1;
    mat[0][2] = -1;

    fp(mat, n - 1);

    for (int i = 0; i < 3; ++i) {
        int ans = 0;
        for (int from = 0; from < 3; ++from) {
            add(ans, s[from] * mat[from][i]);
        }   
        cout << ans << ' ';
    }   
    cout << endl;
}
0