結果
問題 | No.117 組み合わせの数 |
ユーザー | Konton7 |
提出日時 | 2020-02-05 14:09:04 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,297 bytes |
コンパイル時間 | 2,118 ms |
コンパイル使用メモリ | 205,968 KB |
実行使用メモリ | 19,176 KB |
最終ジャッジ日時 | 2024-09-22 12:10:02 |
合計ジャッジ時間 | 3,724 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/istream:39, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/sstream:38, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/complex:45, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ccomplex:39, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:54, from main.cpp:1: In member function 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>]', inlined from 'int main()' at main.cpp:115:17: /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ostream:202:25: warning: 'ans' may be used uninitialized [-Wmaybe-uninitialized] 202 | { return _M_insert(__n); } | ~~~~~~~~~^~~~~ main.cpp: In function 'int main()': main.cpp:42:25: note: 'ans' was declared here 42 | ll t, a, b, status, ans; | ^~~
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using PII = std::pair<int, int>; using PLL = std::pair<ll, ll>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) ll pow_mod(int p, int q, int mod) { ll ret, r; ret = 1; r = p; while (q > 0) { if (q % 2) { ret *= r; ret %= mod; } r = (r * r) % mod; q /= 2; } return ret % mod; } int main() { #ifdef DEBUG cout << "DEBUG MODE" << endl; ifstream in("input.txt"); //for debug cin.rdbuf(in.rdbuf()); //for debug #endif const int mod = 1e9 + 7; const int imax = 1e6; ll t, a, b, status, ans; string s, sa, sb; vector<ll> frac, frac_inv; frac.push_back(1); frac_inv.push_back(1); a = b = 1; rep(i, imax) { a *= i + 1; a %= mod; frac.push_back(a); b *= pow_mod(i + 1, mod - 2, mod); b %= mod; frac_inv.push_back(b); } cin >> t; rep(i, t) { sa = sb = ""; status = 0; cin >> s; for (auto z : s.substr(2, s.length() - 3)) { if (z == ',') { status++; } else if (status == 0) { sa += z; } else if (status == 1) { sb += z; } } a = stoll(sa), b = stoll(sb); if (s[0] == 'C') { if (b > a) { ans = 0; } else { ans = frac[a] * frac_inv[b]; ans %= mod; ans *= frac_inv[a - b]; ans %= mod; } } else if (s[0] == 'P') { if (b > a) { ans = 0; } else { ans = frac[a] * frac_inv[a - b]; ans %= mod; } } else if (s[0] == 'H') { ans = frac[a + b - 1] * frac_inv[b]; ans %= mod; ans *= frac_inv[a - 1]; ans %= mod; } cout << ans << endl; } return 0; }