結果

問題 No.489 株に挑戦
ユーザー noynotenoynote
提出日時 2017-02-25 10:18:13
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,309 bytes
コンパイル時間 3,026 ms
コンパイル使用メモリ 146,272 KB
実行使用メモリ 6,060 KB
最終ジャッジ日時 2023-09-02 07:58:17
合計ジャッジ時間 4,917 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 WA -
testcase_08 AC 1 ms
4,380 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
4,380 KB
testcase_12 WA -
testcase_13 AC 1 ms
4,380 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 48 ms
5,772 KB
testcase_21 AC 12 ms
4,380 KB
testcase_22 AC 5 ms
4,376 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 46 ms
5,756 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 49 ms
5,788 KB
testcase_31 AC 52 ms
5,780 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 27 ms
4,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 2000000000;
using namespace std;

const int MAX_N = 1 << 17;

//セグメントツリーを持つ配列
int n, dat[2 * MAX_N - 1][2];

void init(int n_){
    n = 1;
    while(n < n_) n *= 2;
    rep(i,2 * n - 1) dat[i][0] = 0;
}

void update(int k, int a, int b){
    //葉の節点
    k += n - 1;
    dat[k][0] = a;
    dat[k][1] = b;
    //登りながら更新
    while(k > 0){
        k = (k - 1) / 2;
        if(dat[k * 2 + 1][0] > dat[k * 2 + 2][0]){
            dat[k][0] = dat[k * 2 + 1][0];
            dat[k][1] = dat[k * 2 + 1][1];
        }else if(dat[k * 2 + 1][0] < dat[k * 2 + 2][0]){
            dat[k][0] = dat[k * 2 + 2][0];
            dat[k][1] = dat[k * 2 + 2][1];
        }
    }
}

//[a, b)の最小値を求める
//query(a, b, 0, 0, n)
pair<int, int> query(int a, int b, int k, int l, int r){
    //cout << a << ' ' << b << ' ' << k << ' ' << l << ' ' << r << endl;
    //[a, b) と[l, r)が交差しなければ、INT_MAX
    if(r <= a || b <= l) return make_pair(0,-1);

    //[a,b)が[l,r)を完全に含んでいれば、この節点の値
    if(a <= l && r <= b) return make_pair(dat[k][0], dat[k][1]);
    else{
        //そうでなければ、2つのこの最小値
        pair<int, int> vl = query(a, b, k * 2 + 1, l, ( l + r) / 2);
        pair<int, int> vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
        if(vl.first > vr.first) return vl;
        else return vr;
    }
}

int main(){
    int n, d, k;
    int x[100005];
    cin >> n >> d >> k;
    init(n);
    rep(i,n){
        cin >> x[i];
        update(i,x[i],i);
    }
    long long maxi = 0;
    pair<int, int> day;
    rep(i,n - 1){
        pair<int, int> p;
        int dif;
        p = query(i,min(i + d,n), 0, 0, n);
        dif = p.first - x[i];
        if(dif > maxi){
            maxi = dif;
            day.first = i;
            day.second = p.second;
        }
    }
    cout << k * maxi << endl;
    if(k * maxi > 0) cout << day.first << ' ' << day.second << endl;
}
0