結果

問題 No.1378 Flattening
ユーザー SSRSSSRS
提出日時 2021-02-05 22:33:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 200 ms / 2,000 ms
コード長 740 bytes
コンパイル時間 1,518 ms
コンパイル使用メモリ 171,060 KB
実行使用メモリ 198,920 KB
最終ジャッジ日時 2023-09-15 09:02:16
合計ジャッジ時間 6,488 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 195 ms
198,588 KB
testcase_32 AC 197 ms
198,784 KB
testcase_33 AC 186 ms
198,732 KB
testcase_34 AC 185 ms
198,640 KB
testcase_35 AC 200 ms
198,584 KB
testcase_36 AC 188 ms
198,724 KB
testcase_37 AC 174 ms
198,776 KB
testcase_38 AC 173 ms
198,652 KB
testcase_39 AC 173 ms
198,612 KB
testcase_40 AC 174 ms
198,724 KB
testcase_41 AC 174 ms
198,920 KB
testcase_42 AC 173 ms
198,600 KB
testcase_43 AC 173 ms
198,912 KB
testcase_44 AC 172 ms
198,644 KB
testcase_45 AC 14 ms
17,676 KB
testcase_46 AC 24 ms
27,600 KB
testcase_47 AC 4 ms
5,732 KB
testcase_48 AC 133 ms
153,524 KB
testcase_49 AC 152 ms
173,512 KB
testcase_50 AC 12 ms
15,172 KB
testcase_51 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++){
    cin >> a[i];
  }
  vector<vector<long long>> dp(N + 1, vector<long long>(N + 1, 0));
  dp[0][0] = 1;
  for (int i = 0; i < N; i++){
    int L = 0;
    for (int j = i - 1; j >= 0; j--){
      if (a[j] < a[i]){
        L = j + 1;
        break;
      }
    }
    int R = N;
    for (int j = i + 1; j < N; j++){
      if (a[j] < a[i]){
        R = j;
        break;
      }
    }
    dp[i + 1] = dp[i];
    long long sum = 0;
    for (int j = L; j <= R; j++){
      dp[i + 1][j] += sum;
      dp[i + 1][j] %= MOD;
      sum += dp[i][j];
    }
  }
  cout << dp[N][N] << endl;
}
0