結果

問題 No.489 株に挑戦
ユーザー xuzijian629xuzijian629
提出日時 2018-11-03 01:38:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 1,000 ms
コード長 1,785 bytes
コンパイル時間 2,005 ms
コンパイル使用メモリ 204,036 KB
実行使用メモリ 6,076 KB
最終ジャッジ日時 2023-09-27 06:00:53
合計ジャッジ時間 3,970 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
5,676 KB
testcase_01 AC 20 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 30 ms
5,624 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 17 ms
4,480 KB
testcase_19 AC 14 ms
4,380 KB
testcase_20 AC 36 ms
5,680 KB
testcase_21 AC 10 ms
4,376 KB
testcase_22 AC 4 ms
4,376 KB
testcase_23 AC 19 ms
4,484 KB
testcase_24 AC 41 ms
5,932 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 38 ms
6,076 KB
testcase_27 AC 37 ms
5,896 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 40 ms
5,992 KB
testcase_31 AC 39 ms
6,064 KB
testcase_32 AC 22 ms
4,376 KB
testcase_33 AC 39 ms
5,944 KB
testcase_34 AC 35 ms
5,620 KB
testcase_35 AC 15 ms
4,376 KB
testcase_36 AC 6 ms
4,380 KB
testcase_37 AC 22 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:75:26: 警告: ‘j’ may be used uninitialized [-Wmaybe-uninitialized]
   75 |         if (as[i] == as[j] + nax) {
      |                          ^
main.cpp:58:18: 備考: ‘j’ はここで定義されています
   58 |     i64 nax = 0, j;
      |                  ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

template <class T>
class SegTree {
    using F = function<T(T, T)>;
    int n;
    vector<T> data;
    const F f;
    const T e;

public:
    SegTree(const vector<T>& as, const F f, const T& e) : f(f), e(e) {
        n = 1;
        while (n < as.size()) n <<= 1;
        data.assign(2 * n, e);
        for (int i = 0; i < as.size(); i++) {
            data[n + i] = as[i];
        }
        for (int i = n - 1; i > 0; i--) {
            data[i] = f(data[2 * i], data[2 * i + 1]);
        }
    }

    void update(int k, const T& x) {
        k += n;
        data[k] = x;
        while (k >>= 1) {
            data[k] = f(data[2 * k], data[2 * k + 1]);
        }
    }

    T query(int a, int b) {
        T L = e, R = e;
        for (a += n, b += n; a < b; a >>= 1, b >>= 1) {
            if (a & 1) {
                L = f(L, data[a++]);
            }
            if (b & 1) {
                R = f(data[--b], R);
            }
        }
        return f(L, R);
    }
};

int main() {
    int n, d, k;
    cin >> n >> d >> k;
    vi as(n);
    for (int i = 0; i < n; i++) {
        cin >> as[i];
    }

    i64 nax = 0, j;
    SegTree<i64> segtree(as, [](i64 a, i64 b) {return max(a, b);}, -1e18);
    for (int i = 0; i < n; i++) {
        i64 x = as[i];
        i64 y = segtree.query(i + 1, min(n, i + d + 1));
        if (y - x > nax) {
            j = i;
            nax = y - x;
        }
    }
    if (nax == 0) {
        cout << nax << endl;
        return 0;
    }
    cout << nax * k << endl;
    cout << j << " ";
    for (int i = j + 1; i < n; i++) {
        if (as[i] == as[j] + nax) {
            cout << i << endl;
            return 0;
        }
    }
}
0