結果

問題 No.489 株に挑戦
ユーザー tekitouktekitouk
提出日時 2017-02-25 20:30:25
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,488 bytes
コンパイル時間 629 ms
コンパイル使用メモリ 75,644 KB
実行使用メモリ 9,504 KB
最終ジャッジ日時 2023-09-02 08:11:43
合計ジャッジ時間 5,398 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
9,120 KB
testcase_01 AC 635 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 50 ms
4,956 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 84 ms
4,380 KB
testcase_19 AC 333 ms
4,376 KB
testcase_20 AC 413 ms
5,156 KB
testcase_21 AC 9 ms
4,380 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 12 ms
4,380 KB
testcase_24 TLE -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:91:41: 警告: ‘ans_min’ may be used uninitialized [-Wmaybe-uninitialized]
   91 |                                         if (ans_min == x[i] && ans_max==x[j]) {
      |                                         ^~
main.cpp:65:21: 備考: ‘ans_min’ はここで定義されています
   65 |         ll ans_max, ans_min;
      |                     ^~~~~~~
main.cpp:91:61: 警告: ‘ans_max’ may be used uninitialized [-Wmaybe-uninitialized]
   91 |                                         if (ans_min == x[i] && ans_max==x[j]) {
      |                                             ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
main.cpp:65:12: 備考: ‘ans_max’ はここで定義されています
   65 |         ll ans_max, ans_min;
      |            ^~~~~~~

ソースコード

diff #

#include <sstream>
#include <iostream>
#include <algorithm>
#include <deque>
#include <string>

using namespace std;

typedef long long ll;

ll x[100005];
ll maximum[100005];
ll maximum2[100005];

int main() {

	int N, D;

	ll K;

	scanf("%d %d %lld", &N, &D, &K);

	for (int i = 0; i < N; i++) {
		scanf("%lld", &x[i]);
	}

	deque<ll> nums;

	int cnt = 0;

	while (!nums.empty()) {
		nums.pop_back();
	}

	for (int i = 0; i < N; i++) {
		while (!nums.empty() && x[i] > nums.back()) {
			nums.pop_back();
		}
		nums.push_back(x[i]);
		if (i >= D && nums.front() == x[i - D]) {
			nums.pop_front();
		}
		if (i >= D - 1) {
			maximum[cnt] = nums.front();
			cnt++;
		}

	}

	int cnt2 = 0;

	ll ma = x[N - 1];

	for (int i = N - 2;; i--) {
		if (cnt2 >= D) {
			break;
		}
		maximum2[i] = ma;
		ma = max(ma, x[i]);
		cnt2++;
	}

	ma = 0ll;

	ll ans_max, ans_min;

	for (int i = 0; i < cnt - 1; i++) {
		if (ma < maximum[i + 1] - x[i]) {
			ma = maximum[i + 1] - x[i];
			ans_max = maximum[i + 1];
			ans_min = x[i];
		}
	}

	for (int i = cnt-1; i < N - 1; i++) {
		if (ma < maximum2[i] - x[i]) {
			ma = maximum2[i] - x[i];
			ans_max = maximum2[i];
			ans_min = x[i];
		}
	}
	cout << ma*K << endl;

	if (ma != 0ll) {

		int ansj, ansk;

		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				if (j - i <= D) {
					if (ans_min == x[i] && ans_max==x[j]) {
						printf("%d %d\n",i,j);
						return 0;
					}
				}
				else {
					break;
				}
			}
		}
	}

	return 0;
}
0