結果

問題 No.1105 Many Triplets
ユーザー lynmisakura
提出日時 2020-07-03 21:49:10
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,479 bytes
コンパイル時間 3,550 ms
コンパイル使用メモリ 193,116 KB
最終ジャッジ日時 2025-01-11 14:26:54
ジャッジサーバーID
(参考情報)
judge2 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i = 0;i < n;i++)
using ll = long long;

/*
 * Modint struct
 * library author : @snuke
 * */
const int mod = 1e9 + 7;
struct mint {
  long long x; // typedef long long ll;
  mint(long long x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) { if((x+=a.x)>=mod)x-=mod;return *this;}
  mint& operator-=(const mint a) { if((x+=mod-a.x)>=mod)x-=mod; return *this;}
  mint& operator*=(const mint a) { (x *=a.x)%=mod; return *this;}
  mint operator+(const mint a) const { mint res(*this);return res+=a;}
  mint operator-(const mint a) const { mint res(*this);return res-=a;}
  mint operator*(const mint a) const { mint res(*this);return res*=a;}
  mint pow(ll t) const {
    if (!t) return 1;mint a = pow(t>>1);a*=a;
    if (t&1) a *= *this;return a;
  }
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return (*this) *= a.inv();}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint v[3];
int main(void){
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n;cin >> n;
  rep(i,3){
    ll x;cin >> x;
    v[i] = x;
  }
  n--;
  ll x = n / 6,y = n % 6;
  
  rep(i,3) v[i] *= mint(-27).pow(x);

  rep(i,y){
    mint tmp[3];
    rep(j,3) tmp[j] = v[j];
    rep(j,3) v[j] = tmp[j] - tmp[(j+1) % 3];
  }
  cout << v[0] << ' ' << v[1] << ' ' << v[2] << '\n';
  return 0;
}
0