結果

問題 No.974 最後の日までに
ユーザー hotman78hotman78
提出日時 2020-01-17 23:19:48
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 5,945 bytes
コンパイル時間 5,292 ms
コンパイル使用メモリ 381,332 KB
実行使用メモリ 120,104 KB
最終ジャッジ日時 2023-09-08 07:23:10
合計ジャッジ時間 12,974 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
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 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:41:19: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
   41 | inline bool chmin(auto& s,const auto& t){bool res=s>t;s=min(s,t);return res;}
      |                   ^~~~
main.cpp:41:33: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
   41 | inline bool chmin(auto& s,const auto& t){bool res=s>t;s=min(s,t);return res;}
      |                                 ^~~~
main.cpp:42:19: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
   42 | inline bool chmax(auto& s,const auto& t){bool res=s<t;s=max(s,t);return res;}
      |                   ^~~~
main.cpp:42:33: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
   42 | inline bool chmax(auto& s,const auto& t){bool res=s<t;s=max(s,t);return res;}
      |                                 ^~~~
main.cpp:125:17: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
  125 |     auto update(auto a,auto b){return b==ee?a:b;}
      |                 ^~~~
main.cpp:125:24: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
  125 |     auto update(auto a,auto b){return b==ee?a:b;}
      |                        ^~~~

ソースコード

diff #

#pragma GCC optimize("Ofast","unroll-loops")
//#pragma GCC push_options
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#include <xmmintrin.h>
#include <immintrin.h>
using namespace::std;
__attribute__((constructor))void init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
template<typename T>using pbds=__gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T>using pbds_map=__gnu_pbds::tree<T,T,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T,typename E>using hash_map=__gnu_pbds::gp_hash_table<T,E>;
template<typename T>using pqueue =__gnu_pbds::priority_queue<T, less<T>,__gnu_pbds::rc_binomial_heap_tag>;
typedef long long lint;
#define INF (1LL<<60)
#define IINF (1<<30)
#define EPS (1e-10)
#define MOD 1000000007LL
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
template<typename T>inline void numout(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i<INF/2?i:"INF";f=1;}cout<<endl;}
template<typename T>inline void numout2(T t){for(auto i:t)numout(i);}
template<typename T>inline void output(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}
template<typename T>inline void output2(T t){for(auto i:t)output(i);}
template<typename T>inline void _output(T t){bool f=0;for(lint i=0;i<t.size();i++){cout<<f?"":" "<<t[i];f=1;}cout<<endl;}
template<typename T>inline void _output2(T t){for(lint i=0;i<t.size();i++)output(t[i]);}
#define rep(i,n) for(lint i=0;i<lint(n);++i)
#define repi(i,a,b) for(lint i=lint(a);i<(lint)(b);++i)
#define rrep(i,n) for(lint i=lint(n)-1;i>=0;--i)
#define rrepi(i,a,b) for(lint i=lint(b)-1;i>=lint(a);--i)
#define irep(i) for(lint i=0;;++i)
#define all(n) begin(n),end(n)
#define dist(a,b,c,d) sqrt(pow(a-c,2)+pow(b-d,2))
inline lint gcd(lint A,lint B){return B?gcd(B,A%B):A;}
inline lint lcm(lint A,lint B){return A/gcd(A,B)*B;}
inline bool chmin(auto& s,const auto& t){bool res=s>t;s=min(s,t);return res;}
inline bool chmax(auto& s,const auto& t){bool res=s<t;s=max(s,t);return res;}
const vector<lint> dx={1,0,-1,0,1,1,-1,-1};
const vector<lint> dy={0,1,0,-1,1,-1,1,-1};
#define SUM(v) accumulate(all(v),0LL)
auto call=[](auto f,auto... args){return f(f,args...);};

