Submission #3391769
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
struct initon {
initon() {
cin.tie(0);
ios::sync_with_stdio(false);
};
} hoee;
//別名
#define int long long
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using vl = vector<ll>;
using vvl = vector<vl>;
using P = pair<ll, ll>;
using vp = vector<P>;
using dou = double;
using itn = int;
using str = string;
#define F first
#define S second
//定数
const int INF = (int) 1e9 + 100;
const int MINF = (int) -1e9 - 100;
const ll LINF = (ll) 1e18 + 100;
const ll MLINF = (ll) 1e18 - 100;
const double EPS = 1e-9;
const int y4[] = {-1, 1, 0, 0};
const int x4[] = {0, 0, -1, 1};
const int y8[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int x8[] = {1, 0, -1, 0, 1, -1, 1, -1};
//配列
#define sz(a) (sizeof(a)/sizeof(a[0]))
//コンテナ
#define mp make_pair
#define pb(a) push_back(a)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sort(v) sort(v.begin(),v.end())
//繰り返し
#define _overloadrep(_1, _2, _3, name, ...) name
#define _rep(i, n) for(int i = 0,RLN = (n); i < RLN ; i++)
#define repi(i, m, n) for(int i = m,RLN = (n); i < RLN ; i++)
#define rep(...) _overloadrep(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rer(i, n) for(int RLN = (n-1) ,i = RLN; i >= 0 ; i--)
#define reri(i, m, n) for(int RLN = (n-1) ,i = m-1; i >= n ; i--)
#define rer(...) _overloadrep(__VA_ARGS__,reri,_rer,)(__VA_ARGS__)
// 多次元配列の初期化。第2引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void fill(A (&array)[N], const T &val) {
std::fill((T *) array, (T *) (array + N), val);
}
#define arcpy(a, b) memcpy(a,b,sizeof(b))
//入力
template<typename T = int>
T in() {
T x;
cin >> x;
return (x);
}
string sin() {
return in<string>();
}
double din() {
return in<double>();
}
ll lin() {
return in<ll>();
}
#define na(a) rep(i,sz(a)) cin >> a[i];
#define nad(a) rep(i,sz(a)) cin >> a[i]; a[i]--;
#define nt(a) rep(hi,sz(a))rep(wi,sz(a[0])) cin >> a[hi][wi];
#define ntd(a) rep(hi,sz(a))rep(wi,sz(a[0])) cin >> a[hi][wi]; a[hi][wi]--;
#define nctp(a, c) fill(a,c); rep(hi,1,sz(a)+1)rep(wi,1,sz(a[0])+1) cin >> a[hi][wi];
#define add(a, n) rep(i,n) a.pb(in());
//出力
template<class T>
void out(T x) {
cout << x << endl;
}
//デバッグ
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';
//便利関数
#define bit(n) (1LL<<(n))
template<class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template<class T>
bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
inline bool inside(int y, int x, int H, int W) {
return y >= 0 && x >= 0 && y < H && x < W;
}
//mod関連
ll MOD = (int) 1e9 + 7;
const int setModMax = 510000;
ll fac[setModMax], finv[setModMax], inv[setModMax];
void setMod() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < setModMax; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
ll mcom(ll n, ll r) {
if (n < r || n < 0 || r < 0)return 0;
if (fac[0] == 0)setMod();
return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}
ll minv(ll a) {
if (a < setModMax) return inv[a];
a %= MOD;
ll b = MOD, x = 1, y = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
x -= t * y;
swap(x, y);
}
return (x % MOD + MOD) % MOD;
}
class mint {
private:
ll v;
public:
static ll mod(ll a) { return (a % MOD + MOD) % MOD; }
mint(ll a = 0) { this->v = mod(a); }
mint(const mint &a) { v = a.v; }
mint operator+(const mint &a) { return mint(v + a.v); }
mint operator+(const ll a) { return mint(v + a % MOD); }
friend mint operator+(const ll a, const mint &b) { return mint(a % MOD + b.v); }
void operator+=(const mint &a) { v = (v + a.v) % MOD; }
void operator+=(const ll a) { v = mod(v + a % MOD); }
friend void operator+=(ll &a, const mint &b) { a = mod(a % MOD + b.v); }
mint operator-(const mint &a) { return mint(v - a.v); }
mint operator-(const ll a) { return mint(v - a % MOD); }
friend mint operator-(const ll a, const mint &b) { return mint(a % MOD - b.v); }
void operator-=(const mint &a) { v = mod(v - a.v); }
void operator-=(const ll a) { v = mod(v - a % MOD); }
friend void operator-=(ll &a, const mint &b) { a = mod(a % MOD - b.v); }
mint operator*(const mint &a) { return mint(v * a.v); }
mint operator*(const ll a) { return mint(v * (a % MOD)); }
friend mint operator*(const ll a, const mint &b) { return mint(a % MOD * b.v); }
void operator*=(const mint &a) { v = (v * a.v) % MOD; }
void operator*=(const ll a) { v = mod(v * (a % MOD)); }
friend void operator*=(ll &a, const mint &b) { a = mod(a % MOD * b.v); }
mint operator/(const mint &a) { return mint(v * minv(a.v)); }
mint operator/(const ll a) { return mint(v * minv(a)); }
friend mint operator/(const ll a, const mint &b) { return mint(a % MOD * minv(b.v)); }
void operator/=(const mint &a) { v = (v * minv(a.v)) % MOD; }
void operator/=(const ll a) { v = mod(v * minv(a)); }
friend void operator/=(ll &a, const mint &b) { a = mod(a % MOD * minv(b.v)); }
mint operator^(const mint &a) {
ll x = v, n = a.v, res = 1;
while (n) {
if (n & 1)res = (res * x) % MOD;
x = (x * x) % MOD;
n >>= 1;
}
return res;
}
//単項演算子
mint operator+() { return *this; }
mint operator++() {
v++;
return *this;
}
mint operator++(signed d) {
mint res = *this;
v++;
return res;
}
mint operator-() { return operator*(-1); }
mint operator--() {
v++;
return *this;
}
mint operator--(signed d) {
mint res = *this;
v++;
return res;
}
bool operator==(mint &a) {
return v == a.v;
}
bool operator==(signed a) {
return v == a;
}
friend bool operator==(signed a, mint &b) {
return a == b.v;
}
bool operator!=(mint &a) {
return v != a.v;
}
bool operator!=(signed a) {
return v != a;
}
friend bool operator!=(signed a, mint &b) {
return a != b.v;
}
operator int() { return v; }
};
ll u(ll a) {
return a < 0 ? 0 : a;
}
int N, A[1010], B[1010];
mint dp[1010][1010];
signed main() {
MOD = 998244353;
N = in();
rep(i, N)cin >> A[i];
rep(i, N) B[A[i]]++;
//チームのサイズ 残り今使える人の数
dp[N + 1][0] = 1;
setMod();
//iは次のサイズ
rer(i, N + 2, 1)rer(j, N + 1) {
if (dp[i + 1][j] == 0)continue;
int r = j + B[i];
mint com = dp[i + 1][j];
for (int k = 0; r - i * k >= 0; ++k) {
dp[i][r - i * k] += com * finv[k];
com *= mcom(r - i * k, i);
}
}
out(dp[1][0]);
return 0;
}
Submission Info
Submission Time |
|
Task |
F - チーム分け |
User |
baito |
Language |
C++14 (GCC 5.4.1) |
Score |
600 |
Code Size |
7584 Byte |
Status |
AC |
Exec Time |
377 ms |
Memory |
20224 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
600 / 600 |
Status |
AC
|
|
Set Name |
Test Cases |
Sample |
|
All |
01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, s1.txt, s2.txt, s3.txt |
Case Name |
Status |
Exec Time |
Memory |
01.txt |
AC |
36 ms |
20224 KB |
02.txt |
AC |
36 ms |
20224 KB |
03.txt |
AC |
36 ms |
20224 KB |
04.txt |
AC |
36 ms |
20224 KB |
05.txt |
AC |
36 ms |
20224 KB |
06.txt |
AC |
38 ms |
20224 KB |
07.txt |
AC |
37 ms |
20224 KB |
08.txt |
AC |
37 ms |
20224 KB |
09.txt |
AC |
37 ms |
20224 KB |
10.txt |
AC |
37 ms |
20224 KB |
11.txt |
AC |
293 ms |
20224 KB |
12.txt |
AC |
309 ms |
20224 KB |
13.txt |
AC |
300 ms |
20224 KB |
14.txt |
AC |
297 ms |
20224 KB |
15.txt |
AC |
275 ms |
20224 KB |
16.txt |
AC |
377 ms |
20224 KB |
17.txt |
AC |
374 ms |
20224 KB |
18.txt |
AC |
371 ms |
20224 KB |
19.txt |
AC |
373 ms |
20224 KB |
20.txt |
AC |
372 ms |
20224 KB |
21.txt |
AC |
36 ms |
20224 KB |
22.txt |
AC |
36 ms |
20224 KB |
23.txt |
AC |
36 ms |
20224 KB |
24.txt |
AC |
36 ms |
20224 KB |
s1.txt |
AC |
36 ms |
20224 KB |
s2.txt |
AC |
36 ms |
20224 KB |
s3.txt |
AC |
36 ms |
20224 KB |