結果

問題 No.1105 Many Triplets
ユーザー 👑 NachiaNachia
提出日時 2020-10-19 17:45:22
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,011 bytes
コンパイル時間 1,591 ms
コンパイル使用メモリ 165,952 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-28 13:21:18
合計ジャッジ時間 2,795 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

const ULL M = 1000000007;
const int vector_dim = 3;

struct Vec{
 ULL X[vector_dim]={};

 ULL& operator[](int x){ return X[x]; }
 const ULL& operator[](int x)const{ return X[x]; }
};
Vec operator+(const Vec& l,const Vec& r){
 Vec res;
 rep(i,vector_dim){
  ULL x = l[i]+r[i];
  if(x>=M) x-=M;
  res[i]=x;
 }
 return res;
}
Vec operator-(const Vec& l,const Vec& r){
 Vec res;
 rep(i,vector_dim){
  ULL x = l[i]+M-r[i];
  if(x>=M) x-=M;
  res[i]=x;
 }
 return res;
}
ULL operator*(const Vec& l,const Vec& r){
 ULL res = 0;
 rep(i,vector_dim) res+=l[i]*r[i];
 res%=M;
 return res;
}

struct Matrix{
 ULL X[vector_dim][vector_dim]={};

 ULL* operator[](int x){ return X[x]; }
 const ULL* operator[](int x)const{ return X[x]; }

 static Matrix id(){ Matrix res; rep(i,vector_dim) res[i][i]=1; return res;}
 Matrix pow(ULL idx)const;
};

Matrix operator+(const Matrix& l,const Matrix& r){
 Matrix res;
 rep(i,vector_dim) rep(j,vector_dim){
  ULL x = l[i][j]+r[i][j];
  if(x>=M) x-=M;
  res[i][j]=x;
 }
 return res;
}
Matrix operator-(const Matrix& l,const Matrix& r){
 Matrix res;
 rep(i,vector_dim) rep(j,vector_dim){
  ULL x = l[i][j]+M+r[i][j];
  if(x>=M) x-=M;
  res[i][j]=x;
 }
 return res;
}
Matrix operator*(const Matrix& l,const Matrix& r){
 Matrix res;
 rep(i,vector_dim) rep(j,vector_dim){
  rep(k,vector_dim) res[i][j] += l[i][k] * r[k][j];
  res[i][j] %= M;
 }
 return res;
}
Matrix Matrix::pow(ULL idx)const{
  if(idx==0) return id();
  Matrix res = pow(idx/2); res=res*res;
  if(idx%2==1) res=res*(*this);
  return res;
 }
Vec operator*(const Vec& l,const Matrix& r){
 Vec res;
 rep(i,vector_dim){
  rep(j,vector_dim) res[i] += l[j] * r[j][i];
  res[i] %= M;
 }
 return res;
}

int main(){
 ULL N; cin>>N;

 Matrix G = {{{1,0,M-1},{M-1,1,0},{0,M-1,1}}};
 G = G.pow(N-1);

 Vec A; rep(i,3) cin>>A[i];
 A = A*G;

 cout<<A[0]<<" "<<A[1]<<" "<<A[2]<<endl;

 return 0;
}
0