結果
| 問題 | No.1247 ブロック登り |
| コンテスト | |
| ユーザー |
mugen_1337
|
| 提出日時 | 2020-10-03 01:33:34 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 6,562 bytes |
| 記録 | |
| コンパイル時間 | 2,155 ms |
| コンパイル使用メモリ | 205,552 KB |
| 最終ジャッジ日時 | 2025-01-15 01:35:10 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 MLE * 2 |
| other | AC * 9 TLE * 12 MLE * 5 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) begin(x),end(x)
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
struct IOSetup{
IOSetup(){
cin.tie(0);
ios::sync_with_stdio(0);
cout<<fixed<<setprecision(12);
}
} iosetup;
template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
return os;
}
template<typename T>
istream &operator>>(istream &is,vector<T>&v){
for(T &x:v)is>>x;
return is;
}
template<typename Monoid, typename OperatorMonoid=Monoid>
struct LazySegmentTree{
using F=function<Monoid(Monoid,Monoid)>;
using G=function<Monoid(Monoid,OperatorMonoid)>;
using H=function<OperatorMonoid(OperatorMonoid,OperatorMonoid)>;
int sz,height;
vector<Monoid> data;
vector<OperatorMonoid> lazy;
const F f;
const G g;
const H h;
const Monoid M1;
const OperatorMonoid OM0;
LazySegmentTree(int n,const F f,const G g,const H h,const Monoid &M1,const OperatorMonoid OM0)
: f(f),g(g),h(h),M1(M1),OM0(OM0) {
sz=1;height=0;
while(sz<n) sz<<=1,height++;
data.assign(2*sz,M1);lazy.assign(2*sz,OM0);
}
void set(int k,const Monoid &x){data[k+sz]=x;}
void build(){for(int k=sz-1;k>0;k--) data[k]=f(data[2*k+0],data[2*k+1]);}
inline void propagate(int k){
if(lazy[k]!=OM0){
lazy[2*k+0]=h(lazy[2*k+0],lazy[k]);
lazy[2*k+1]=h(lazy[2*k+1],lazy[k]);
data[k]=reflect(k);
lazy[k]=OM0;
}
}
inline Monoid reflect(int k){
return lazy[k]==OM0?data[k]:g(data[k],lazy[k]);
}
inline void recalc(int k){
while(k>>=1)data[k]=f(reflect(2*k+0),reflect(2*k+1));
}
inline void thrust(int k){
for(int i=height;i>0;i--) propagate(k>>i);
}
void update(int a,int b,const OperatorMonoid &x){
if(a>=b) return ;
thrust(a+=sz);thrust(b+=sz-1);
for(int l=a,r=b+1;l<r;l>>=1,r>>=1){
if(l&1) lazy[l]=h(lazy[l],x),l++;
if(r&1) --r,lazy[r]=h(lazy[r],x);
}
recalc(a);recalc(b);
}
Monoid query(int a,int b){
thrust(a+=sz);thrust(b+=sz-1);
Monoid L=M1,R=M1;
for(int l=a,r=b+1;l<r;l>>=1,r>>=1){
if(l&1) L=f(L,reflect(l++));
if(r&1) R=f(reflect(--r),R);
}
return f(L,R);
}
Monoid operator[](const int &k){
return query(k,k+1);
}
};
// // range set range min
// using M=ll;
// using OM=ll;
// const M M1=LINF;
// const OM OM0=-LINF;
// M segf(M a,M b){
// return (a<b?a:b);
// }
// M segg(M a,OM b){
// return (b==OM0?a:b);
// }
// OM segh(OM a,OM b){
// return (b==OM0?a:b);
// }
// // range set range max
// using M=ll;
// using OM=ll;
// const M M1=-LINF;
// const OM OM0=-LINF;
// M segf(M a,M b){
// return (a>b?a:b);
// }
// M segg(M a,OM b){
// return (b==OM0?a:b);
// }
// OM segh(OM a,OM b){
// return (b==OM0?a:b);
// }
// // range add range min
// using M=ll;
// using OM=ll;
// const M M1=LINF;
// const OM OM0=0;
// M segf(M a,M b){
// return (a<b?a:b);
// }
// M segg(M a,OM b){
// return a+b;
// }
// OM segh(OM a,OM b){
// return a+b;
// }
// // range add range max
// using M=ll;
// using OM=ll;
// const M M1=-LINF;
// const OM OM0=0;
// M segf(M a,M b){
// return (a>b?a:b);
// }
// M segg(M a,OM b){
// return a+b;
// }
// OM segh(OM a,OM b){
// return a+b;
// }
// // range set range sum (sum, count)
// using M=pair<ll,ll>;
// using OM=ll;
// const M M1=M(0,0);
// const OM OM0=-LINF;
// M segf(M a,M b){
// return M(a.first+b.first,a.second+b.second);
// }
// M segg(M a,OM b){
// return M(a.second*b,a.second);
// }
// ll segh(ll a,ll b){
// return (b==OM0?a:b);
// }
// range chmax range max
using M=ll;
using OM=ll;
const M M1=-LINF;
const OM OM0=-LINF;
M segf(M a,M b){
return a>b?a:b;
}
auto segg=segf;
auto segh=segf;
ll dp[310][310][310][2];
/*
dp[i][l][r][t]:
i回移動した,[l,r)決定済み,
t = 0 => 今,左端にいます
t = 1 => 右端 (r-1)にいます
*/
signed main(){
rep(i,310)rep(j,310)rep(k,310)rep(t,2)dp[i][j][k][t]=-LINF;
rep(i,310) dp[0][i][i][0]=0,dp[0][i][i][1]=0;
int n,k;cin>>n>>k;
vector<ll> a(n);
cin>>a;
if(k==1){
rep(i,n){
ll res=-LINF;
if(i) chmax(res,a[i-1]);
if(i<n-1) chmax(res,a[i+1]);
cout<<res<<endl;
}
return 0;
}
rep(i,k)rep(l,n+1)for(int r=l;r<=n;r++)rep(t,2){
int w=r-l;// width
ll mul=k-i;
// stay
if(i+2<=k and w>1) chmax(dp[i+2][l][r][t],dp[i][l][r][t]);
// left to right
if(t==0 and i+w-1<=k and w>0) chmax(dp[i+w-1][l][r][1],dp[i][l][r][t]);
// right to left
if(t==1 and i+w-1<=k and w>0) chmax(dp[i+w-1][l][r][0],dp[i][l][r][t]);
// left -> left-1
if(t==0 and l>0) chmax(dp[i+1][l-1][r][t],dp[i][l][r][t]+a[l-1]*mul);
// right -> right+1
if(t==1 and r<n) chmax(dp[i+1][l][r+1][t],dp[i][l][r][t]+a[r]*mul);
}
// rep(i,k+1)rep(l,n+1)for(int r=l;r<=n;r++){
// cout<<i<<" "<<l<<" ~ "<<r<<" : "<<dp[i][l][r][0]<<" "<<dp[i][l][r][1]<<endl;
// }
LazySegmentTree<M,OM> even(n,segf,segg,segh,M1,OM0),odd(n,segf,segg,segh,M1,OM0);
even.build();odd.build();
rep(i,k+1)rep(l,n)for(int r=l;r<=n;r++){
int w=r-l;
if(w<=1 or (dp[i][l][r][0]<=-LINF+INF+INF+INF and dp[i][l][r][1]<=-LINF+INF+INF+INF)) continue;
int rem=k-i+1;// 残り移動回数
if((l+rem)%2==0) even.update(max(0,l-1),min(n,min(r+1,l+rem+2)),dp[i][l][r][0]);
else odd.update(max(0,l-1),min(n,min(r+1,l+rem+2)),dp[i][l][r][0]);
if((r-1+rem)%2==0) even.update(max(0,max(l-1,r-2-rem)),min(n,r+1),dp[i][l][r][1]);
else odd.update(max(0,max(l-1,r-2-rem)),min(n,r+1),dp[i][l][r][1]);
}
rep(i,n){
if(i%2) cout<<odd[i]<<endl;
else cout<<even[i]<<endl;
}
return 0;
}
mugen_1337