結果

問題 No.140 みんなで旅行
ユーザー imgry22imgry22
提出日時 2015-02-05 13:03:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 1,450 bytes
コンパイル時間 1,161 ms
コンパイル使用メモリ 145,068 KB
実行使用メモリ 10,720 KB
最終ジャッジ日時 2023-09-05 12:47:44
合計ジャッジ時間 2,097 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,472 KB
testcase_01 AC 2 ms
7,764 KB
testcase_02 AC 3 ms
8,136 KB
testcase_03 AC 2 ms
7,748 KB
testcase_04 AC 3 ms
7,432 KB
testcase_05 AC 3 ms
7,444 KB
testcase_06 AC 3 ms
7,560 KB
testcase_07 AC 2 ms
7,516 KB
testcase_08 AC 2 ms
7,456 KB
testcase_09 AC 2 ms
7,576 KB
testcase_10 AC 2 ms
7,504 KB
testcase_11 AC 8 ms
10,720 KB
testcase_12 AC 3 ms
7,860 KB
testcase_13 AC 3 ms
7,704 KB
testcase_14 AC 8 ms
10,672 KB
testcase_15 AC 8 ms
10,672 KB
testcase_16 AC 5 ms
9,352 KB
testcase_17 AC 4 ms
8,500 KB
testcase_18 AC 8 ms
10,576 KB
testcase_19 AC 8 ms
10,500 KB
testcase_20 AC 3 ms
8,516 KB
testcase_21 AC 3 ms
7,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000007LL
#define EPS 1E-12

const int MAX_N = 560;
int N;
ll C[MAX_N+1][MAX_N+1];
ll S[MAX_N+1][MAX_N+1];
ll P[MAX_N+1][MAX_N+1];
ll res;

int main()
{
  cin >> N;

  rep(i, N+1) C[i][0] = 1LL;
  rep(i, N) rep(j, i+1) C[i+1][j+1] = (C[i][j] + C[i][j+1]) % MOD;

  S[0][0] = 1LL;
  rep(i, N) rep(j, i+1) S[i+1][j+1] = (S[i][j] + ((j + 1) * S[i][j+1]) % MOD) % MOD;

  rep(i, N+1) P[i][0] = 1LL;
  rep(i, N+1) rep(j, N+1) P[i][j+1] = P[i][j] * i * (i-1) % MOD;

  erep(i, 1, N) erep(j, 1, i) res = (res + ((C[N][i] * S[i][j]) % MOD * P[j][N-i]) % MOD) % MOD;

  cout << res << endl;

  return 0;
}
0