結果

問題 No.489 株に挑戦
ユーザー TangentDayTangentDay
提出日時 2017-02-24 22:45:54
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 42 ms / 1,000 ms
コード長 1,709 bytes
コンパイル時間 678 ms
コンパイル使用メモリ 77,412 KB
実行使用メモリ 4,792 KB
最終ジャッジ日時 2023-09-27 04:59:58
合計ジャッジ時間 2,870 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
4,792 KB
testcase_01 AC 18 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 33 ms
4,528 KB
testcase_17 AC 5 ms
4,376 KB
testcase_18 AC 20 ms
4,380 KB
testcase_19 AC 14 ms
4,380 KB
testcase_20 AC 34 ms
4,580 KB
testcase_21 AC 8 ms
4,380 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 20 ms
4,376 KB
testcase_24 AC 41 ms
4,520 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 33 ms
4,552 KB
testcase_27 AC 42 ms
4,576 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 33 ms
4,520 KB
testcase_31 AC 32 ms
4,524 KB
testcase_32 AC 22 ms
4,376 KB
testcase_33 AC 38 ms
4,528 KB
testcase_34 AC 36 ms
4,512 KB
testcase_35 AC 15 ms
4,380 KB
testcase_36 AC 5 ms
4,380 KB
testcase_37 AC 19 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:90:11: warning: ‘j’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     printf("%lld\n%d %d\n", ans, j, k);
     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define INF 1e9

const int MAX_N = 200010;

int n, width;
int dat[MAX_N*4];

void init(){
    width = 1;
    while(width<n) width*=2;
    REP(i,2*width-1) dat[i] = INF;
}

void update(int i, int x){
    i += width-1;
    dat[i] = x;
    while (i>0){
        i = (i-1)/2;
        dat[i] = min(dat[i*2+1],dat[i*2+2]);
    }
}

int query(int a, int b, int k, int l, int r){
    if (r<=a || b<=l) return INF;
    if (a<=l && r<=b) return dat[k];
    int vl = query(a,b,k*2+1,l,(l+r)/2);
    int vr = query(a,b,k*2+2,(l+r)/2,r);
    return min(vl,vr);
}

int main() {
    int d;
    ll kabu;
    cin >> n >> d >> kabu;
    init();
    VI x(n);
    REP(i,n){
        scanf("%d", &x[i]);
        update(i, x[i]);
    }
    ll ans = 0;
    int j, k;
    REP(i,n){
        int mi = query(max(0, i-d), i+1, 0, 0, width);
        if (x[i] - mi > ans){
            ans = x[i] - mi;
            k = i;
        }
    }

    if (ans == 0){
        cout << 0 << endl;
        return 0;
    }

    FOR(i,max(0,k-d),k){
        if (x[i] == x[k] - ans){
            j = i;
            break;
        }
    }

    ans *= kabu;
    printf("%lld\n%d %d\n", ans, j, k);

    return 0;
}
0