結果
問題 | No.1489 Repeat Cumulative Sum |
ユーザー | deuteridayo |
提出日時 | 2021-04-23 22:41:41 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,568 bytes |
コンパイル時間 | 3,650 ms |
コンパイル使用メモリ | 233,336 KB |
実行使用メモリ | 170,164 KB |
最終ジャッジ日時 | 2024-07-04 08:26:41 |
合計ジャッジ時間 | 10,342 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
testcase_01 | -- | - |
testcase_02 | -- | - |
testcase_03 | -- | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
コンパイルメッセージ
main.cpp: In function 'lint ncrmodp(lint, lint, lint)': main.cpp:33:29: warning: iteration 20000001 invokes undefined behavior [-Waggressive-loop-optimizations] 33 | kai[i] = kai[i-1] * i; | ~~~~~~~^ main.cpp:32:22: note: within this loop 32 | for(int i=1;i<=mod;i++){ | ~^~~~~
ソースコード
#include<bits/stdc++.h> #include<atcoder/all> using namespace std; using namespace atcoder; using lint = long long; using ulint = unsigned long long; #define endl '\n' int const INF = 1<<30; lint const INF64 = 1LL<<61; lint const mod = 1e9+7; //long const mod = 998244353; lint ceilDiv(lint x, lint y){if(x >= 0){return (x+y-1)/y;}else{return x/y;}} lint floorDiv(lint x, lint y){if(x >= 0){return x/y;}else{return (x-y+1)/y;}} lint Sqrt(lint x){lint upper = 1e9;lint lower = 0;while(upper - lower > 0){lint mid = (1+upper + lower)/2;if(mid * mid > x){upper = mid-1;}else{lower = mid;}}return upper;} lint gcd(lint a,lint b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);} lint lcm(lint a,lint b){return (a / gcd(a,b)) * b;} lint chmin(vector<lint>&v){lint ans = INF64;for(lint i:v){ans = min(ans, i);}return ans;} lint chmax(vector<lint>&v){lint ans = -INF64;for(lint i:v){ans = max(ans, i);}return ans;} double dist(double x1, double y1, double x2, double y2){return sqrt(pow(x1-x2, 2) + pow(y1-y2,2));} string toString(lint n){string ans = "";if(n == 0){ans += "0";}else{while(n > 0){int a = n%10;char b = '0' + a;string c = "";c += b;n /= 10;ans = c + ans;}}return ans;} vector<lint>prime;void makePrime(lint n){prime.push_back(2);for(lint i=3;i<=n;i+=2){bool chk = true;for(lint j=0;j<prime.size() && prime[j]*prime[j] <= i;j++){if(i % prime[j]==0){chk=false;break;}}if(chk)prime.push_back(i);}} struct edge{ int to; }; using graph = vector<vector<edge>>; lint kai[20000001]; bool firstCallnCr = true; lint ncrmodp(lint n,lint r,lint p){ if(firstCallnCr){ kai[0] = 1; for(int i=1;i<=mod;i++){ kai[i] = kai[i-1] * i; kai[i] %= mod; } firstCallnCr = false; } if(n >= mod)return 0; if(n<0)return 0; if(n < r)return 0; if(n==0)return 1; lint ans = kai[n]; lint tmp = (kai[r] * kai[n-r]) % p; for(lint i=1;i<=p-2;i*=2){ if(i & p-2){ ans *= tmp; ans %= p; } tmp *= tmp; tmp %= p; } return ans; } lint f(lint n, lint m){ lint tmp = 1; tmp *= m+2; tmp *= ncrmodp(n+m+2, n, mod); tmp -= n+1; tmp += mod; tmp %= mod; tmp *= inv_mod(n+1, mod); return tmp; } int main(){ lint n,m; cin >> n >> m; lint a[n+1]; for(int i=2;i<=n;i++)cin >> a[i]; lint ans = 0; for(int i=2;i<=n;i++){ ans += a[i] * f(n-i, m-2); ans %= mod; } for(int i=2;i<=n;i++){ ans += a[i]; ans %= mod; } cout << ans << endl; }