結果
問題 | No.978 Fibonacci Convolution Easy |
ユーザー | outline |
提出日時 | 2020-03-16 19:27:26 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 33 ms / 2,000 ms |
コード長 | 3,167 bytes |
コンパイル時間 | 1,395 ms |
コンパイル使用メモリ | 110,640 KB |
実行使用メモリ | 18,816 KB |
最終ジャッジ日時 | 2024-05-06 01:09:05 |
合計ジャッジ時間 | 2,508 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 13 ms
9,216 KB |
testcase_02 | AC | 7 ms
6,400 KB |
testcase_03 | AC | 30 ms
18,048 KB |
testcase_04 | AC | 9 ms
6,912 KB |
testcase_05 | AC | 3 ms
5,376 KB |
testcase_06 | AC | 11 ms
8,448 KB |
testcase_07 | AC | 19 ms
12,928 KB |
testcase_08 | AC | 14 ms
9,984 KB |
testcase_09 | AC | 22 ms
14,208 KB |
testcase_10 | AC | 30 ms
18,816 KB |
testcase_11 | AC | 10 ms
7,680 KB |
testcase_12 | AC | 3 ms
5,376 KB |
testcase_13 | AC | 12 ms
8,576 KB |
testcase_14 | AC | 5 ms
5,376 KB |
testcase_15 | AC | 13 ms
9,088 KB |
testcase_16 | AC | 33 ms
18,688 KB |
testcase_17 | AC | 31 ms
18,688 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 1 ms
5,376 KB |
testcase_20 | AC | 1 ms
5,376 KB |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <queue> #include <string> #include <map> #include <set> #include <stack> #include <tuple> #include <deque> #include <numeric> #include <bitset> #include <iomanip> #include <cassert> #include <chrono> #include <random> #include <limits> #include <iterator> #include <functional> #include <sstream> #include <complex> using namespace std; #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) typedef long long ll; typedef uint64_t ull; typedef pair<int, int> P; typedef pair<int, double> Pid; typedef pair<double, int> Pdi; typedef pair<ll, int> Pl; typedef pair<ll, ll> Pll; typedef pair<int, pair<int, int>> PP; typedef pair<P, int> PPi; constexpr double PI = 3.1415926535897932; // acos(-1) constexpr double EPS = 1e-9; constexpr int INF = 1001001001; constexpr int mod = 1e+9 + 7; // constexpr int mod = 998244353; template<int mod> struct ModInt{ int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p){ if((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p){ if((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p){ x = (int)(1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p){ *this *= p.inverse(); return *this; } ModInt operator-() const {return ModInt(-x);} ModInt operator+(const ModInt &p) const {return ModInt(*this) += p;} ModInt operator-(const ModInt &p) const {return ModInt(*this) -= p;} ModInt operator*(const ModInt &p) const {return ModInt(*this) *= p;} ModInt operator/(const ModInt &p) const {return ModInt(*this) /= p;} bool operator==(const ModInt &p) const {return x == p.x;} bool operator!=(const ModInt &p) const {return x != p.x;} ModInt inverse() const{ int a = x, b = mod, u = 1, v = 0, t; while(b > 0){ t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const{ ModInt ret(1), mul(x); while(n > 0){ if(n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p){ return os << p.x; } friend istream &operator>>(istream &is, ModInt &a){ int64_t t; is >> t; a = ModInt<mod>(t); return (is); } static int get_mod() {return mod;} }; using modint = ModInt<mod>; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n; modint p; cin >> n >> p; vector<modint> a(n); a[0] = 0, a[1] = 1; vector<modint> sum(n+1, 0); for(int i = 2; i < n; ++i) a[i] = p * a[i - 1] + a[i - 2]; for(int i = 0; i < n; ++i) sum[i + 1] = sum[i] + a[i]; modint ans = 0; for(int i = 0; i < n; ++i) ans += a[i] * (sum[n] - sum[i]); cout << ans << endl; }