結果
問題 | No.1378 Flattening |
ユーザー | carrot46 |
提出日時 | 2021-02-06 20:58:13 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,851 bytes |
コンパイル時間 | 1,767 ms |
コンパイル使用メモリ | 176,712 KB |
実行使用メモリ | 785,408 KB |
最終ジャッジ日時 | 2024-07-03 09:07:04 |
合計ジャッジ時間 | 12,784 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | RE | - |
testcase_04 | WA | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | WA | - |
testcase_09 | RE | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | AC | 3 ms
6,940 KB |
testcase_18 | RE | - |
testcase_19 | WA | - |
testcase_20 | RE | - |
testcase_21 | WA | - |
testcase_22 | RE | - |
testcase_23 | WA | - |
testcase_24 | RE | - |
testcase_25 | WA | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | TLE | - |
testcase_32 | TLE | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
testcase_48 | -- | - |
testcase_49 | -- | - |
testcase_50 | -- | - |
testcase_51 | -- | - |
ソースコード
#include <bits/stdc++.h> //#include <chrono> //#pragma GCC optimize("Ofast") using namespace std; #define reps(i,s,n) for(int i = s; i < n; i++) #define rep(i,n) reps(i,0,n) #define Rreps(i,n,e) for(int i = n - 1; i >= e; --i) #define Rrep(i,n) Rreps(i,n,0) #define ALL(a) a.begin(), a.end() using ll = long long; using vec = vector<ll>; using mat = vector<vec>; ll N,M,H,W,Q,K,A,B; string S; using P = pair<ll, ll>; const ll INF = (1LL<<60); template<class T> bool chmin(T &a, const T b){ if(a > b) {a = b; return true;} else return false; } template<class T> bool chmax(T &a, const T b){ if(a < b) {a = b; return true;} else return false; } template<class T> void my_printv(std::vector<T> v,bool endline = true){ if(!v.empty()){ for(std::size_t i{}; i<v.size()-1; ++i) std::cout<<v[i]<<" "; std::cout<<v.back(); } if(endline) std::cout<<std::endl; } template <unsigned long long mod > class modint{ public: ll x; constexpr modint(){x = 0;} constexpr modint(ll _x) : x((_x < 0 ? ((_x += (LLONG_MAX / mod) * mod) < 0 ? _x + (LLONG_MAX / mod) * mod : _x) : _x)%mod){} constexpr modint set_raw(ll _x){ //_x in [0, mod) x = _x; return *this; } constexpr modint operator-(){ return x == 0 ? 0 : mod - x; } constexpr modint& operator+=(const modint& a){ if((x += a.x) >= mod) x -= mod; return *this; } constexpr modint operator+(const modint& a) const{ return modint(*this) += a; } constexpr modint& operator-=(const modint& a){ if((x -= a.x) < 0) x += mod; return *this; } constexpr modint operator-(const modint& a) const{ return modint(*this) -= a; } constexpr modint& operator*=(const modint& a){ (x *= a.x)%=mod; return *this; } constexpr modint operator*(const modint& a) const{ return modint(*this) *= a; } constexpr modint pow(unsigned long long pw) const{ modint res(1), comp(*this); while(pw){ if(pw&1) res *= comp; comp *= comp; pw >>= 1; } return res; } //以下、modが素数のときのみ constexpr modint inv() const{ if(x == 2) return (mod + 1) >> 1; return modint(*this).pow(mod - 2); } constexpr modint& operator/=(const modint &a){ (x *= a.inv().x)%=mod; return *this; } constexpr modint operator/(const modint &a) const{ return modint(*this) /= a; } constexpr bool sqrt(bool find_mini = false) { if(x == 0) return true; modint jge = this->pow((mod - 1)>>1); if(jge.x + 1 == mod) return false; if((mod&3) == 3){ *this = this->pow((mod + 1)>>2); }else{ int m = 0; modint c, t; if(mod == 998244353){ m = 23; c = 15311432; t = this->pow(119); *this = this->pow(60); }else{ ll q = mod - 1; modint z = 2; while(!(q&1)){q>>=1; ++m;} while(z.pow((mod-1)>>1).x == 1) z += 1; c = z.pow(q); t = this->pow(q); *this = this->pow((q+1)>>1); } while(t.x != 1){ modint cpy_t = t; int pw = m; while(cpy_t.x != 1){--pw; cpy_t *= cpy_t;} rep(i, pw-1) c *= c; (*this) *= c; c *= c; t *= c; m -= pw; } } if(find_mini) this->x = min(this->x, (ll)mod - this->x); return true; } }; #define mod1 998244353 using mint = modint<mod1>; ostream& operator<<(ostream& os, const mint& a){ os << a.x; return os; } using vm = vector<mint>; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cin>>N; vec a(N), pos(N); mat minielem(N, vec(N + 1)); vector<vm> dp(N, vm(N + 1)), lsum(N, vm(N + 1)), rsum(N, vm(N + 1)); rep(i, N){ cin>>a[i]; --a[i]; pos[a[i]] = i; minielem[i][i+1] = a[i]; } auto init = [](vector<vm> &d, bool if_sum){ int n = d.size(); rep(i, n) { d[i][i] = 1; d[i][i+1] = 1 + if_sum; } }; auto pr = [](vector<vm> &v){ for(vm &c : v) my_printv(c); cout<<endl; }; init(dp, false); init(lsum, true); init(rsum, true); reps(len, 2, N + 1){ rep(l, N - len + 1){ int r = l + len; int m = (minielem[l][r] = min(minielem[l][r-1], minielem[r-1][r])); dp[l][r] = lsum[l][pos[m]] * rsum[pos[m] + 1][r]; lsum[l][r] = lsum[l][r-1] + dp[l][r]; rsum[l][r] = rsum[l+1][r] + dp[l][r]; } } cout<<dp[0][N]<<endl; }