結果

問題 No.489 株に挑戦
ユーザー ふっぴーふっぴー
提出日時 2017-12-16 14:31:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 1,000 ms
コード長 2,662 bytes
コンパイル時間 1,734 ms
コンパイル使用メモリ 175,512 KB
実行使用メモリ 87,324 KB
最終ジャッジ日時 2023-09-27 05:53:40
合計ジャッジ時間 5,140 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
87,064 KB
testcase_01 AC 54 ms
86,072 KB
testcase_02 AC 25 ms
84,736 KB
testcase_03 AC 24 ms
84,952 KB
testcase_04 AC 25 ms
84,764 KB
testcase_05 AC 25 ms
84,892 KB
testcase_06 AC 25 ms
84,848 KB
testcase_07 AC 25 ms
84,820 KB
testcase_08 AC 26 ms
84,904 KB
testcase_09 AC 24 ms
84,716 KB
testcase_10 AC 25 ms
84,724 KB
testcase_11 AC 24 ms
84,976 KB
testcase_12 AC 25 ms
84,868 KB
testcase_13 AC 25 ms
84,720 KB
testcase_14 AC 25 ms
84,868 KB
testcase_15 AC 27 ms
85,292 KB
testcase_16 AC 75 ms
87,000 KB
testcase_17 AC 31 ms
85,480 KB
testcase_18 AC 54 ms
86,064 KB
testcase_19 AC 47 ms
86,072 KB
testcase_20 AC 79 ms
87,056 KB
testcase_21 AC 36 ms
85,552 KB
testcase_22 AC 29 ms
85,288 KB
testcase_23 AC 59 ms
86,008 KB
testcase_24 AC 89 ms
87,172 KB
testcase_25 AC 25 ms
84,892 KB
testcase_26 AC 71 ms
87,052 KB
testcase_27 AC 87 ms
87,120 KB
testcase_28 AC 25 ms
84,840 KB
testcase_29 AC 25 ms
84,832 KB
testcase_30 AC 81 ms
87,044 KB
testcase_31 AC 69 ms
87,032 KB
testcase_32 AC 60 ms
85,940 KB
testcase_33 AC 86 ms
87,324 KB
testcase_34 AC 80 ms
87,056 KB
testcase_35 AC 46 ms
86,064 KB
testcase_36 AC 32 ms
85,360 KB
testcase_37 AC 56 ms
86,064 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
次のファイルから読み込み:  /usr/local/gcc7/include/c++/12.2.0/istream:39,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/sstream:38,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/complex:45,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/ccomplex:39,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/x86_64-pc-linux-gnu/bits/stdc++.h:54,
         次から読み込み:  main.cpp:1:
メンバ関数 ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>]’ 内,
    inlined from ‘int main()’ at main.cpp:123:26:
/usr/local/gcc7/include/c++/12.2.0/ostream:202:25: 警告: ‘selld’ may be used uninitialized [-Wmaybe-uninitialized]
  202 |       { return _M_insert(__n); }
      |                ~~~~~~~~~^~~~~
main.cpp: 関数 ‘int main()’ 内:
main.cpp:111:18: 備考: ‘selld’ はここで定義されています
  111 |         ll buyd, selld;
      |                  ^~~~~
メンバ関数 ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>]’ 内,
    inlined from ‘int main()’ at main.cpp:123:11:
/usr/local/gcc7/include/c++/12.2.0/ostream:202:25: 警告: ‘buyd’ may be used uninitialized [-Wmaybe-uninitialized]
  202 |       { return _M_insert(__n); }
      |                ~~~~~~~~~^~~~~
main.cpp: 関数 ‘int main()’ 内:
main.cpp:111:12: 備考: ‘buyd’ はここで定義されています
  111 |         ll buyd, selld;
      |            ^~~~

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 1e18 * 2;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };



//rmq に使用
const ll MAX_N = 1 << 21;
int n;
vector<pll> dat(2 * MAX_N - 1);
vl a(MAX_N);


//rmqに使用
void init(int k, int l, int r) {
	if (r - l == 1) {
		dat[k].first = a[l];
		dat[k].second = l;
	}
	else {
		int lch = 2 * k + 1, rch = 2 * k + 2;
		init(lch, l, (l + r) / 2);
		init(rch, (l + r) / 2, r);
		if (dat[lch].first >= dat[rch].first) {
			dat[k] = dat[lch];
		}
		else {
			dat[k] = dat[rch];
		}

	}
}

//k番目の値をaに変更
//rmqに使用
void update(int k, int a, int v, int l, int r) {
	if (r - l == 1) {
		dat[v].first = a;
	}
	else {
		if (k < (l + r) / 2)
			update(k, a, 2 * v + 1, l, (l + r) / 2);
		else {
			update(k, a, 2 * v + 2, (l + r) / 2, r);
		}
		if (dat[2*v+1].first >= dat[2*v+2].first) {
			dat[k] = dat[2*v+1];
		}
		else {
			dat[k] = dat[2*v+2];
		}
	}
}

//rmqに使用
//[a,b)の最小値を求める
//後ろのほうの引数は計算の簡単のための引数
//kは接点の番号,l,rはその接点が[l,r)に対応していることを表す
//従って、外からはquery(a,b,0,0,n)としてよぶ
pll query(int a, int b, int k, int l, int r) {
	if (r <= a || b <= l) {
		return pll(-1, inf);
	}
	if (a <= l && r <= b) {
		return dat[k];
	}
	else {
		pll ul = query(a, b, k * 2 + 1, l, (l + r) / 2);
		pll ur = query(a, b, k * 2 + 2, (l + r) / 2, r);
		if (ul.first >= ur.first) {
			return ul;
		}
		else {
			return ur;
		}
	}
}

int main() {
	int d, k, i, j;
	cin >> n >> d >> k;
	vector<pll> vp;
	for (i = 0; i < n; i++) {
		cin >> a[i];
		vp.push_back(pll(a[i], i));
	}
	sort(vp.begin(), vp.end());
	init(0, 0, n);
	ll ans = -INF;
	ll buyd, selld;
	for (i = 0; i < n; i++) {
		ll buy = a[i];
		pll sell = query(i, min(i + d + 1, n), 0, 0, n);
		if (ans < (sell.first - buy) * k) {
			buyd = i;
			selld = sell.second;
			ans = (sell.first - buy)*k;
		}
	}
	cout << ans << endl;
	if (ans) {
		cout << buyd << " " << selld << endl;
	}
}
0