結果

問題 No.1247 ブロック登り
ユーザー 👑 potato167potato167
提出日時 2022-03-01 03:13:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 4,046 bytes
コンパイル時間 2,606 ms
コンパイル使用メモリ 222,780 KB
実行使用メモリ 814,576 KB
最終ジャッジ日時 2023-09-21 12:10:09
合計ジャッジ時間 6,403 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 33 ms
16,184 KB
testcase_08 AC 37 ms
17,872 KB
testcase_09 AC 10 ms
7,512 KB
testcase_10 AC 14 ms
8,660 KB
testcase_11 MLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll ILL=1167167167167167167;
const int INF=1100000000;
const ll mod=1e9+7;
#define rep(i,a) for (int i=0;i<a;i++)
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}


namespace po167{
template<class T>
struct my_set_max{
	priority_queue<T> exist;
	priority_queue<T> absent;
	void op(){
		while(!absent.empty()&&exist.top()==absent.top()){
			exist.pop();
			absent.pop();
		}
	}
	size_t size(){
		op();
		return exist.size()-absent.size();
	}
	T get(){
		op();
		return exist.top();
	}
	void insert(T a){
		exist.push(a);
	}
	void delate(T a){
		absent.push(a);
	}
};
template<class T>
struct my_set_min{
	priority_queue<T, vector<T>, greater<T>> exist;
	priority_queue<T, vector<T>, greater<T>> absent;
	void op(){
		while(!absent.empty()&&exist.top()==absent.top()){
			exist.pop();
			absent.pop();
		}
	}
	T get(){
		op();
		return exist.top();
	}
	size_t size(){
		op();
		return exist.size()-absent.size();
	}
	void insert(T a){
		exist.push(a);
	}
	void delate(T a){
		absent.push(a);
	}
};
template<class T>
struct my_set_med{
	my_set_max<T> pq_left;
	my_set_min<T> pq_right;
	void op(){
		while(pq_left.size()>pq_right.size()){
			T tmp=pq_left.get();
			pq_left.delate(tmp);
			pq_right.insert(tmp);
		}
		while(pq_left.size()<pq_right.size()){
			T tmp=pq_right.get();
			pq_right.delate(tmp);
			pq_left.insert(tmp);
		}
	}
	void insert(T a){
		if(pq_left.size()!=0&&pq_left.get()>a) pq_left.insert(a);
		else pq_right.insert(a);
	}
	void delate(T a){
		if(pq_left.size()!=0&&pq_left.get()>=a) pq_left.delate(a);
		else pq_right.delate(a);
	}
	std::pair<T,T> get(){
		op();
		assert(pq_left.size()!=0);
		if(pq_left.size()==pq_right.size()){
			return {pq_left.get(),pq_right.get()};
		}
		else return {pq_left.get(),pq_left.get()};
	}
	size_t size(){
		return pq_left.size()+pq_right.size();
	}
};
}
using po167::my_set_max;
using po167::my_set_min;
using po167::my_set_med;

void solve();
// oddloop
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t=1;
	//cin>>t;
	rep(i,t) solve();
}

void solve(){
	int N,K;
	cin>>N>>K;
	vector<int> A(N);
	rep(i,N) cin>>A[i];
	vector<vector<vector<vector<int>>>> dp(K,vector<vector<vector<int>>>(N,vector<vector<int>>(N,vector<int>(2,-INF))));
	rep(i,N-1){
		dp[K-1][i][i+1][0]=A[i]*K+A[i+1]*(K-1);
		dp[K-1][i][i+1][1]=A[i]*(K-1)+A[i+1]*K;
	}
	vector<vector<pair<int,int>>> p(N+2);
	for(int c=K-1;c>=0;c--){
		rep(j,N) rep(i,j) rep(k,2){
			if(c<K-2) chmax(dp[c][i][j][k],dp[c+2][i][j][k]);
			if(dp[c][i][j][k]==-INF) continue;
			//p
			int l=i,r=min(j,i+c),d=i;
			if(k==0) l=max(i,j-c),r=j,d=j;
			d+=c;
			d%=2;
			if(r%2!=d) r--;
			if(l%2!=d) l++;
			r+=2;
			p[l].push_back({dp[c][i][j][k],1});
			p[r].push_back({dp[c][i][j][k],-1});
			if(c==0) continue;
			if(k==0){
				if(j+1!=N) chmax(dp[c-1][i][j+1][0],dp[c][i][j][k]+A[j+1]*(c-1));
				if(i!=0&&c>=j-i+1) chmax(dp[c-j+i-1][i-1][j][1],dp[c][i][j][k]+A[i-1]*(c-j+i-1));
			}else{
				if(j+1!=N&&c>=j-i+1) chmax(dp[c-j+i-1][i][j+1][0],dp[c][i][j][k]+A[j+1]*(c-j+i-1));
				if(i!=0) chmax(dp[c-1][i-1][j][1],dp[c][i][j][k]+A[i-1]*(c-1));
			}
		}
	}
	vector<my_set_max<ll>> q(2);
	rep(i,N){
		for(auto x:p[i]){
			if(x.second==1) q[i%2].insert(x.first);
			else q[i%2].delate(x.first);
		}
		cout<<q[i%2].get()<<"\n";
	}
}

0