結果

問題 No.1448 和差算
ユーザー 蜜蜂
提出日時 2021-04-01 16:15:25
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,092 bytes
コンパイル時間 3,540 ms
コンパイル使用メモリ 228,464 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-17 19:45:30
合計ジャッジ時間 4,696 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

//g++ 2.cpp -std=c++14 -I .
#include <bits/stdc++.h>
using namespace std;

#include <atcoder/all>
using namespace atcoder;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vld = vector<ld>;
using vvld = vector<vld>;

#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(),a.end()
#define rep(i,start,end) for(ll i=start;i<(ll)(end);i++)
#define per(i,start,end) for(ll i=start;i>=(ll)(end);i--)

constexpr ll mod = 1e9+7;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ll a,b,c,d,n;
  cin>>a>>b>>c>>d>>n;

  ll z=n%8;

  ll ans=-1e18;
  rep(i,0,2){
    rep(j,0,2){
      ll a0,b0;

      if(i==0){
        a0=a;
      }
      else{
        a0=b;
      }

      if(j==0){
        b0=c;
      }
      else{
        b0=d;
      }

      rep(k,0,z){
        ll p=a0-b0,q=a0+b0;
        a0=p,b0=q;
      }

      ans=max(ans,a0+b0);
    }
  }

  ans%=mod;
  if(ans<0){
    ans+=mod;
  }
  ans*=pow_mod(16,n/8,mod);
  ans%=mod;

  cout<<ans<<endl;
}
0