結果

問題 No.117 組み合わせの数
ユーザー BantakoBantako
提出日時 2018-06-04 11:06:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,191 bytes
コンパイル時間 1,767 ms
コンパイル使用メモリ 168,380 KB
実行使用メモリ 18,664 KB
最終ジャッジ日時 2023-09-12 22:03:54
合計ジャッジ時間 2,756 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:28:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   28 | main(){
      | ^~~~
次のファイルから読み込み:  /usr/local/gcc7/include/c++/12.2.0/istream:39,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/sstream:38,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/complex:45,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/ccomplex:39,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/x86_64-pc-linux-gnu/bits/stdc++.h:54,
         次から読み込み:  main.cpp:1:
メンバ関数 ‘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:47:17:
/usr/local/gcc7/include/c++/12.2.0/ostream:202:25: 警告: ‘ans’ may be used uninitialized [-Wmaybe-uninitialized]
  202 |       { return _M_insert(__n); }
      |                ~~~~~~~~~^~~~~
main.cpp: 関数 ‘int main()’ 内:
main.cpp:43:12: 備考: ‘ans’ はここで定義されています
   43 |         ll ans;
      |            ^~~

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
vector<ll> fact(2000010);
ll powmod(ll x,ll n){
    if(n == 0)return 1;
    ll ans = powmod(x*x%MOD,n/2);
    if(n % 2)ans = ans * x % MOD;
    return ans;
}
ll divmod(ll a,ll b){
    return ((a%MOD) * (powmod(b,MOD-2)%MOD)) % MOD;
}
ll perm(ll n,ll r){
    if(n < r)return 0;
    return divmod( fact[n] , fact[n-r]);
}
ll combi(ll n,ll r){
    if(n < r || n < 0)return 0;
    return divmod( perm(n,r) , fact[r]);
}
ll dupc(ll n,ll r){
    return combi(n+r-1,r);
}
main(){
    fact[0] = 1;
    rep(i,1,2000010)fact[i] = fact[i-1] * i % MOD;

    ll T;
    cin >> T;
    rep(i,0,T){
        string S,str[2] = {};
        cin >> S;
        char p = S[0];
        bool f = 0;
        for(char c:S){
            if(c == ',')f = 1;
            if(c >= '0' && c <= '9')str[f].push_back(c);
        }
        ll ans;
        if(p == 'P')ans = perm( stoi(str[0]),stoi(str[1]) );
        if(p == 'C')ans = combi( stoi(str[0]),stoi(str[1]) );
        if(p == 'H')ans = dupc( stoi(str[0]),stoi(str[1]) );
        cout << ans << endl;
    }
}
0