結果

問題 No.3052 Increasing Sliding Window Minimum
ユーザー 沙耶花
提出日時 2025-03-07 21:51:49
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 940 bytes
コンパイル時間 4,214 ms
コンパイル使用メモリ 252,120 KB
実行使用メモリ 8,612 KB
最終ジャッジ日時 2025-03-07 21:51:56
合計ジャッジ時間 6,034 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 8 WA * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000000
#define Inf64 1000000000000000001LL

int main(){
	
	int _t;
	cin>>_t;
	rep(_,_t){
		int n;
		cin>>n;
		vector<int> pos(n,-1);
		vector<int> aa(n);
		rep(i,n){
			int a;
			cin>>a;
			a--;
			aa[i] = a;
			if(a>=0)pos[a] = i+1;
		}
		vector<mint> dp(n+1,0);
		dp[0] = 1;
		rep(i,n){
			vector<mint> ndp(n+1,0);
			mint booked = 0;
			rep(j,n+1){
				if(dp[j]==0)continue;
				if(pos[i]==-1){
					if(j>0 && aa[j-1]>i)booked++;
					{
						ndp[j] += dp[j] * (j-i-booked);
					}
					for(int k=1;k<=2;k++){
						if(j+k <= n && aa[j+k-1]==-2)ndp[j+k] += dp[j];
					}
				}
				else{
					if(pos[i] - j <= 2){
						ndp[max(pos[i],j)] += dp[j];
					}
				}
			}
			swap(dp,ndp);
		}
		cout<<dp[n].val()<<endl;
	}
	return 0;
}
0