結果

問題 No.409 ダイエット
ユーザー jelljell
提出日時 2018-10-23 18:03:54
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 571 ms / 2,000 ms
コード長 6,767 bytes
コンパイル時間 1,818 ms
コンパイル使用メモリ 179,212 KB
実行使用メモリ 74,584 KB
最終ジャッジ日時 2024-11-19 04:27:25
合計ジャッジ時間 18,610 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,820 KB
testcase_01 AC 2 ms
6,820 KB
testcase_02 AC 2 ms
6,816 KB
testcase_03 AC 2 ms
6,816 KB
testcase_04 AC 2 ms
6,816 KB
testcase_05 AC 2 ms
6,816 KB
testcase_06 AC 2 ms
6,816 KB
testcase_07 AC 2 ms
6,816 KB
testcase_08 AC 2 ms
6,820 KB
testcase_09 AC 2 ms
6,820 KB
testcase_10 AC 2 ms
6,820 KB
testcase_11 AC 2 ms
6,816 KB
testcase_12 AC 2 ms
6,820 KB
testcase_13 AC 2 ms
6,816 KB
testcase_14 AC 3 ms
6,816 KB
testcase_15 AC 2 ms
6,816 KB
testcase_16 AC 2 ms
6,816 KB
testcase_17 AC 2 ms
6,820 KB
testcase_18 AC 2 ms
6,816 KB
testcase_19 AC 2 ms
6,816 KB
testcase_20 AC 2 ms
6,816 KB
testcase_21 AC 2 ms
6,820 KB
testcase_22 AC 2 ms
6,816 KB
testcase_23 AC 3 ms
6,816 KB
testcase_24 AC 2 ms
6,820 KB
testcase_25 AC 2 ms
6,820 KB
testcase_26 AC 2 ms
6,820 KB
testcase_27 AC 2 ms
6,820 KB
testcase_28 AC 2 ms
6,816 KB
testcase_29 AC 2 ms
6,816 KB
testcase_30 AC 2 ms
6,820 KB
testcase_31 AC 2 ms
6,820 KB
testcase_32 AC 2 ms
6,820 KB
testcase_33 AC 2 ms
6,820 KB
testcase_34 AC 2 ms
6,816 KB
testcase_35 AC 5 ms
6,816 KB
testcase_36 AC 5 ms
6,820 KB
testcase_37 AC 5 ms
6,820 KB
testcase_38 AC 5 ms
6,816 KB
testcase_39 AC 5 ms
6,820 KB
testcase_40 AC 6 ms
6,820 KB
testcase_41 AC 6 ms
6,816 KB
testcase_42 AC 6 ms
6,816 KB
testcase_43 AC 6 ms
6,820 KB
testcase_44 AC 6 ms
6,816 KB
testcase_45 AC 6 ms
6,816 KB
testcase_46 AC 5 ms
6,820 KB
testcase_47 AC 5 ms
6,816 KB
testcase_48 AC 5 ms
6,816 KB
testcase_49 AC 6 ms
6,820 KB
testcase_50 AC 5 ms
6,816 KB
testcase_51 AC 6 ms
6,820 KB
testcase_52 AC 6 ms
6,816 KB
testcase_53 AC 6 ms
6,816 KB
testcase_54 AC 5 ms
6,816 KB
testcase_55 AC 263 ms
39,292 KB
testcase_56 AC 210 ms
73,028 KB
testcase_57 AC 568 ms
74,584 KB
testcase_58 AC 215 ms
25,760 KB
testcase_59 AC 333 ms
42,384 KB
testcase_60 AC 191 ms
24,916 KB
testcase_61 AC 480 ms
46,936 KB
testcase_62 AC 549 ms
73,620 KB
testcase_63 AC 478 ms
46,996 KB
testcase_64 AC 250 ms
38,588 KB
testcase_65 AC 526 ms
72,264 KB
testcase_66 AC 561 ms
74,264 KB
testcase_67 AC 396 ms
44,788 KB
testcase_68 AC 326 ms
42,476 KB
testcase_69 AC 449 ms
46,460 KB
testcase_70 AC 450 ms
45,812 KB
testcase_71 AC 232 ms
26,392 KB
testcase_72 AC 571 ms
73,300 KB
testcase_73 AC 506 ms
47,164 KB
testcase_74 AC 305 ms
40,420 KB
testcase_75 AC 535 ms
72,240 KB
testcase_76 AC 359 ms
43,740 KB
testcase_77 AC 225 ms
26,192 KB
testcase_78 AC 269 ms
39,244 KB
testcase_79 AC 207 ms
25,384 KB
testcase_80 AC 539 ms
72,828 KB
testcase_81 AC 499 ms
47,152 KB
testcase_82 AC 370 ms
43,584 KB
testcase_83 AC 389 ms
44,032 KB
testcase_84 AC 323 ms
40,932 KB
testcase_85 AC 30 ms
9,624 KB
testcase_86 AC 315 ms
40,356 KB
testcase_87 AC 446 ms
45,760 KB
testcase_88 AC 165 ms
24,148 KB
testcase_89 AC 405 ms
43,480 KB
testcase_90 AC 163 ms
23,908 KB
testcase_91 AC 437 ms
44,168 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:161:20: warning: ‘idx’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  161 |         return data[idx];
      |                ~~~~^
