結果

問題 No.1378 Flattening
ユーザー 00 Sakuda00 Sakuda
提出日時 2024-04-01 18:11:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 378 ms / 2,000 ms
コード長 1,363 bytes
コンパイル時間 2,730 ms
コンパイル使用メモリ 212,544 KB
実行使用メモリ 199,168 KB
最終ジャッジ日時 2024-04-01 18:12:06
合計ジャッジ時間 9,064 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 1 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 2 ms
6,676 KB
testcase_28 AC 2 ms
6,676 KB
testcase_29 AC 1 ms
6,676 KB
testcase_30 AC 1 ms
6,676 KB
testcase_31 AC 378 ms
199,168 KB
testcase_32 AC 354 ms
199,168 KB
testcase_33 AC 294 ms
199,168 KB
testcase_34 AC 306 ms
199,168 KB
testcase_35 AC 287 ms
199,168 KB
testcase_36 AC 272 ms
199,168 KB
testcase_37 AC 264 ms
199,168 KB
testcase_38 AC 270 ms
199,168 KB
testcase_39 AC 257 ms
199,168 KB
testcase_40 AC 257 ms
199,168 KB
testcase_41 AC 261 ms
199,168 KB
testcase_42 AC 257 ms
199,168 KB
testcase_43 AC 257 ms
199,168 KB
testcase_44 AC 263 ms
199,168 KB
testcase_45 AC 22 ms
17,920 KB
testcase_46 AC 36 ms
28,032 KB
testcase_47 AC 6 ms
6,676 KB
testcase_48 AC 206 ms
153,984 KB
testcase_49 AC 227 ms
174,080 KB
testcase_50 AC 19 ms
15,488 KB
testcase_51 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>
#include <atcoder/segtree>
using namespace atcoder;
using namespace std;
using ll = long long;
using mint = modint998244353;
int op(int a, int b) {return min(a,b);}
int inf = 1e9;
int e() {return inf;}
int main() {
	int N;cin >> N;
	vector<int> A(N + 1, 0);
	for (int i = 1;i <= N;i++) cin >> A[i];
	vector<vector<mint>> dp(N + 1, vector<mint>(N + 1, 0));
	segtree<int, op, e> seg(A);
	vector<int> L(N + 1), R(N + 1);
		for (int j = 1;j <= N;j++) {
			int ok = j;
			int ng = 0;
			while (ok - ng > 1) {
				int x = (ok + ng) / 2;
				if (seg.prod(x, j + 1) == A[j]) {
					ok = x;
				} else {
					ng = x;
				}
			}
			int l = ok;
			ok = j;
			ng = N + 1;
			while (ng - ok > 1) {
				int x = (ok + ng) / 2;
				if (seg.prod(j, x + 1) == A[j]) {
					ok = x;
				} else {
					ng = x;
				}
			}
			int r = ok;
			L[j] = l;
			R[j] = r;
		}
	for (int j = 0;j <= N;j++) dp[0][j] = 1;
	vector<vector<mint>> S(N + 1, vector<mint>(N + 1, 0));
	for (int j = 0;j <= N;j++) S[0][j] = dp[0][j];
	for (int i = 1;i <= N;i++)  {
		for (int j = 1;j <= N;j++) {
		int l = L[j];int r = R[j];
		dp[i][j] += dp[i][j - 1];
		if (i < l or r < i) continue;
		dp[i][j] += S[i - 1][j - 1] - (l == 1 ? 0 : S[l - 2][j - 1]);
		}
		for (int j = 0;j <= N;j++) S[i][j] = S[i - 1][j] + dp[i][j];
	}
	cout << dp[N][N].val() << endl;
}

0