提出 #43483669


ソースコード 拡げる

#include<bits/stdc++.h>
#define LL long long
#define DB double
#define MOD 998244353
#define ls(x) x << 1
#define rs(x) x << 1 | 1
#define lowbit(x) x & (-x)
#define PII pair<int, int>
#define MP make_pair
#define VI vector<int>
#define VII vector<int>::iterator
#define EB emplace_back
#define SI set<int>
#define SII set<int>::iterator
#define QI queue<int>
using namespace std;
template<typename T> void chkmn(T &a, const T &b) { (a > b) && (a = b); }
template<typename T> void chkmx(T &a, const T &b) { (a < b) && (a = b); }
int inc(const int &a, const int &b) { return a + b >= MOD ? a + b - MOD : a + b; }
int dec(const int &a, const int &b) { return a - b < 0 ? a - b + MOD : a - b; }
int mul(const int &a, const int &b) { return 1LL * a * b % MOD; }
void Inc(int &a, const int &b) { ((a += b) >= MOD) && (a -= MOD); }
void Dec(int &a, const int &b) { ((a -= b) < 0) && (a += MOD); }
void Mul(int &a, const int &b) { a = 1LL * a * b % MOD; }
void Sqr(int &a) { a = 1LL * a * a % MOD; }
int qwqmi(int x, int k = MOD - 2)
{
	int res = 1;
	while(k)
	{
		if(k & 1) Mul(res, x);
		Sqr(x), k >>= 1;
	}
	return res;
}
const int N = 505;
int C[N][N], fac[N], facinv[N], qwq[N][N];
void preprocess()
{
	C[0][0] = 1;
	for(int i = 1; i < N; ++i)
		for(int j = 0; j < N; ++j)
		{
			if(!j) C[i][j] = 1;
			else C[i][j] = inc(C[i - 1][j], C[i - 1][j - 1]);
		}
	fac[0] = facinv[0] = 1;
	for(int i = 1; i < N; ++i)
		fac[i] = mul(fac[i - 1], i);
	facinv[N - 1] = qwqmi(fac[N - 1]);
	for(int i = N - 2; i >= 1; --i)
		facinv[i] = mul(facinv[i + 1], i + 1);
	for(int i = 0; i < N; ++i)
	{
		qwq[i][0] = 1;
		for(int j = 1; j < N; ++j)
			qwq[i][j] = mul(qwq[i][j - 1], facinv[i]);
	}
}
int n, a[N], s[N];
int f[N][N][N], ans;
int main()
{
	preprocess();
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
	{
		scanf("%d", &a[i]);
		s[a[i]]++;
	}
	for(int i = n; i >= 0; --i)
		s[i] += s[i + 1];
	f[n + 1][0][0] = 1;
	for(int i = n; i >= 0; --i)
	{
		for(int j = 0; (i + 1) * j <= s[i + 1]; ++j)
		{
			for(int k = 0; k <= s[i + 1]; ++k)
			{
				for(int x = 0; x + j <= s[i] && k + i * x <= s[i]; ++x)
				{
					int w = f[i + 1][j][k];
					Mul(w, C[s[i] - j][x]);
					Mul(w, fac[s[i] - k]);
					Mul(w, qwq[i][x]);
					Mul(w, facinv[s[i] - k - i * x]);
					Inc(f[i][j + x][k + i * x], w);
				}
			}
		}
	}
	printf("%d\n", f[0][n][n]);
	return 0;
}

提出情報

提出日時
問題 E - Strange Constraints
ユーザ Schucking_Sattin
言語 C++ (GCC 9.2.1)
得点 700
コード長 2433 Byte
結果 AC
実行時間 806 ms
メモリ 20540 KiB

コンパイルエラー

./Main.cpp: In function ‘int main()’:
./Main.cpp:65:7: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   65 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
./Main.cpp:68:8: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   68 |   scanf("%d", &a[i]);
      |   ~~~~~^~~~~~~~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 700 / 700
結果
AC × 4
AC × 22
セット名 テストケース
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 00_sample_04.txt
All 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 00_sample_04.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt
ケース名 結果 実行時間 メモリ
00_sample_01.txt AC 9 ms 5488 KiB
00_sample_02.txt AC 10 ms 5560 KiB
00_sample_03.txt AC 10 ms 5640 KiB
00_sample_04.txt AC 7 ms 5620 KiB
01_test_01.txt AC 8 ms 5408 KiB
01_test_02.txt AC 4 ms 5548 KiB
01_test_03.txt AC 8 ms 5664 KiB
01_test_04.txt AC 739 ms 17724 KiB
01_test_05.txt AC 594 ms 16724 KiB
01_test_06.txt AC 713 ms 17500 KiB
01_test_07.txt AC 799 ms 18224 KiB
01_test_08.txt AC 789 ms 18004 KiB
01_test_09.txt AC 795 ms 18040 KiB
01_test_10.txt AC 415 ms 9600 KiB
01_test_11.txt AC 806 ms 20532 KiB
01_test_12.txt AC 593 ms 9980 KiB
01_test_13.txt AC 805 ms 20540 KiB
01_test_14.txt AC 780 ms 14416 KiB
01_test_15.txt AC 793 ms 18224 KiB
01_test_16.txt AC 799 ms 18132 KiB
01_test_17.txt AC 794 ms 18120 KiB
01_test_18.txt AC 795 ms 18412 KiB