main.cpp:152:24: note: ‘idx’ was declared here
  152 |         int latest = 0,idx;
      |                        ^~~
main.cpp:161:20: warning: ‘idx’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  161 |         return data[idx];
      |                ~~~~^
main.cpp:152:24: note: ‘idx’ was declared here
  152 |         int latest = 0,idx;
      |                        ^~~
main.cpp:161:20: warning: ‘idx’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  161 |         return data[idx];
      |                ~~~~^
main.cpp:152:24: note: ‘idx’ was declared here
  152 |         int latest = 0,idx;
      |                        ^~~
main.cpp:161:20: warning: ‘idx’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  161 |         return data[idx];
      |                ~~~~^
main.cpp:152:24: note: ‘idx’ was declared here
  152 |         int latest = 0,idx;
      |                        ^~~
main.cpp:161:20: warning: ‘idx’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  161 |         return data[idx];
      |                ~~~~^
main.cpp:152:24: note: ‘idx’ was declared here
  152 |         int latest = 0,idx;
      |                        ^~~
main.cpp:161:20: warning: ‘idx’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  161 |         return data[idx];
      |                ~~~~^
main.cpp:152:24: note: ‘idx’ was declared here
  152 |         int latest = 0,idx;
      |                        ^~~
main.cpp:161:20: warning: ‘idx’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  161 |         return data[idx];
      |                ~~~~^
main.cpp:152:24: note: ‘idx’ was declared here
  152 |        

ソースコード

diff #

/*
#include <boost/functional/hash.hpp>
#include <boost/multiprecision/cpp_int.hpp>
typedef boost::multiprecision::cpp_int mlint;
*/
#include <bits/stdc++.h>
using namespace std;

#define esc(x) cout << (x) << endl,exit(0)
#define fcout(d) cout << fixed << setprecision(d)
#define each(i,v) for(auto i = begin(v),end_copy = end(v); i != end_copy; ++i)
#define reach(i,v) for(auto i = rbegin(v),rend_copy = rend(v); i != rend_copy; ++i)
#define urep(i,s,t) for(int i = (int)(s),t_copy = (int)t; i <= t_copy; ++i)
#define drep(i,s,t) for(int i = (int)(s),t_copy = (int)t; i >= t_copy; --i)
#define rep(i,n) urep(i,0,(n) - 1)
#define rep1(i,n) urep(i,1,(n))
#define rrep(i,n) drep(i,(n) - 1,0)
#define all(v) begin(v),end(v)
#define rall(v) rbegin(v),rend(v)
#define vct vector
#define prique priority_queue
#define l_bnd lower_bound
#define u_bnd upper_bound
#define rsz resize
#define ers erase
#define emp emplace
#define emf emplace_front
#define emb emplace_back
#define pof pop_front
#define pob pop_back
#define mkp make_pair
#define mkt make_tuple
#define fir first
#define sec second

typedef long long ll;
typedef double db;
typedef vct<vct<ll>> mat;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<db,int> pdi;
typedef map<int,int> mpii;

#ifdef Local
#define print(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
clock_t starting_time = clock();
#endif

void setup() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    #ifdef Local
    cout << "-- Execution At Local ---\n" << "\n<Standard Output>\n\n";
    auto print_info = []() {
        cout << "\n----------------\n";
        cout << "\nExec time : " << (double)(clock() - starting_time) / CLOCKS_PER_SEC * 1000 << " ms\n\n";
    };
    atexit(print_info);
    #endif
}

template <class T, class U> ostream& operator << (ostream& s, pair<T,U> p) { return s << p.fir << " " << p.sec; }
template <class T> ostream& operator << (ostream& s, vector<T>& v) { for(auto i = v.begin(); i != v.end(); i++) { if(i != begin(v)) s << " "; s << *i; } return s; }

template <typename T> void hash_combine(size_t &seed, T const &key) {
    hash<T> hasher;
    seed ^= hasher(key) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}

namespace std {
    template <typename T1, typename T2> struct hash<pair<T1,T2>> {
        size_t operator()(pair<T1,T2> const &p) const {
            size_t seed(0);
            hash_combine(seed,p.first);
            hash_combine(seed,p.second);
            return seed;
        }
    };
}

