結果

問題 No.489 株に挑戦
ユーザー tottoripapertottoripaper
提出日時 2017-03-26 22:05:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 40 ms / 1,000 ms
コード長 2,407 bytes
コンパイル時間 1,506 ms
コンパイル使用メモリ 170,704 KB
実行使用メモリ 6,480 KB
最終ジャッジ日時 2023-09-27 05:40:20
合計ジャッジ時間 3,667 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
5,992 KB
testcase_01 AC 20 ms
5,808 KB
testcase_02 AC 4 ms
5,436 KB
testcase_03 AC 4 ms
5,624 KB
testcase_04 AC 3 ms
5,432 KB
testcase_05 AC 3 ms
5,448 KB
testcase_06 AC 3 ms
5,428 KB
testcase_07 AC 4 ms
5,440 KB
testcase_08 AC 3 ms
5,428 KB
testcase_09 AC 3 ms
5,424 KB
testcase_10 AC 3 ms
5,424 KB
testcase_11 AC 3 ms
5,440 KB
testcase_12 AC 4 ms
5,700 KB
testcase_13 AC 4 ms
5,656 KB
testcase_14 AC 4 ms
5,716 KB
testcase_15 AC 5 ms
5,532 KB
testcase_16 AC 34 ms
6,160 KB
testcase_17 AC 7 ms
5,532 KB
testcase_18 AC 21 ms
5,812 KB
testcase_19 AC 17 ms
5,848 KB
testcase_20 AC 36 ms
6,156 KB
testcase_21 AC 11 ms
5,592 KB
testcase_22 AC 6 ms
5,548 KB
testcase_23 AC 20 ms
5,844 KB
testcase_24 AC 40 ms
6,208 KB
testcase_25 AC 4 ms
5,428 KB
testcase_26 AC 37 ms
6,408 KB
testcase_27 AC 38 ms
6,400 KB
testcase_28 AC 4 ms
5,420 KB
testcase_29 AC 3 ms
5,416 KB
testcase_30 AC 37 ms
6,208 KB
testcase_31 AC 37 ms
6,480 KB
testcase_32 AC 23 ms
5,836 KB
testcase_33 AC 39 ms
6,372 KB
testcase_34 AC 36 ms
6,132 KB
testcase_35 AC 16 ms
5,716 KB
testcase_36 AC 8 ms
5,532 KB
testcase_37 AC 22 ms
5,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

// I want to delete this stupid solution ;(
#define sandwich(x) [](auto a, auto b){return (x)(a, b);}

template <typename T>
using F2 = std::function<T(T,T)>;

template <typename T, int N, typename F = std::plus<T>>
    struct SegmentTree{
        SegmentTree(T u, F f = F()){
            size = 1;
            while(size < N){
                size <<= 1;
            }

            unit = u;
            func = f;

            init();
        }
        void init(){
            for(int i=0;i<size;++i){
                data[i+size] = unit;
            }

            for(int i=size-1;i>0;--i){
                data[i] = func(data[i*2], data[i*2+1]);
            }
        }
        void update(int k, int v){
            k += size;
            data[k] = v;

            while(k > 1){
                k >>= 1;
                data[k] = func(data[k*2], data[k*2+1]);
            }
        }
        inline T query(int l, int r){
            return _query(l, r, 1, 0, size);
        }
        T _query(int a, int b, int k, int l, int r){
            if(b <= l || r <= a){return unit;}
            if(a <= l && r <= b){return data[k];}
            int mid = (l + r) >> 1;
            return func(_query(a, b,   2*k,   l, mid),
                        _query(a, b, 2*k+1, mid, r  ));
        }

        T unit, data[N*4];
        int size;
        F func;
    };

ll N, D, K;
ll d[100100];
SegmentTree<ll, 100100, F2<ll>> st(0ll, sandwich(max));

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    std::cin >> N >> D >> K;

    for(int i=0;i<N;++i){
        std::cin >> d[i];
        st.update(i, d[i]);
    }

    int idx = -1;
    ll res = 0ll;
    for(int i=0;i<N-1;++i){
        ll x = (st.query(i+1, min(i+1+D, N)) - d[i]) * K;
        if(x > res){
            res = x;
            idx = i;
        }
    }

    std::cout << res << std::endl;
    if(res > 0){
        std::cout << idx << " ";
        
        for(int i=1;i<=D&&idx+i<N;++i){
            if(d[idx+i] - d[idx] == res / K){
                std::cout << (idx+i) << std::endl;
                return 0;
            }
        }
    }
}
0