結果

問題 No.1378 Flattening
ユーザー chocoruskchocorusk
提出日時 2021-02-06 17:08:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 245 ms / 2,000 ms
コード長 1,205 bytes
コンパイル時間 1,279 ms
コンパイル使用メモリ 127,864 KB
実行使用メモリ 121,968 KB
最終ジャッジ日時 2023-09-16 02:37:13
合計ジャッジ時間 8,931 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 241 ms
120,352 KB
testcase_32 AC 244 ms
121,968 KB
testcase_33 AC 189 ms
72,344 KB
testcase_34 AC 237 ms
120,280 KB
testcase_35 AC 245 ms
120,236 KB
testcase_36 AC 202 ms
81,200 KB
testcase_37 AC 196 ms
79,012 KB
testcase_38 AC 195 ms
83,576 KB
testcase_39 AC 207 ms
93,880 KB
testcase_40 AC 204 ms
89,384 KB
testcase_41 AC 208 ms
96,964 KB
testcase_42 AC 203 ms
94,648 KB
testcase_43 AC 198 ms
88,500 KB
testcase_44 AC 192 ms
79,428 KB
testcase_45 AC 23 ms
16,424 KB
testcase_46 AC 36 ms
23,344 KB
testcase_47 AC 7 ms
7,108 KB
testcase_48 AC 149 ms
62,924 KB
testcase_49 AC 210 ms
103,208 KB
testcase_50 AC 20 ms
13,348 KB
testcase_51 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
ll dp[5050][5050];
const ll MOD=998244353;
int main()
{
    int n; cin>>n;
  int a[5050];
  for(int i=0; i<n; i++){
    cin>>a[i];
  }
  int l[5050],r[5050];
  for(int i=0; i<n; i++){
    int l1=i,r1=i;
    while(l1>0 && a[l1-1]>=a[i]) l1--;
    while(r1<n-1 && a[r1+1]>=a[i]) r1++;
    l[i]=l1,r[i]=r1;
  }
  for(int i=0; i<n; i++) if(l[i]==0) dp[0][i]=1;
  for(int i=0; i<n-1; i++){
    ll s=0;
    for(int j=0; j<n; j++){
      (s+=dp[i][j])%=MOD;
      if(!(l[j]<=i+1 && i+1<=r[j])) continue;
      (dp[i+1][j]+=s)%=MOD;
    }
  }
  ll ans=0;
  for(int i=0; i<n; i++){
    if(r[i]==n-1) (ans+=dp[n-1][i])%=MOD;
  }
  cout<<ans<<endl;
    return 0;
}
0