結果

問題 No.489 株に挑戦
ユーザー face4face4
提出日時 2019-01-26 11:22:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 1,000 ms
コード長 1,633 bytes
コンパイル時間 834 ms
コンパイル使用メモリ 76,908 KB
実行使用メモリ 6,076 KB
最終ジャッジ日時 2023-09-27 05:59:01
合計ジャッジ時間 4,131 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
5,756 KB
testcase_01 AC 27 ms
4,392 KB
testcase_02 AC 2 ms
4,380 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 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 43 ms
5,688 KB
testcase_17 AC 6 ms
4,376 KB
testcase_18 AC 24 ms
4,452 KB
testcase_19 AC 19 ms
4,376 KB
testcase_20 AC 48 ms
5,636 KB
testcase_21 AC 12 ms
4,376 KB
testcase_22 AC 5 ms
4,376 KB
testcase_23 AC 27 ms
4,380 KB
testcase_24 AC 53 ms
5,896 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 48 ms
5,952 KB
testcase_27 AC 51 ms
5,904 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 50 ms
6,076 KB
testcase_31 AC 47 ms
5,960 KB
testcase_32 AC 29 ms
4,376 KB
testcase_33 AC 53 ms
6,000 KB
testcase_34 AC 47 ms
5,748 KB
testcase_35 AC 19 ms
4,620 KB
testcase_36 AC 8 ms
4,380 KB
testcase_37 AC 28 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

struct SegmentTree{
    vector<int> node, pos;
    int n;
    
    SegmentTree(vector<int> v){
        int s = v.size();
        n = 1;
        while(n < s) n *= 2;
        node.resize(2*n-1, 0);
        pos.resize(2*n-1, 0);
        for(int i = 0; i < s; i++)      node[i+n-1] = v[i], pos[i+n-1] = i;
        for(int i = n-2; i >= 0; i--){
            node[i] = max(node[2*i+1], node[2*i+2]);
            if(node[2*i+1] >= node[2*i+2])  pos[i] = pos[2*i+1];
            else                            pos[i] = pos[2*i+2];
        }
    }

    // [a, b)の最大値 kは現在地,[l, r)をカバー
    int getmax(int a, int b, int k=0, int l=0, int r=-1){
        if(r < 0)   r = n;
        
        if(a >= r || b <= l)    return -1;

        if(a <= l && r <= b)    return pos[k];

        int vl = getmax(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmax(a, b, 2*k+2, (l+r)/2, r);

        if(vl == -1)    return vr;
        if(vr == -1)    return vl;
        if(node[n-1+vl] >= node[n-1+vr])  return vl;
        else                return vr;
    }
};

int main(){
    int n, d, k;
    cin >> n >> d >> k;

    vector<int> v(n);
    for(int i = 0; i < n; i++)  cin >> v[i];

    SegmentTree seg(v);

    ll ans = 0;
    int posi, posj;
    for(int i = 0; i < n-1; i++){
        int pos = seg.getmax(i+1, min(n, i+d+1));
        ll tmp = (ll)k * (v[pos]-v[i]);
        if(tmp > ans){
            ans = tmp;
            posi = i, posj = pos;
        }
    }

    cout << ans << endl;
    if(ans) cout << posi << " " << posj << endl;

    return 0;
}
0