結果

問題 No.1105 Many Triplets
ユーザー CleyLCleyL
提出日時 2022-08-20 22:02:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,628 bytes
コンパイル時間 554 ms
コンパイル使用メモリ 72,860 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-17 19:37:45
合計ジャッジ時間 1,440 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
using namespace std;
struct d{
    long long a,b,c;
};

d operator*(d a,d b){
    return {a.a*b.a,a.b*b.b,a.c*b.c};
}
d operator%(d a,long long b){
    return {a.a%b,a.b%b,a.c%b};
}

long long operator*(long long a, d b){
    return a*(b.a+b.b+b.c);
}
istream& operator>>(istream& in, d a){
    in>>a.a>>a.b>>a.c;
    return in;
}
ostream& operator<<(ostream& out, d a){
    out<<"("<<a.a<<", "<<a.b<<", "<<a.c<<")";
    return out;
}
long long MOD = 1000000007;
template <typename T>
T uPow(T z,T n, T mod){
  T ans = 1;
  while(n != 0){
    if(n%2){
      ans*=z;
      if(mod)ans%=mod;
    }
    n >>= 1;
    z*=z;
    if(mod)z%=mod;
  }
  return ans;
}
d pat_a[6] = {{1,-1,0},{0,-1,1},{-1,0,1},{-1,1,0},{0,1,-1},{1,0,-1}};
d pat_b[6] = {{1,-2,1},{-1,-1,2},{-2,1,1},{-1,2,-1},{1,1,-2},{2,-1,-1}};
int main(){
    long long n;cin>>n;
    d A;
    cin>>A.a>>A.b>>A.c;
    if(n%2){

        long long x = ((n-3)/2)%6;
        long long y = (n-3)/2;
        long long k = uPow(3LL,y,MOD);
        d d = {(k*(A*pat_b[x])%MOD)%MOD,(k*(A*pat_b[(x+4)%6])%MOD)%MOD,(k*(A*pat_b[(x+2)%6])%MOD)%MOD};
        if(d.a < 0)d.a+=MOD;
        if(d.b < 0)d.b+=MOD;
        if(d.c < 0)d.c+=MOD;
        cout << d.a << " " << d.b << " " << d.c << endl;
    }else{
        long long x = ((n-2)/2)%6;
        long long y = (n-2)/2;
        long long k = uPow(3LL,y,MOD);
        d d = {(k*(A*pat_a[x])%MOD)%MOD,(k*(A*pat_a[(x+4)%6])%MOD)%MOD,(k*(A*pat_a[(x+2)%6])%MOD)%MOD};
        if(d.a < 0)d.a+=MOD;
        if(d.b < 0)d.b+=MOD;
        if(d.c < 0)d.c+=MOD;
        cout << d.a << " " << d.b << " " << d.c << endl;
    }
}
0