結果

問題 No.520 プロジェクトオイラーへの招待
ユーザー mamekin
提出日時 2017-06-03 13:55:01
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 480 ms / 4,000 ms
コード長 2,807 bytes
コンパイル時間 1,042 ms
コンパイル使用メモリ 107,644 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-22 04:29:10
合計ジャッジ時間 2,294 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;
long long extgcd(long long a, long long b, long long &x, long long &y) {
long long g = a;
if(b != 0){
g = extgcd(b, a % b, y, x);
y -= (a / b) * x;
}else{
x = 1;
y = 0;
}
return g;
}
long long mod_inverse(long long a, long long m)
{
long long x, y;
extgcd(a, m, x, y);
return (x % m + m) % m;
}
class FactorialCalculation
{
private:
const int mod;
vector<long long> factorial;
vector<long long> invFactorial;
public:
FactorialCalculation(int n, int mod) : mod(mod)
{
factorial.resize(n+1, 1);
invFactorial.resize(n+1, 1);
for(int i=1; i<=n; ++i){
factorial[i] = factorial[i-1] * i % mod;
invFactorial[i] = mod_inverse(factorial[i], mod);
}
}
long long getFactorial(int n){
return factorial[n];
}
long long getInvFactorial(int n){
return invFactorial[n];
}
long long getPermutation(int n, int r){
if(n < r)
return 0;
return factorial[n] * invFactorial[n-r] % mod;
}
long long getCombination(int n, int r){
if(n < r)
return 0;
return getPermutation(n, r) * invFactorial[r] % mod;
}
long long getHomogeneous(int n, int r){
return getCombination(n+r-1, r);
}
};
const int MOD = 1000000007;
int main()
{
int n;
cin >> n;
FactorialCalculation fc(200, MOD);
while(--n >= 0){
vector<int> v(3);
for(int i=0; i<3; ++i)
cin >> v[i];
long long ans = 0;
for(int i=0; i<3; ++i){
for(int j=0; j<v[i]; ++j){
ans += fc.getCombination(v[(i+1)%3]+j-1, j) *
fc.getCombination(v[i]-j-1+v[(i+2)%3], v[(i+2)%3]);
ans %= MOD;
}
}
for(int i=0; i<v[0]; ++i){
for(int j=0; j<v[1]; ++j){
for(int k=0; k<v[2]; ++k){
long long tmp = fc.getCombination(v[0]-i-1+j, j);
tmp *= fc.getCombination(v[1]-j-1+k, k);
tmp %= MOD;
tmp *= fc.getCombination(v[2]-k-1+i, i);
tmp %= MOD;
ans += tmp;
ans %= MOD;
}
}
}
cout << ans << endl;
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0