結果
問題 | No.44 DPなすごろく |
ユーザー | なお |
提出日時 | 2014-10-27 08:55:57 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,235 bytes |
コンパイル時間 | 1,458 ms |
コンパイル使用メモリ | 156,856 KB |
実行使用メモリ | 4,384 KB |
最終ジャッジ日時 | 2023-08-28 23:09:50 |
合計ジャッジ時間 | 2,471 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 1 ms
4,376 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 1 ms
4,380 KB |
testcase_04 | AC | 1 ms
4,380 KB |
testcase_05 | AC | 1 ms
4,380 KB |
testcase_06 | AC | 2 ms
4,376 KB |
testcase_07 | AC | 2 ms
4,380 KB |
testcase_08 | AC | 1 ms
4,380 KB |
testcase_09 | AC | 1 ms
4,376 KB |
testcase_10 | AC | 1 ms
4,384 KB |
testcase_11 | AC | 2 ms
4,384 KB |
testcase_12 | AC | 2 ms
4,380 KB |
testcase_13 | AC | 2 ms
4,380 KB |
testcase_14 | AC | 1 ms
4,380 KB |
testcase_15 | AC | 1 ms
4,376 KB |
testcase_16 | AC | 1 ms
4,380 KB |
testcase_17 | AC | 2 ms
4,380 KB |
testcase_18 | AC | 2 ms
4,376 KB |
testcase_19 | AC | 2 ms
4,376 KB |
testcase_20 | AC | 1 ms
4,380 KB |
testcase_21 | AC | 1 ms
4,380 KB |
testcase_22 | AC | 1 ms
4,376 KB |
testcase_23 | AC | 1 ms
4,376 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; template<class _Tc>class Matrix{private:unsigned int r,c;vector<vector<_Tc>>v;public:unsigned int rows(){return r;}unsigned int columns(){return c;}unsigned int size(){return r*c;}Matrix(unsigned int rows,unsigned int columns):r(rows),c(columns){v.resize(rows);for(unsigned int i=0;i<rows;++i)v[i].resize(columns);}vector<_Tc>&operator[](unsigned int row){return v[row];}const Matrix&operator*=(const Matrix&m){if(c!=m.r)throw;Matrix n(r,m.c);for(unsigned int i=0;i<r;++i)for(unsigned int j=0;j<m.c;++j)for(unsigned int k=0;k<c;++k)n.v[i][j]+=v[i][k]*m.v[k][j];return*this=n;}const Matrix&operator*=(const _Tc &m){for(unsigned int i=0;i<r;++i)for(unsigned int j=0;j<c;++j)v[i][j]*=m;return*this;}static const Matrix unit(unsigned int s,_Tc v=1){Matrix n(s,s);for(unsigned int i=0;i<s;++i)n.v[i][i]=v;return n;}const Matrix pow(unsigned int p)const{if(c!=r)throw;Matrix n=Matrix::unit(r),m=*this;while(p>0){if(p&1)n*=m;m*=m;p>>=1;}return n;}}; long long fib(int n){ Matrix<long long> a(2,2); a[0][0] = a[0][1] = a[1][0] = 1; a[1][1] = 0; a = a.pow(n); return a[1][0]; } int main(){ int n; cin >> n; cout << fib(n+1) << endl; return 0; }