結果

問題 No.489 株に挑戦
ユーザー maimai
提出日時 2017-02-25 01:02:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 1,000 ms
コード長 3,875 bytes
コンパイル時間 1,796 ms
コンパイル使用メモリ 171,956 KB
実行使用メモリ 6,148 KB
最終ジャッジ日時 2023-09-27 05:18:21
合計ジャッジ時間 3,415 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
5,720 KB
testcase_01 AC 18 ms
4,484 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 35 ms
6,020 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 21 ms
4,424 KB
testcase_19 AC 16 ms
4,396 KB
testcase_20 AC 36 ms
5,816 KB
testcase_21 AC 9 ms
4,376 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 21 ms
4,868 KB
testcase_24 AC 41 ms
5,976 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 38 ms
6,144 KB
testcase_27 AC 41 ms
5,992 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 35 ms
6,148 KB
testcase_31 AC 33 ms
6,000 KB
testcase_32 AC 22 ms
4,396 KB
testcase_33 AC 39 ms
5,972 KB
testcase_34 AC 36 ms
5,796 KB
testcase_35 AC 15 ms
4,496 KB
testcase_36 AC 6 ms
4,380 KB
testcase_37 AC 20 ms
4,388 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:121:74: 警告: ‘bestj’ may be used uninitialized [-Wmaybe-uninitialized]
  121 |         cout << (((ll)best)*(ll)kk) << endl << --besti << ' ' << --bestj << endl;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
main.cpp:107:20: 備考: ‘bestj’ はここで定義されています
  107 |     ll besti = -1, bestj;
      |                    ^~~~~

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;
typedef unsigned int uint;
typedef long long int ll;
typedef unsigned long long int ull;

#define debugv(v) printf("L%d %s => ",__LINE__,#v);for(auto e:v){cout<<e<<" ";}cout<<endl;
#define debugm(m) printf("L%d %s is..\n",__LINE__,#m);for(auto v:m){for(auto e:v){cout<<e<<" ";}cout<<endl;}
#define debuga(m,w) printf("L%d %s is => ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout<<endl;
#define debugaa(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[x][y]<<" ";}cout<<endl;}
#define debugaar(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[y][x]<<" ";}cout<<endl;}
#define ALL(v) (v).begin(),(v).end()
#define BIGINT 0x7FFFFFFFLL
#define E107 1000000007ll
void printbit(int u) { if (u == 0)cout << 0; else { int s = 0, k = 0; for (; 0<u; u >>= 1, k++)s = (s << 1) | (u & 1); for (; 0<k--; s >>= 1)cout << (s & 1); } }

#define TIME chrono::system_clock::now()
#define MILLISEC(t) (chrono::duration_cast<chrono::milliseconds>(t).count())

namespace {
    std::chrono::system_clock::time_point t;
    void tic() { t = TIME; }
    void toc() { fprintf(stderr, "TIME : %lldms\n", MILLISEC(TIME - t)); }
    std::chrono::system_clock::time_point tle = TIME;
    void safe_tle(int msec) { assert(MILLISEC(TIME - tle) < msec); }
}

template<typename T1, typename T2>
ostream& operator <<(ostream &o, const pair<T1, T2> p) { o << "(" << p.first << ":" << p.second << ")"; return o; }

template<typename T, T idt = 0x7FFFFFFF, typename Compare = std::less<T>>
class segtree {
    size_t size;
    vector<T> data;
    Compare cp;

    const T& selector(const T& x, const T& y) const {
        return cp(x, y) ? x : y;
    }
public:

    segtree(size_t n) {
        size = 1;
        while (size<n) size <<= 1;
        data.resize(size * 2);
    }

    void fill(const T& e) {
        std::fill(data.begin(), data.end(), e);
    }

    const T& operator[](size_t index) const {
        return data[size - 1 + index];
    }

    void update(size_t index, const T& e) {
        index += size - 1;
        data[index] = e;
        while (0 < index) {
            index = (index - 1) / 2; // 親へ移動
            data[index] = selector(data[index * 2 + 1], data[index * 2 + 2]); // iの子を参照して、d[i]を更新する
        }
    }

    T query(size_t begin, size_t end, size_t ptr = 0, size_t rangebegin = 0, size_t rangeend = 0) const {
        if (rangeend <= rangebegin) { rangeend = size; }
    
        if (rangeend <= begin || end <= rangebegin) return idt;
        if (begin <= rangebegin && rangeend <= end) return data[ptr];
    
        size_t rangemid = (rangebegin + rangeend) / 2;
        return selector(query(begin, end, ptr * 2 + 1, rangebegin, rangemid), query(begin, end, ptr * 2 + 2, rangemid, rangeend));
    }

};


int width, height;
ll n, dd, kk;

ll daikon[100010];

struct compare{
    bool operator ()(const ll& l, const ll& r) const {
        if (l == BIGINT) return false;
        if (r == BIGINT) return true;
        return daikon[l] <= daikon[r];
    }
};

int main() {
    ll i, j, k, l;
    ll x, y, a, b;


    cin >> n >> dd >> kk;

    for (i = 1; i <= n; ++i) {
        scanf("%lld", daikon + i);
    }

    segtree<int, BIGINT, compare> seg(n*2);
    seg.fill(BIGINT);

    ll best = 0;
    ll besti = -1, bestj;
    for (i = 1; i <= n; ++i) {
        seg.update(i, i);
        ll les = seg.query(max(0ll, i - dd), i);
        if (les != BIGINT && best < daikon[i] - daikon[les]) {
            best = daikon[i] - daikon[les];
            besti = les;
            bestj = i;
        }
    }
    if (besti == -1 || best == 0) {
        cout << 0 << endl;
    }
    else {
        cout << (((ll)best)*(ll)kk) << endl << --besti << ' ' << --bestj << endl;
    }

    return 0;
}
0