結果
| 問題 | No.3777 Train Seats |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-10-23 23:19:04 |
| 言語 | C++23(gcc16) (gcc 16.2.0 + boost 1.92.0 + ACL) |
| 結果 |
TLE
不安定
|
| 実行時間 | - |
| コード長 | 1,906 bytes |
| 記録 | |
| コンパイル時間 | 3,746 ms |
| コンパイル使用メモリ | 202,440 KB |
| 実行使用メモリ | 18,928 KB |
| 最終ジャッジ日時 | 2026-10-23 23:19:48 |
| 合計ジャッジ時間 | 41,090 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 44 TLE * 6 |
コンパイルメッセージ
main.cpp:16:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
16 | main() {
| ^~~~
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
using namespace std;
const long long MOD=998244353;
long long f[1001][1001],c[1001][1001];
long long fc[1001];
long long ans[1001];
bool added[1001][1001];
main() {
long long q;
cin>>q;
vector <long long> zz[1001];
f[0][0]=1;
zz[0].push_back(0);
for (int i=0;i<=q;i++)
for (int j=0;j<=i;j++) {
if (j==0) c[i][j]=1;
else if (i==j) c[i][j]=1;
else if (j==1) c[i][j]=i;
else c[i][j]=(c[i-1][j-1]+c[i-1][j])%MOD;
}
for (int n=1;n<=q;n++) {
for (int first=1;first<=((n+1)/2);first++) {
int Lside=max(0,first-2);
int Rside=max(0,n-first-1);
for (int Ltake : zz[Lside]) // optimize
for (int Rtake : zz[Rside]) // optimize
{
long long val=(((f[Lside][Ltake]*f[Rside][Rtake])%MOD)*c[Ltake+Rtake][Ltake])%MOD;
if ( first < (n-first+1) ) val=(val*2LL)%MOD;
f[n][1+Ltake+Rtake]+=val;
f[n][1+Ltake+Rtake]%=MOD;
if (!added[n][1+Ltake+Rtake]) {
added[n][1+Ltake+Rtake]=true;
zz[n].push_back(1+Ltake+Rtake);
}
}
}
//for (int k=0;k<=n;k++)
// if (f[n][k]) zz[n].push_back(make_pair(k,f[n][k]));
//cout<<"done "<<n<<endl;
}
fc[0]=1;
for (long long x=1;x<=q;x++)
fc[x]=(fc[x-1]*x)%MOD;
for (int n=1;n<=q;n++) {
ans[n]=0;
for (int i : zz[n])
if (f[n][i]) {
ans[n]+=(f[n][i]*fc[n-i])%MOD;
ans[n]%=MOD;
}
}
//for (int nn=1;nn<=10;nn++)
// cout<<nn<<" --> "<<ans[nn]<<endl;
cout<<ans[q]<<endl;
}