結果

問題 No.1448 和差算
ユーザー ytqm3
提出日時 2021-03-31 11:01:37
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 607 bytes
コンパイル時間 4,041 ms
コンパイル使用メモリ 250,304 KB
最終ジャッジ日時 2025-01-20 01:09:32
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 RE * 1
other AC * 29 RE * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
const long mod=1000000007;

long f(long a,long b,long N){
  for(int i=0;i<N;i++){
    a-=b;b+=a+b;
  }
  return a+b;
}

int main(){
  long A,B,C,D,N,ans;
  cin>>A>>B>>C>>D>>N;
  assert(A<=B);
  assert(C<=D);
  assert(abs(A)<=1e9);
  assert(abs(B)<=1e9);
  assert(abs(C)<=1e9);
  assert(abs(D)<=1e9);
  assert(0<=N);
  assert(N<=1e18);
  assert(N%8!=2);
  ans=max({f(A,C,N%8),f(A,D,N%8),f(B,C,N%8),f(B,D,N%8)})%mod*pow_mod(16,N/8,mod)%mod;
  if(ans<0){
    cout<<ans+mod<<endl;
  }
  else{
    cout<<ans<<endl;
  }
}
0