結果
問題 |
No.2689 Populous
|
ユーザー |
|
提出日時 | 2024-03-20 22:33:57 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,069 bytes |
コンパイル時間 | 1,838 ms |
コンパイル使用メモリ | 104,356 KB |
実行使用メモリ | 11,348 KB |
最終ジャッジ日時 | 2024-09-30 08:37:58 |
合計ジャッジ時間 | 3,013 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 9 WA * 19 |
ソースコード
#include<iostream> #include<cassert> #include<atcoder/modint> #include<atcoder/convolution> using namespace std; using mint=atcoder::modint998244353; int H,W; int A[1000][1000]; mint dp[1000][1000]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin>>H>>W; for(int i=0;i<W;i++)cin>>A[0][i]; for(int i=1;i<H-1;i++)cin>>A[i][0]>>A[i][W-1]; for(int i=0;i<W;i++)cin>>A[H-1][i]; { for(int i=0;i<H;i++)for(int j=0;j<W;j++)if(A[i][j]!=0) { if(i+1<H&&A[i+1][j]!=0&&abs(A[i][j]-A[i+1][j])>=2) { cout<<-1<<endl; return 0; } if(j+1<W&&A[i][j+1]!=0&&abs(A[i][j]-A[i][j+1])>=2) { cout<<-1<<endl; return 0; } } } int h=0,w=0; for(int i=1;i<H-1;i++) { if(abs(A[i][0]-A[i][W-1])>=W)h++; } for(int i=1;i<W-1;i++) { if(abs(A[0][i]-A[H-1][i])>=H)w++; } if(h<w)swap(h,w); dp[0][0]=1; for(int i=0;i<h;i++) { for(int j=0;j<=min(w,i);j++) { dp[i+1][j]+=dp[i][j]*mint::raw(j+(W-2-w)); dp[i+1][j+1]+=dp[i][j]*mint::raw(w-j); } } mint ans=0; for(int j=0;j<=w;j++)ans+=dp[h][j]; cout<<ans.val()<<endl; }