結果

問題 No.117 組み合わせの数
ユーザー imoni_kawaiiimoni_kawaii
提出日時 2020-01-05 02:19:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,840 bytes
コンパイル時間 1,478 ms
コンパイル使用メモリ 172,116 KB
実行使用メモリ 27,920 KB
最終ジャッジ日時 2024-05-02 09:05:16
合計ジャッジ時間 4,035 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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:75:13:
/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:71:8: note: 'ans' was declared here
   71 |     ll ans;
      |        ^~~

ソースコード

diff #

#include <bits/stdc++.h>
#define __dist_rep(a1,a2,a3,f,...) f
#define __rep2(i,n) for (int i=0; i<(n); ++i)
#define __rep3(i,a,b) for (int i=(a); i<(b); ++i)
#define rep(...) __dist_rep(__VA_ARGS__,__rep3,__rep2)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n)-1; i>=0; --i)
#define fi first
#define se second
#define debug(x) cerr<<#x<<": "<<(x)<<endl

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template <class T> string tostring(const T &x) { ostringstream oss; oss << x; return oss.str(); }
template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int INF = 1e9+5;
const ll LINF = 1LL<<60;

const ll MOD = 1e9+7;

vector<ll> fac, finv, inv;

void com_init(int n) {
  fac.resize(n+1,1);
  finv.resize(n+1,1);
  inv.resize(n+1,1);
  inv[0] = 0;
  for (int i=2; i<=n; ++i) {
    fac[i] = fac[i-1]*i % MOD;
    inv[i] = -inv[MOD%i]*(MOD/i) % MOD + MOD;
    finv[i] = finv[i-1]*inv[i] % MOD;
  }
}

ll com(int n, int k) {
  if (n<k || n<0 || k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k] % MOD) % MOD;
}

ll perm(int n, int k) {
  if (n<k || n<0 || k<0) return 0;
  return fac[n]*finv[n-k]%MOD;
}

ll H(int n, int k) {
  if (n==0 && k==0) return 1;
  return com(n+k-1,k);
}

int t;

int main() {
  cin>>t;
  com_init(1000000);
  rep(q,t) {
    string s;
    cin>>s;
    char c=s[0];
    int i;
    for (i=2; i<s.size(); i++) if (s[i]==',') break;
    int n=stoi(s.substr(2,i-2));
    int k=stoi(s.substr(i+1,s.size()-i-2));
    ll ans;
    if (c=='C') ans=com(n,k);
    if (c=='P') ans=perm(n,k);
    if (c=='H') ans=H(n,k);
    cout << ans << '\n';
  }
  return 0;
}
0