結果
問題 | No.801 エレベーター |
ユーザー |
![]() |
提出日時 | 2019-03-17 22:45:23 |
言語 | C++11 (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,823 bytes |
コンパイル時間 | 715 ms |
コンパイル使用メモリ | 91,056 KB |
実行使用メモリ | 500,480 KB |
最終ジャッジ日時 | 2024-07-08 01:05:01 |
合計ジャッジ時間 | 20,726 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 TLE * 1 -- * 15 |
ソースコード
#include <cstdio> #include <cstdlib> #include <cmath> #include <climits> #include <cassert> #include <iostream> #include <iomanip> #include <string> #include <stack> #include <queue> #include <vector> #include <map> #include <set> #include <algorithm> #include <numeric> #include <bitset> #define all(c) c.begin(), c.end() #define rall(c) c.rbegin(), c.rend() #define debug(x) cerr << #x << ": " << x << endl using namespace std; typedef long long ll; typedef pair<ll, ll> Pll; typedef pair<int, int> Pii; const ll MOD = 1000000007; vector< vector<ll> > product(vector< vector<ll> > A, vector< vector<ll> > B){ int height = A.size(), width = B[0].size(), n = B.size(); vector< vector<ll> > C(height, vector<ll>(width, 0)); for(int i=0;i<height;++i){ for(int j=0;j<width;++j){ for(int k=0;k<n;++k){ C[i][j] += (A[i][k] * B[k][j]) % MOD; C[i][j] %= MOD; } } } return C; } vector< vector<ll> > matrix_pow(vector< vector<ll> > A, ll t) { int n = A.size(); vector< vector<ll> > B(n, vector<ll>(n, 0)); for(int i=0;i<n;++i) B[i][i] = 1; while(t){ if(t & 1){ B = product(B, A); } A = product(A, A); t >>= 1; } return B; } int main() { int n,m,K,l,r; cin >> n >> m >> K; vector< vector<ll> > A(n, vector<ll>(n, 0LL)); for(int i=1;i<=m;++i) { cin >> l >> r; --l; --r; for(int j=l;j<=r;++j) { ++A[j][l]; if(r+1 < n) --A[j][r+1]; } } for(int i=0;i<n;++i) { for(int j=1;j<n;++j) { A[i][j] += A[i][j-1]; } } vector< vector<ll> > B(n, vector<ll>(n, 0LL)); B[0][0] = 1LL; vector< vector<ll> > AA = matrix_pow(A, K); vector< vector<ll> > C = product(B, AA); cout << C[0][n-1] << "\n"; }