結果
問題 | No.117 組み合わせの数 |
ユーザー | 👑 obakyan |
提出日時 | 2019-05-02 23:45:09 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,959 bytes |
コンパイル時間 | 774 ms |
コンパイル使用メモリ | 76,720 KB |
実行使用メモリ | 18,988 KB |
最終ジャッジ日時 | 2024-06-10 04:15:38 |
合計ジャッジ時間 | 1,431 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:47:13: warning: format ‘%s’ expects argument of type ‘char*’, but argument 2 has type ‘char (*)[100]’ [-Wformat=] 47 | scanf("%s", &c); | ~^ ~~ | | | | | char (*)[100] | char* main.cpp:47:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 47 | scanf("%s", &c); | ~~~~~^~~~~~~~~~
ソースコード
#include <cstdio> #include <cstdlib> #include <cstddef> #include <vector> #include <algorithm> #include <cmath> #include <string> #include <iostream> #include <iomanip> #define L64 long long #define MOD (1000000007LL) L64 modpow(L64 src, L64 pow, L64 mod) { L64 res = 1; while (0 < pow) { if (pow % 2 == 1) { res = (res * src) % mod; pow--; } src = (src * src) % mod; pow /= 2; } return res; } L64 modinv(L64 src, L64 mod) { return modpow(src, mod - 2, mod); } int main(void) { std::vector<L64> factorials; factorials.resize(2000001); factorials[0] = 1; char c[100]; L64 a, b; int t; char tp; for(L64 i = 1; i <= 2000000; i++){ factorials[i] = (factorials[i - 1] * i) % MOD; } std::cin >> t; for(int i = 0; i < t; i++){ scanf("%s", &c); tp = c[0]; int pos = 2; a = 0; while(true){ char tmp = c[pos]; if(tmp == ','){ pos++; break; } else { a = a * 10LL + (L64)(tmp - 48); pos++; } } b = 0; while(true){ char tmp = c[pos]; if(tmp == ')'){ pos++; break; } else { b = b * 10LL + (L64)(tmp - 48); pos++; } } if(tp != 'H' && a < b){ std::cout << 0 << std::endl; } else if(tp == 'C'){ L64 ret = factorials[a]; L64 div = factorials[a - b]; ret = (ret * modinv(div, MOD)) % MOD; div = factorials[b]; ret = (ret * modinv(div, MOD)) % MOD; std::cout << ret << std::endl; } else if(tp == 'P'){ L64 ret = factorials[a]; L64 div = factorials[a - b]; ret = (ret * modinv(div, MOD)) % MOD; std::cout << ret << std::endl; } else { a = a + b - 1; L64 ret = factorials[a]; L64 div = factorials[a - b]; ret = (ret * modinv(div, MOD)) % MOD; div = factorials[b]; ret = (ret * modinv(div, MOD)) % MOD; std::cout << ret << std::endl; } } }