結果

問題 No.1378 Flattening
コンテスト
ユーザー tempura_pp
提出日時 2021-02-06 00:35:30
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 422 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,187 ms
コンパイル使用メモリ 211,360 KB
実行使用メモリ 7,968 KB
最終ジャッジ日時 2026-06-17 15:15:32
合計ジャッジ時間 2,885 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
constexpr int mod = 998244353;
int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (auto &e : a) cin >> e;
	vector<int> dp(n + 1);
	dp[0] = 1;
	for (int i = 0; i < n; i++) {
		int l = i, r = i + 1;
		while (l > 0 && a[l - 1] > a[i]) --l;
		while (r < n && a[i] < a[r]) ++r;
		for (int j = l; j < r; j++) (dp[j + 1] += dp[j]) %= mod;
	}
	cout << dp[n] << endl;
	return 0;
}
0