結果

問題 No.489 株に挑戦
ユーザー ldsybldsyb
提出日時 2017-02-25 01:05:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,540 bytes
コンパイル時間 1,011 ms
コンパイル使用メモリ 74,968 KB
実行使用メモリ 7,344 KB
最終ジャッジ日時 2023-08-31 01:10:29
合計ジャッジ時間 2,920 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 WA -
testcase_08 AC 1 ms
4,380 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
4,380 KB
testcase_12 WA -
testcase_13 AC 1 ms
4,380 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 45 ms
7,184 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 49 ms
7,288 KB
testcase_21 AC 12 ms
4,380 KB
testcase_22 AC 6 ms
4,380 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 46 ms
7,312 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 51 ms
7,344 KB
testcase_31 AC 53 ms
7,312 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 28 ms
5,212 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:9:32: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
    9 |         segclass compare(const auto& left, const auto& right){
      |                                ^~~~
main.cpp:9:50: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
    9 |         segclass compare(const auto& left, const auto& right){
      |                                                  ^~~~

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

struct segtree{
	using segclass = pair<long long, long long>;
	const segclass def = make_pair(0, 0);

	segclass compare(const auto& left, const auto& right){
		if(left.first >= right.first) return left;
		if(left.second >= right.second) return left;
		return right;
	}

	int n = 1;
	vector<segclass> tree;

	segtree(int n_){
		while(n_ > (n <<= 1));
		n <<= 1;
		tree = vector<segclass>(n - 1, def);
		n >>= 1;
	}

	segclass get(int k){
		return tree[k + n - 1];
	}

	void update(int k, segclass a){
		k += n - 1;
		tree[k] = a;
		while(k > 0){
			k = (k - 1) / 2;
			tree[k] = compare(tree[2 * k + 1], tree[2 * k + 2]);
		}
	}

	segclass query(int a, int b, int k, int l, int r){
		if(r <= a || b <= l) return def;
		if(a <= l && r <= b) return tree[k];
		else{
			auto vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
			auto vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
			return compare(vl, vr);
		}
	}
};

int main(){
	int n, d, k;
	cin >> n >> d >> k;
	segtree seg(n);
	for(int i = 0, x; i < n && cin >> x; i++) seg.update(i, make_pair(x, i));
	pair<long long, pair<int, int>> ans(0, make_pair(0, 0));
	for(int i = 0; i < n; i++){
		auto maxi = seg.query(i, min(n, i + d), 0, 0, n);
		if(ans.first < (maxi.first - seg.get(i).first) * k){
			ans.first = (maxi.first - seg.get(i).first) * k;
			ans.second = make_pair(i, maxi.second);
		}
	}
	if(!ans.first){
		cout << 0 << endl;
		return 0;
	}
	cout << ans.first << endl << ans.second.first << ' ' << ans.second.second << endl;
}
0