結果

問題 No.489 株に挑戦
ユーザー xuzijian629xuzijian629
提出日時 2018-11-03 01:37:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,784 bytes
コンパイル時間 2,398 ms
コンパイル使用メモリ 205,880 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-30 20:28:56
合計ジャッジ時間 4,045 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 3 ms
6,940 KB
testcase_16 AC 34 ms
6,940 KB
testcase_17 AC 6 ms
6,940 KB
testcase_18 AC 20 ms
6,944 KB
testcase_19 AC 16 ms
6,940 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 42 ms
6,940 KB
testcase_27 AC 41 ms
6,940 KB
testcase_28 WA -
testcase_29 AC 2 ms
6,940 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:75:26: warning: 'j' may be used uninitialized [-Wmaybe-uninitialized]
   75 |         if (as[i] == as[j] + nax) {
      |                          ^
main.cpp:58:18: note: 'j' was declared here
   58 |     int 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];
    }

    int nax = 0, j;
    SegTree<i64> segtree(as, [](i64 a, i64 b) {return max(a, b);}, -1e9);
    for (int i = 0; i < n; i++) {
        int x = as[i];
        int 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