bool odd(ll x) { return x & 1; }
bool even(ll x) { return !odd(x); }
bool parity(ll x, ll y) { return odd(x) ^ even(y); }
bool bit(ll n, uint8_t e) { return n & 1LL << e; }
int ilog(ll x, uint64_t b) { int ret = 0; while(x /= b) ret++; return ret; }
ll qceil(ll x, ll y) { return x > 0 ? (x - 1) / y + 1 :  x / y; }
ll gcd(ll a, ll b) { if(!b) return abs(a); if(a % b) return gcd(b, a % b); return b; }
ll lcm(ll a, ll b) { if(a & b) return a / gcd(a, b) * b; return 0; }
template <class T, class U> bool chmax(T& m, U x) { if(m < x) { m = x; return 1; } return 0; }
template <class T, class U> bool chmin(T& m, U x) { if(m > x) { m = x; return 1; } return 0; }
template <class T> T cmprs(T& v) {
    T tmp = v;
    sort(all(tmp));
    tmp.erase(unique(all(tmp)),end(tmp));
    each(i,v) *i = l_bnd(all(tmp),*i) - begin(tmp) + 1;
    return v;
}

const int dir[8][2] = { {1,0},{0,1},{-1,0},{0,-1},{1,1},{-1,1},{-1,-1},{1,-1} };
const ll inf32 = (1 << 30) - 1;
const ll inf64 = (1LL << 62) - 1;
const ll mod = 1e9 + 7;
const db eps = 1e-15;

template <class K = ll> struct CHT {
    struct line { K slop,incp; int time; };

    unordered_map<K,int> toI;
    vector<K> toK;
    vector<line> data;
    int dom = 1;    // the width of the domain [0,dom)
    int clock = 0;  // the number of total addition
    bool conv = 0;

    CHT(int n) {
        while(n >= dom) dom <<= 1;
        dom = dom * 2 + 1;
        data.resize(dom << 1);
    }

    CHT(const vector<K> &S) : toK(S)
    {
        conv = 1;
        int n = S.size();
        while(n >= dom) dom <<= 1;
        dom = dom * 2 + 1;
        data.resize(dom << 1);
        toK.resize(dom = n);
        for(auto i = 0; i < n; ++i) {
            toI[S[i]] = i;
        }
    }

    int conv_toI(K x) {
        if(conv) return toI[x];
        return x + dom / 2;
    }

    K conv_toK(int i) {
        if(conv) return toK[i];
        return i - dom / 2;
    }

    K getval(const line& ln, K x) { return x * ln.slop + ln.incp; }

    K query(K x) { return getval(find(conv_toI(x)),x); }

    bool is_lower(const line& ln, int i) { return query(conv_toK(i)) > getval(ln,conv_toK(i)); }

    const line& find(int i) {
        int latest = 0,idx;
        i += dom;
        while(i) {
            if(data[i].time > latest) {
                latest = data[i].time;
                idx = i;
            }
            i >>= 1;
        }
        return data[idx];
    }

    //for the interval [i,j)
    void update(const line& ln, int i, int j) {
        i += dom;
        j += dom;
        while(i < j) {
            if(i & 1) data[i++] = ln;
            if(j & 1) data[--j] = ln;
            i >>= 1, j >>= 1;
        }
    }

    int intersect(const line& ln, int low, int up) {
        while(abs(low - up) > 1) {
            int mid = (up + low) / 2;
            if(is_lower(ln,mid)) low = mid;
            else up = mid;
        }
        return low;
    }

    bool add(K s, K t) {
        line ln = {s,t,++clock};
        if(clock == 1) {
            fill(begin(data),end(data),ln);
            return true;
        }
        int ok = dom - 1;
        int ng = -1;
        while(ok - ng > 1) {
            int mid = (ok + ng) / 2;
            if(find(mid).slop > s) ng = mid;
            else ok = mid;
        }
        if(!ok) {
            if(!is_lower(ln,0)) return false;
            update(ln,0,intersect(ln,0,dom) + 1);
            return true;
        }
        if(is_lower(ln,ok)) {
            update(ln,intersect(ln,ok,0),intersect(ln,ok,dom) + 1);
            return true;
        }
        ok--;
        if(is_lower(ln,ok)) {
            update(ln,intersect(ln,ok,0),intersect(ln,ok,dom) + 1);
            return true;
        }
        return false;
    }
};

ll N,A,B;
ll D[300010];
ll dp[300010];

int main() {
    setup();

    cin >> N >> A >> B >> dp[0];
    rep1(i,N) cin >> D[i];
    vector<ll> s;
    for(int i = 1; i <= N; i++) s.emb(i);
    CHT<ll> cht(s);
    for(ll i = 1; i <= N; i++) {
        cht.add(-B * (i - 1),dp[i - 1] + A * i + i * (i - 1) / 2 * B);
        dp[i] = D[i] - A * i + i * (i - 1) / 2 * B + cht.query(i);
    }
    ll ans = inf64;
    for(ll i = 0; i <= N; i++) {
        ans = min(ans,dp[i] + (N - i) * (N + 1 - i) / 2 * B - A * (N - i));
    }
    esc(ans);
}
0