結果
問題 | No.1275 綺麗な式 |
ユーザー |
![]() |
提出日時 | 2020-10-30 23:47:30 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,095 bytes |
コンパイル時間 | 2,336 ms |
コンパイル使用メモリ | 193,600 KB |
最終ジャッジ日時 | 2025-01-15 18:08:16 |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 2 |
other | AC * 4 WA * 56 |
コンパイルメッセージ
main.cpp: In member function ‘matrix& matrix::operator*=(matrix)’: main.cpp:68:5: warning: no return statement in function returning non-void [-Wreturn-type] 67 | a = na; b = nb; c = nc; d = nd; +++ |+ return *this; 68 | } | ^
ソースコード
#include <bits/stdc++.h> // #include <atcoder/all> using namespace std; // using namespace atcoder; #define rep2(i,m,n) for (int i = (m); i < (n); ++i) #define rep(i,n) rep2(i,0,n) #define debug(x) cout << x << endl; typedef long long int ll; typedef long double ld; typedef pair<int, int> P; template<typename T> struct V : vector<T> { using vector<T>::vector; }; V() -> V<int>; V(size_t) -> V<int>; template<typename T> V(size_t, T) -> V<T>; template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); } template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); } template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; } struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } const int INF = 1<<30; const ll LINF = 1LL<<61; const ll MOD = 1000000007; // using mint = modint1000000007; struct mint { ll x; mint(ll x = 0) : x(x % MOD) {} mint& operator+=(const mint rh) { if((x += rh.x) >= MOD) x -= MOD; return *this; } mint& operator-=(const mint rh) { if((x += MOD-rh.x) >= MOD) x -= MOD; return *this; } mint& operator*=(const mint rh) { (x *= rh.x) %= MOD; return *this; } mint operator+(const mint rh) const { return mint(*this) += rh; } mint operator-(const mint rh) const { return mint(*this) -= rh; } mint operator*(const mint rh) const { return mint(*this) *= rh; } mint pow(ll k) const { if(!k) return 1; mint a = x; mint res = 1; while(k) { if(k & 1) res *= a; k >>= 1; a *= a; } return res; } mint inv() const { return pow(MOD-2); } mint& operator/=(const mint rh) { return *this *= rh.inv(); } mint operator/(const mint rh) { return mint(*this) /= rh; } }; //2*2正方行列 struct matrix { mint a, b, c, d; matrix(mint a, mint b, mint c, mint d) : a(a), b(b), c(c), d(d) {} matrix& operator*=(const matrix rh) { mint p = rh.a, q = rh.b, r = rh.c, s = rh.d; mint na, nb, nc, nd; na = a*p + b*r; nb = a*q + b*s; nc = c*p + d*r; nd = c*q + d*s; a = na; b = nb; c = nc; d = nd; } matrix operator*(const matrix rh) const { return matrix(*this) *= rh; } }; matrix power(matrix x, ll k) { if(k == 1) { return x; } matrix res = x; k--; while(k) { if(k & 1) res = (res * x); k >>= 1; x = (x * x); } return res; } int main() { ll a, b, n; cin >> a >> b >> n; mint a1(2), a2(2*a); matrix p = power(matrix(mint(2*a), mint(mint(b)-mint(a*a)), mint(1), mint(0)), n); mint ans = p.c * a2 + p.d * a1; cout << ans.x << endl; return 0; }