結果

問題 No.1378 Flattening
コンテスト
ユーザー vjudge1
提出日時 2025-11-17 12:31:48
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 122 ms / 2,000 ms
コード長 1,069 bytes
コンパイル時間 3,115 ms
コンパイル使用メモリ 278,984 KB
実行使用メモリ 199,328 KB
最終ジャッジ日時 2025-11-17 12:31:55
合計ジャッジ時間 6,463 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define yes cout << "Yes\n"
#define no cout << "No\n"
#define coutfix(num, ans) (cout << fixed << setprecision(num) << ans << '\n')
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 998244353;
int dp[5005][5005];

void solve()
{
    int n;
    cin >> n;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }

    dp[0][0] = 1;
    for (int i = 1; i <= n; i++)
    {
        int l=i,r=i;
        while(l >= 1 && a[l] >= a[i])
        {
            l--;
        }
        while(r <= n && a[r] >= a[i])
        {
            r++;
        }
        for (int j = 0; j <= n; j++)
        {
            dp[i][j] = dp[i-1][j];
        }
        for (int j = l+1; j < r; j++)
        {
            dp[i][j] = (dp[i][j] + dp[i][j-1]) % MOD;
        }
    }
    cout << dp[n][n] << endl;
}

signed main()
{
    cin.tie(0)->sync_with_stdio(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
0