結果

問題 No.1608 Yet Another Ants Problem
ユーザー rtyu
提出日時 2021-07-16 22:47:49
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 223 ms / 2,000 ms
コード長 1,058 bytes
コンパイル時間 468 ms
コンパイル使用メモリ 67,892 KB
実行使用メモリ 74,112 KB
最終ジャッジ日時 2024-07-06 10:18:29
合計ジャッジ時間 5,048 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;

int a[3009];
long long cb[3009][3009], ans[3009], md = 998244353;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, l; cin >> n >> l;
	cb[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		cb[i][0] = 1;
		for (int j = 1; j <= n; j++)
			cb[i][j] = (cb[i - 1][j - 1] + cb[i - 1][j]) % md;
	}
	for (int i = 1; i <= n; i++) {
		for (int pi = 0; pi < 2; pi++) {
			int c = n - 1, lc = 0, rc = 0, h = a[i];
			if (pi) h = l - a[i];
			bool f = true;
			for (int j = 1; j <= n; j++) {
				if (i == j) continue;
				bool lf = (a[j] <= h), rf = ((l - a[j]) <= h);
				if (pi) {
					if (a[j] == h) lf = false;
					if (l - a[j] == h) rf = false;
				}
				if (!lf && !rf) {
					f = false;
					break;
				}
				else if (!lf || !rf) {
					c--;
					if (!lf) rc++;
					else lc++;
				}
			}
			if (!f) continue;
			for (int j = 0; j <= c; j++) 
				ans[lc + j + 1] = (ans[lc + j + 1] + cb[c][j]) % md;
		}
	}
	for (int i = 1; i <= n; i++)
		cout << ans[i] << '\n';
	return 0;
}
0