結果

問題 No.489 株に挑戦
ユーザー recososorecososo
提出日時 2020-06-13 20:47:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 1,000 ms
コード長 2,357 bytes
コンパイル時間 1,552 ms
コンパイル使用メモリ 168,732 KB
実行使用メモリ 6,004 KB
最終ジャッジ日時 2023-09-27 06:12:59
合計ジャッジ時間 3,167 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
5,668 KB
testcase_01 AC 10 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 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,380 KB
testcase_16 AC 16 ms
5,616 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 10 ms
4,380 KB
testcase_19 AC 8 ms
4,380 KB
testcase_20 AC 17 ms
5,624 KB
testcase_21 AC 5 ms
4,376 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 8 ms
4,380 KB
testcase_24 AC 20 ms
5,896 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 18 ms
5,888 KB
testcase_27 AC 18 ms
5,928 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 19 ms
5,936 KB
testcase_31 AC 19 ms
6,004 KB
testcase_32 AC 11 ms
4,624 KB
testcase_33 AC 18 ms
5,928 KB
testcase_34 AC 16 ms
5,612 KB
testcase_35 AC 8 ms
4,376 KB
testcase_36 AC 4 ms
4,380 KB
testcase_37 AC 11 ms
4,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
template <typename T, typename E, typename F, typename G>
struct SegmentTree{
    int n;
    F f;
    G g;
    T ti;
    vector<T> dat;
    SegmentTree(){};
    SegmentTree(F f,G g,T ti):f(f),g(g),ti(ti){}
    void init(int n_){    
        n=1;
        while(n<n_) n<<=1;
        dat.assign(n<<1,ti);
    }
    void build(const vector<T> &v){
        int n_=v.size();
        init(n_);
        for(int i=0;i<n_;i++) dat[n+i]=v[i];
        for(int i=n-1;i;i--)
            dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
    }
    void update(int k,const E &x){
        k += n;
        dat[k] = g(dat[k], x);
        while(k>>=1)
            dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);    
    }
    T operator [](int k) const { return dat[k+n]; }
    // [a,b)
    T query(int a,int b) const {
        T vl=ti,vr=ti;
        for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
            if(l&1) vl=f(vl,dat[l++]);
            if(r&1) vr=f(dat[--r],vr);
        }
        return f(vl,vr);
    }
};
  
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    // llならここを変える
    using T = ll;  // type T 
    using E = ll;  // type E
    // 区間**
    auto f = [](T a, T b){ // return type T value
        return max(a,b);
    };
    auto g = [](T a, E b){ // return type T value
        return b;  // return b;
    };
    T ti = 0;  // identify element 入れる値
    ll n,d,k;cin >> n >> d >> k;
    vector<ll> x(n+1);
    rep(i,n){
        cin >> x[i];
    }
    SegmentTree<T,E,decltype(f),decltype(g)> seg(f,g,ti);
    seg.build(x);
    ll ans=0;
    ll t;
    for(int i=0;i<n;i++){
        if(chmax(ans,seg.query(i+1,min(n,i+d+1))-x[i])){
            t=i;
        }
    }
    if(!ans){
        cout << 0 << endl;
        return 0;
    }
    cout << ans*k << endl;
    for(int i=t+1;i<n;i++){
        if(x[i]==ans+x[t]){
            cout << t << " " << i << endl;
            return 0;
        }
    }
}
0