結果
| 問題 | No.1105 Many Triplets | 
| コンテスト | |
| ユーザー |  Nachia | 
| 提出日時 | 2020-10-19 17:45:22 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 2,011 bytes | 
| コンパイル時間 | 1,417 ms | 
| コンパイル使用メモリ | 168,084 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-07-21 08:00:08 | 
| 合計ジャッジ時間 | 2,339 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 25 | 
ソースコード
#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;
}
            
            
            
        