結果
問題 | No.1275 綺麗な式 |
ユーザー |
![]() |
提出日時 | 2020-10-30 23:08:57 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,449 bytes |
コンパイル時間 | 1,700 ms |
コンパイル使用メモリ | 173,240 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-22 02:46:34 |
合計ジャッジ時間 | 3,237 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 14 WA * 46 |
ソースコード
#include<bits/stdc++.h>using namespace std;typedef long long ll;typedef pair<int,int> P;#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n";} while(0)#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}const char newl = '\n';ll const mod = 1e9+7;vector<vector<ll>> prod(vector<vector<ll>>& a, vector<vector<ll>>& b, ll mod) {vector<vector<ll>> ret(a.size(),vector<ll>(b[0].size(),0));for (int i = 0;i < a.size();++i) for (int j = 0;j < b[0].size();++j) for (int k = 0;k < a[0].size();++k) {ret[i][j] += a[i][k]*b[k][j];ret[i][j] %= mod;}return ret;}int main() {ll a,b,n;cin >> a >> b >> n;vector<vector<ll>> ans(2,vector<ll>(1,0)),c(2,vector<ll>(2));ans[0][0] = 2*a;ans[1][0] = 2;c[0][0] = 2*a;c[0][1] = -a*a+b;c[1][0] = 1;c[1][1] = 0;if (n == 0) {cout << 2 << newl;return 0;}n--;while (n) {if (n&1) ans = prod(c,ans,mod);c = prod(c,c,mod);n /= 2;}cout << (ans[0][0]+mod)%mod << newl;}