結果

問題 No.489 株に挑戦
ユーザー sekiya9311sekiya9311
提出日時 2017-02-24 23:49:04
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 95 ms / 1,000 ms
コード長 3,961 bytes
コンパイル時間 1,570 ms
コンパイル使用メモリ 124,828 KB
実行使用メモリ 14,384 KB
最終ジャッジ日時 2023-09-27 05:12:51
合計ジャッジ時間 4,133 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
11,200 KB
testcase_01 AC 43 ms
9,416 KB
testcase_02 AC 2 ms
4,436 KB
testcase_03 AC 3 ms
4,580 KB
testcase_04 AC 3 ms
4,384 KB
testcase_05 AC 3 ms
4,564 KB
testcase_06 AC 3 ms
4,580 KB
testcase_07 AC 3 ms
4,524 KB
testcase_08 AC 3 ms
4,528 KB
testcase_09 AC 3 ms
4,580 KB
testcase_10 AC 3 ms
4,436 KB
testcase_11 AC 3 ms
4,436 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 3 ms
4,488 KB
testcase_14 AC 3 ms
4,484 KB
testcase_15 AC 5 ms
4,948 KB
testcase_16 AC 45 ms
6,404 KB
testcase_17 AC 9 ms
5,344 KB
testcase_18 AC 28 ms
6,024 KB
testcase_19 AC 23 ms
5,796 KB
testcase_20 AC 74 ms
11,992 KB
testcase_21 AC 20 ms
7,044 KB
testcase_22 AC 8 ms
5,348 KB
testcase_23 AC 42 ms
9,556 KB
testcase_24 AC 95 ms
13,952 KB
testcase_25 AC 3 ms
4,632 KB
testcase_26 AC 57 ms
14,384 KB
testcase_27 AC 41 ms
5,556 KB
testcase_28 AC 3 ms
4,600 KB
testcase_29 AC 3 ms
4,632 KB
testcase_30 AC 87 ms
13,796 KB
testcase_31 AC 56 ms
14,048 KB
testcase_32 AC 46 ms
9,632 KB
testcase_33 AC 94 ms
13,616 KB
testcase_34 AC 74 ms
11,772 KB
testcase_35 AC 27 ms
7,568 KB
testcase_36 AC 12 ms
5,872 KB
testcase_37 AC 45 ms
9,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <chrono>

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 RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

template<typename type = int,
typename ctype = std::less<type>,
type LIM = (std::is_same<ctype, std::less<type>>::value ?
std::numeric_limits<type>::max() :
std::numeric_limits<type>::min())>
class SegTreeRMQ {  //デフォでminimum
private:
    const int n;
    std::vector<type> st;
    ctype comp;
    type query(int l, int r, int k, int L, int R) {
        if (R <= l || r <= L) return LIM;
        if (l <= L && R <= r) return st[k];
        type res = LIM;
        int h = (L + R) >> 1;
        if (l < h) res = std::min(res, query(l, r, (k << 1) + 1, L, h), comp);
        if (h < r) res = std::min(res, query(l, r, (k << 1) + 2, h, R), comp);
        return res;
    }
    void update(int id, type el, int k, int L, int R) {
        if (id < L || R <= id) return;
        if (L + 1 == R && id == L) {
            st[k] = el;
            return;
        }
        int h = (L + R) >> 1;
        update(id, el, (k << 1) + 1, L, h);
        update(id, el, (k << 1) + 2, h, R);
        st[k] = std::min(st[(k << 1) + 2], st[(k << 1) + 1], comp);
    }
public:
    SegTreeRMQ() : n(-1) {}
    SegTreeRMQ(int _n, type initval = LIM) : n(_n), st(_n << 2, initval){}
    //範囲 [l, r) !!!!!
    type query(int l, int r) {
        assert(this->n != -1 && 0 <= l && r <= this->n && l <= r);
        return query(l, r, 0, 0, n);
    }
    void update(int id, type el) {
        assert(this->n != -1 && id < this->n);
        update(id, el, 0, 0, n);
    }
};

const int MAX = 1e5 + 10;
int N, D, K;
int x[MAX];
SegTreeRMQ<int, greater<int>> seg(MAX);
unordered_map<int, VI> mp;

int main(void) {
    scanf("%d%d%d", &N, &D, &K);
    REP(i, N) {
        scanf("%d", x + i);
        mp[x[i]].EB(i);
        seg.update(i, x[i]);
    }
    FORE(e, mp) {
        REVERSE(e.second);
    }
    LL ma = 0;
    int buy = -1, sell = -1;
    int j = 0;
    REP(i, N) {
        const int que = seg.query(i, min<LL>(MAX, i + D + 1));
        if (chmax<LL>(ma, que - x[i])) {
            VI &vec = mp[que];
            while (!(i <= vec.back() && vec.back() <= i + D + 1)) vec.pop_back();
            buy = i;
            sell = vec.back();
        }
    }
    if (ma) cout << ma * K << '\n' << buy << " " << sell << endl;
    else cout << 0 << endl;
}
0