結果
| 問題 |
No.1378 Flattening
|
| コンテスト | |
| ユーザー |
IKyopro
|
| 提出日時 | 2020-10-31 15:07:43 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,624 bytes |
| コンパイル時間 | 2,329 ms |
| コンパイル使用メモリ | 201,032 KB |
| 最終ジャッジ日時 | 2025-01-15 18:33:03 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 1 |
| other | AC * 19 WA * 31 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
template<class T> bool chmin(T& a,T b){if(a>b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b){if(a<b) {a = b; return true;} return false;}
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << " = " << (x) << endl;
constexpr ll mod = 998244353;
struct mint {
ll x;
mint(ll x=0):x((x%mod+mod)%mod){}
friend ostream &operator<<(ostream& os,const mint& a){
return os << a.x;
}
friend istream &operator>>(istream& is,mint& a){
ll t;
is >> t;
a = mint(t);
return (is);
}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res+=a;
}
mint operator-(const mint a) const {
mint res(*this);
return res-=a;
}
mint operator*(const mint a) const {
mint res(*this);
return res*=a;
}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
// for prime mod
mint inv() const {
return pow(mod-2);
}
mint& operator/=(const mint a) {
return (*this) *= a.inv();
}
mint operator/(const mint a) const {
mint res(*this);
return res/=a;
}
bool operator==(const mint a)const{
return x==a.x;
}
};
template<typename Monoid,typename F>
class SegmentTree{
private:
int sz;
vector<Monoid> seg;
const F op;
const Monoid e;
public:
SegmentTree(int n,const F op,const Monoid &e):op(op),e(e){
sz = 1;
while(sz<=n) sz <<= 1;
seg.assign(2*sz,e);
}
void set(int k, const Monoid &x){
seg[k+sz] = x;
}
void build(){
for(int i=sz-1;i>0;i--){
seg[i] = op(seg[2*i],seg[2*i+1]);
}
}
void update(int k,const Monoid &x){
k += sz;
seg[k] = x;
while(k>>=1){
seg[k] = op(seg[2*k],seg[2*k+1]);
}
}
Monoid query(int l,int r){
Monoid L = e,R = e;
for(l+=sz,r+=sz;l<r;l>>=1,r>>=1){
if(l&1) L = op(L,seg[l++]);
if(r&1) R = op(seg[--r],R);
}
return op(L,R);
}
Monoid operator[](const int &k)const{
return seg[k+sz];
}
};
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vec<int> A(N);
vec<int> pos(N);
vvec<int> mi(N+1,vec<int>(N+1,N));
for(int i=0;i<N;i++){
cin >> A[i];
A[i]--;
pos[A[i]] = i;
}
for(int l=0;l<N;l++) for(int r=l+1;r<N;r++) mi[l][r] = min(mi[l][r-1],A[r-1]);
vec<mint> dp(N,0);
vec<mint> R(N+1,1),L(N+1);
mint sum = 1;
for(int i=0;i<N;i++){
vec<mint> ndp(N);
for(int j=0;j<N;j++){
if(j<=A[i]) ndp[j] += dp[j];
if(i<=pos[j] && mi[i][pos[j]]>j) ndp[j] += L[j]+R[j+1];
if(pos[j]<i && mi[pos[j]][i+1]==j) ndp[j] += L[j];
}
dp.swap(ndp);
R[N] = 0;
for(int j=N-1;j>=0;j--) R[j] = R[j+1]+dp[j];
for(int j=0;j<N;j++) L[j+1] = L[j]+(pos[j]<=i? dp[j]:0);
}
cout << accumulate(all(dp),(mint) 0) << "\n";
}
IKyopro