結果
問題 |
No.940 ワープ ε=ε=ε=ε=ε=│;p>д<│
|
ユーザー |
|
提出日時 | 2025-01-01 01:04:03 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 89 ms / 5,000 ms |
コード長 | 1,152 bytes |
コンパイル時間 | 1,999 ms |
コンパイル使用メモリ | 193,280 KB |
最終ジャッジ日時 | 2025-02-26 17:17:35 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 22 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:35:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 35 | scanf("%d%d%d", &p, &q, &r); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> using LL = long long; const int N = 4e6 + 7; const int MOD = 1e9 + 7; int p, q, r, fac[N], ifc[N]; int a[N]; int pow(int x, int y) { int ret = 1; while(y) { if(y & 1) ret = 1LL * ret * x % MOD; x = 1LL * x * x % MOD; y >>= 1; } return ret; } int com(int x, int y) { return 1LL * fac[x] * ifc[y] % MOD * ifc[x - y] % MOD; } int main() { fac[0] = 1; for(int i = 1; i < N; ++i) fac[i] = 1LL * fac[i - 1] * i % MOD; ifc[N - 1] = pow(fac[N - 1], MOD - 2); for(int i = N - 2; i >= 0; --i) ifc[i] = 1LL * ifc[i + 1] * (i + 1) % MOD; scanf("%d%d%d", &p, &q, &r); if(!p && !q && !r) { puts("1"); return 0; } int m = p + q + r; a[0] = 1; for(int i = 0; i <= m + 1; ++i) a[i] = a[i] - (m + 1 - i & 1 ? -1 : 1) * com(m + 1, i); for(int i = 0; i <= m; ++i) { a[i] = 1LL * a[i] * ifc[2] % MOD; a[i + 1] = (a[i + 1] + a[i]) % MOD; } int ans = 0; for(int i = 1; i <= m; ++i) ans = (ans + 1LL * a[i] * com(i + p - 1, p) % MOD * com(i + q - 1, q) % MOD * com(i + r - 1, r)) % MOD; printf("%d\n", (ans + MOD) % MOD); return 0; }