結果

問題 No.1105 Many Triplets
ユーザー hiro71687khiro71687k
提出日時 2023-03-10 20:01:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,241 bytes
コンパイル時間 4,516 ms
コンパイル使用メモリ 266,544 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-18 06:47:50
合計ジャッジ時間 6,023 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
using ld=long double;
ld pie=3.141592653589793;
ll inf=155550555555555;
ll mod=1000000007;
ll modpow(ll x, ll n) {
  x = x%mod;
  if(n==0) return 1;  //再帰の終了条件

  else if(n%2==1) {
    return (x*modpow(x, n-1))%mod;  //nが奇数ならnを1ずらす
  }
  else return modpow((x*x)%mod, n/2)%mod;  //nが偶数ならnが半分になる
}
int main(){
    ll n;
    cin >> n;
    ll a,b,c;
    cin >> a >> b >> c;
    n-=2;
    vector<tuple<ll,ll,ll>>t(6);
    t[0]={a-b,b-c,c-a};
    t[1]={a-2*b+c,a+b-2*c,-2*a+b+c};
    t[2]={-3*b+3*c,3*a-3*c,3*b-3*a};
    t[3]={-3*a-3*b+6*c,6*a-3*b-3*c,-3*a+6*b-3*c};
    t[4]={-9*a+9*c,9*a-9*b,9*b-9*c};
    t[5]={-18*a+9*b+9*c,9*a-18*b+9*c,9*a+9*b-18*c};
    for (ll i = 0; i < t.size(); i++)
    {
        get<0>(t[i])%=mod;
        get<1>(t[i])%=mod;
        get<2>(t[i])%=mod;
    }
    ll z=n/6;
    ll x=modpow(-27,z);
    x+=mod;
    x%=mod;
    n%=6;
    z=n;
    ll aa=(get<0>(t[z])*x)%mod,bb=(get<1>(t[z])*x)%mod ,cc=(get<2>(t[z])*x)%mod;
    aa+=mod;
    aa%=mod;
    bb+=mod;
    bb%=mod;
    cc+=mod;
    cc%=mod;
    cout << aa << ' ' << bb << ' ' << cc << endl;
}
0