結果
| 問題 | No.2232 Miser's Gift |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-12-29 13:09:38 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 46 ms / 2,000 ms |
| コード長 | 5,230 bytes |
| 記録 | |
| コンパイル時間 | 3,440 ms |
| コンパイル使用メモリ | 288,984 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-12-29 13:09:47 |
| 合計ジャッジ時間 | 8,383 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 55 |
ソースコード
#include<bits/stdc++.h>
#if __has_include(<atcoder/all>)
#endif
using namespace std;
#define eb emplace_back
#define LL(...) ll __VA_ARGS__;lin(__VA_ARGS__)
#define RDVV(T,n,...) vec<T>__VA_ARGS__;fe(refs(__VA_ARGS__),e)e.get().resizes(n);vin(__VA_ARGS__)
#define VV(n,...) RDVV(ll,n,__VA_ARGS__)
#define fo(i,...) for(auto[i,i##stop,i##step]=for_range<ll>(0,__VA_ARGS__);i<i##stop;i+=i##step)
#define fe(a,e,...) for(auto&&__VA_OPT__([)e __VA_OPT__(,__VA_ARGS__]):a)
#define defpp template<ostream&o=cout>void pp(const auto&...a){[[maybe_unused]]const char*c="";((o<<c<<a,c=" "),...);o<<'\n';}void epp(const auto&...a){pp<cerr>(a...);}
#define entry defpp void main();void main2();}int main(){my::io();my::main();}namespace my{
namespace my{
void io(){cin.tie(nullptr)->sync_with_stdio(0);cout<<fixed<<setprecision(15);}
using ll=long long;
constexpr auto refs(auto&...a){return array{ref(a)...};}
template<class T>constexpr auto for_range(T s,T b){T a=0;if(s)swap(a,b);return array{a-s,b,1-s*2};}
template<class T>constexpr auto for_range(T s,T a,T b,T c=1){return array{a-s,b,(1-s*2)*c};}
void lin(auto&...a){(cin>>...>>a);}
void vin(auto&...a){fo(i,(a.size()&...))(cin>>...>>a[i]);}
constexpr ll size10(auto x){x|=1;ll r=0;while(x>0)x/=10,++r;return r;}
template<class T>constexpr ll maxsize10(){return size10(numeric_limits<T>::max());}
auto max(auto...a){return max(initializer_list<common_type_t<decltype(a)...>>{a...});}
template<class A,class B=A>struct pair{
A a;B b;
pair()=default;
pair(A a,B b):a(a),b(b){}
auto operator<=>(const pair&)const=default;
};
template<bool is_negative=false>struct infinity{
template<integral T>static constexpr T ones(size_t n){return n?ones<T>(n-1)*10+1:0;}
template<integral T>constexpr operator T()const{return ones<T>(maxsize10<T>())*(1-is_negative*2);}
constexpr auto operator-()const{return infinity<!is_negative>();}
};
constexpr infinity oo;
template<class...A>using pack_back_t=tuple_element_t<sizeof...(A)-1,tuple<A...>>;
}
namespace my{
template<class V>concept vectorial=is_base_of_v<vector<typename remove_cvref_t<V>::value_type>,remove_cvref_t<V>>;
template<class V>constexpr int depth=0;
template<vectorial V>constexpr int depth<V> =depth<typename V::value_type>+1;
template<class T>struct core_t_helper{using type=T;};
template<vectorial V>struct core_t_helper<V>{using type=typename core_t_helper<typename V::value_type>::type;};
template<class T>using core_t=core_t_helper<T>::type;
template<class V>struct vec;
template<int D,class T>struct hvec_helper{using type=vec<typename hvec_helper<D-1,T>::type>;};
template<class T>struct hvec_helper<0,T>{using type=T;};
template<int D,class T>using hvec=hvec_helper<D,T>::type;
template<class V>struct vec:vector<V>{
static constexpr int D=depth<V>+1;
using C=core_t<V>;
using vector<V>::vector;
vec(const auto&...a)requires(sizeof...(a)>=3){resizes(a...);}
void resizes(const auto&...a){if constexpr(sizeof...(a)==D)*this=make(a...,C{});else*this=make(a...);}
static auto make(ll n,const auto&...a){
if constexpr(sizeof...(a)==1)return vec<C>(n,array{a...}[0]);
else return vec<decltype(make(a...))>(n,make(a...));
}
ll size()const{return vector<V>::size();}
vec&fill(C x){if constexpr(D>1){ }else std::fill(this->begin(),this->end(),x);return*this;}
auto&emplace_back(auto&&...a){vector<V>::emplace_back(std::forward<decltype(a)>(a)...);return*this;}
template<class T=C>auto fold(auto&&f)const{
pair<T,bool>res{};
fe(*this,e){
if constexpr(!vectorial<V>){
if(res.b)f(res.a,e);
else res={e,1};
}else { }
}
return res;
}
auto min()const{return fold([](auto&a,auto b){if(b<a)a=b;}).a;}
vec scan(auto&&f)const{vec res=*this;fo(i,size()-1)res[i+1]=f(res[i],(*this)[i+1]);return res;}
};
template<class...A>requires(sizeof...(A)>=2)vec(const A&...a)->vec<hvec<sizeof...(A)-2,pack_back_t<A...>>>;
}
namespace my{
template<class T=ll>auto pow2_partition(ll n){vec<T>r;for(ll k=1;k<=n;k<<=1)r.eb(k),n-=k;if(n)r.eb(n);return r;}
}
namespace my{
template<class T>struct max_node{
using S=T;
static S op(S a,S b){return max(a,b);}
static S e(){return-oo;}
};
}
namespace my{
template<class T,T op(T,T),T e()>auto knapsack_limitations_nonneg_enumerate(const vec<T>&a,const vec<T>&b,const vec<T>&c,ll X){
assert(a.min()>=0);
ll n=a.size();
vec dp(2,X+1,e());
dp[0][0]=0;
fo(i,n){
fe(pow2_partition(c[i]),t){
dp[1].fill(e());
fo(j,X+1){
if(dp[0][j]==e())continue;
dp[1][j]=op(dp[1][j],dp[0][j]);
ll nj=j+a[i]*t;
if(nj<=X)dp[1][nj]=op(dp[1][nj],dp[0][j]+b[i]*t);
}
swap(dp[0],dp[1]);
}
}
return dp[0];
}
template<class T,T op(T,T),T e()>auto knapsack_01_nonneg_enumerate(const vec<T>&a,const vec<T>&b,ll X){
return knapsack_limitations_nonneg_enumerate<T,op,e>(a,b,vec<T>(a.size(),1),X);
}
template<class M>auto knapsack_01_nonneg_enumerate(const vec<typename M::S>&a,const vec<typename M::S>&b,ll X){
return knapsack_01_nonneg_enumerate<typename M::S,M::op,M::e>(a,b,X);
}
}
namespace my{entry
void main(){
LL(N,M);
VV(N,a,b);
auto dp=knapsack_01_nonneg_enumerate<max_node<ll>>(a,b,M);
dp=dp.scan(max<ll,ll>);
fo(X,1,M+1)pp(dp[M]-dp[M-X]+1);
}}