結果
| 問題 |
No.3117 Reversible Tile
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2025-05-01 22:31:14 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 169 ms / 3,000 ms |
| コード長 | 746 bytes |
| コンパイル時間 | 2,008 ms |
| コンパイル使用メモリ | 192,508 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-05-01 22:31:19 |
| 合計ジャッジ時間 | 5,571 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:14:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
14 | scanf("%d%d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~
main.cpp:15:32: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
15 | for(i=1;i<=n;i++) scanf("%d",&a[i]);
| ~~~~~^~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3fLL;
const int MAX=5000+10;
const int mod=998244353;
int a[MAX];
ll dp[2][MAX];
ll cal(ll x){return x*(x-1)/2%mod;}
int main()
{
int n,m,i,j,f,cnt;
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++) scanf("%d",&a[i]);
cnt=0;
a[0]=a[n+1]=0;
for(i=1;i<=n+1;i++) cnt+=(a[i]!=a[i-1]);
f=0;
memset(dp[f],0,sizeof dp[f]);
dp[f][cnt]=1;
for(i=1;i<=m;i++)
{
f^=1;
for(j=0;j<=n+1;j++)
{
dp[f][j]=0;
if(j+2<=n+1) dp[f][j]+=dp[!f][j+2]*cal(j+2)%mod;
if(j-2>=0) dp[f][j]+=dp[!f][j-2]*cal((n+1)-(j-2))%mod;
dp[f][j]+=dp[!f][j]*(j*((n+1)-j)%mod)%mod;
dp[f][j]%=mod;
}
}
printf("%lld\n",dp[f][0]);
return 0;
}
vjudge1