結果

問題 No.2689 Populous
ユーザー kotatsugamekotatsugame
提出日時 2024-03-20 22:33:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,069 bytes
コンパイル時間 1,963 ms
コンパイル使用メモリ 104,408 KB
実行使用メモリ 11,364 KB
最終ジャッジ日時 2024-03-20 22:35:00
合計ジャッジ時間 3,112 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
8,388 KB
testcase_01 AC 4 ms
8,388 KB
testcase_02 AC 3 ms
8,388 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 4 ms
8,388 KB
testcase_10 WA -
testcase_11 AC 3 ms
8,388 KB
testcase_12 AC 4 ms
8,388 KB
testcase_13 AC 3 ms
8,388 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 3 ms
8,388 KB
testcase_18 WA -
testcase_19 AC 3 ms
8,388 KB
testcase_20 AC 6 ms
11,364 KB
testcase_21 AC 6 ms
11,364 KB
testcase_22 AC 6 ms
11,364 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0