template<typename T=long long,typename E=T>
struct dynamic_lazy_segment{
    private:
    T et;
    E ee;
    lint n;
    lint size;
    struct node{
        T val;
        E lazy;
        node *lch,*rch;
        node(dynamic_lazy_segment& seg):lch(nullptr),rch(nullptr){val=seg.et;lazy=seg.ee;}
    };
    node* root;
    public:
    dynamic_lazy_segment(int size,T et,E ee):et(et),ee(ee),n(1),size(size){
        while(n<size)n<<=1;
        root=new node(*this);
    }
    dynamic_lazy_segment(T et,E ee):et(et),ee(ee),n(1LL<<60),size(1LL<<60){
        root=new node(*this);
    }
    inline void update(lint a,lint b,const E& x){
        update(a,b,x,0,0,n,root);
    }
    inline T get(lint a,lint b){
        return get(a,b,0,0,n,root);
    }
    private:
    //0-indexed [a,b)
    T update(const lint& a,const lint& b,const E& x,const lint& k,const lint& l,const lint& r,node* t){
        eval(t,r-l,k);
        //区間外
        if(r<=a||b<=l)return t->val;
        //全部区間内
        if(a<=l&&r<=b){
            t->lazy=g(t->lazy,x);
            eval(t,r-l,k);
            return h(t->val,t->lazy,r-l);
        }
        //一部区間内
        if(!t->lch)t->lch=new node(*this);
        if(!t->rch)t->rch=new node(*this);
        return t->val=f(update(a,b,x,2*k+1,l,(l+r)/2,t->lch),update(a,b,x,2*k+2,(l+r)/2,r,t->rch));
    }
    //0-indexed [a,b)
    T get(const lint& a,const lint& b,const lint& k,const lint& l,const lint& r,node* t){
        eval(t,r-l,k);
        //区間外
        if(r<=a||b<=l)return et;
        //全部区間内
        if(a<=l&&r<=b)return t->val;
        //一部区間内
        if(!t->lch)t->lch=new node(*this);
        if(!t->rch)t->rch=new node(*this);
        return f(get(a,b,2*k+1,l,(l+r)/2,t->lch),get(a,b,2*k+2,(l+r)/2,r,t->rch));
    }
    inline void eval(node* t,const int& len,const int& k){
        if(t->lazy==ee) return;
        if(k*2+1<n*2-1){
            if(t->lch==nullptr)t->lch=new node(*this);
            if(t->rch==nullptr)t->rch=new node(*this);
            t->lch->lazy=g(t->lch->lazy,t->lazy);
            t->rch->lazy=g(t->rch->lazy,t->lazy);
        }
        t->val=h(t->val,t->lazy,len);
        t->lazy=ee;
    }
    T f(T a,T b){
        return max(a,b);
    }
    T h(T a,E b,lint len){
        return update(a,b);
    }
    E g(E a,E b){
        return update(a,b);
    }
    auto update(auto a,auto b){return b==ee?a:b;}
};

int main(){
    lint n;
    cin>>n;
    vec a(n),b(n),c(n);
    rep(i,n)cin>>a[i]>>b[i]>>c[i];
    vector<dynamic_lazy_segment<lint,lint>>seg(n+10,dynamic_lazy_segment<lint,lint>(-INF,-INF));
    priority_queue<tuple<lint,lint,lint>,vector<tuple<lint,lint,lint>>,greater<tuple<lint,lint,lint>>>que;
    que.emplace(0,0,0);
    lint ans=0;
    while(!que.empty()){
        lint day,money,like;
        tie(day,money,like)=que.top();
        que.pop();
        if(day==n){
            if(money>=0)chmax(ans,like);
            continue;
        }
        if(seg[day+1].get(like,INF)<money+a[day]){
            seg[day+1].update(like,like+1,money+a[day]);
            que.emplace(day+1,money+a[day],like);
        }
        if(day!=n-1)if(seg[day+2].get(like+b[day+1],INF)<money-c[day+1]){
            seg[day+2].update(like+b[day+1],like+b[day+1]+1,money-c[day+1]);
            que.emplace(day+2,money-c[day+1],like+b[day+1]);
        }
    }
    cout<<ans<<endl;
}
0