結果

問題 No.489 株に挑戦
ユーザー tekitouktekitouk
提出日時 2017-02-25 20:01:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,475 bytes
コンパイル時間 725 ms
コンパイル使用メモリ 75,892 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-11 15:02:09
合計ジャッジ時間 2,993 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,812 KB
testcase_01 AC 8 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 RE -
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 RE -
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 12 ms
6,940 KB
testcase_17 WA -
testcase_18 AC 8 ms
6,940 KB
testcase_19 AC 6 ms
6,944 KB
testcase_20 AC 13 ms
6,940 KB
testcase_21 AC 4 ms
6,940 KB
testcase_22 AC 3 ms
6,944 KB
testcase_23 AC 9 ms
6,940 KB
testcase_24 AC 14 ms
6,944 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 14 ms
6,940 KB
testcase_27 WA -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 AC 9 ms
6,940 KB
testcase_33 AC 14 ms
6,940 KB
testcase_34 AC 13 ms
6,944 KB
testcase_35 AC 7 ms
6,940 KB
testcase_36 AC 3 ms
6,944 KB
testcase_37 AC 8 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:98:23: warning: 'ansj' may be used uninitialized [-Wmaybe-uninitialized]
   98 |                 printf("%d %d\n",ansj,ansk);
      |                 ~~~~~~^~~~~~~~~~~~~~~~~~~~~
main.cpp:84:21: note: 'ansj' was declared here
   84 |                 int ansj, ansk;
      |                     ^~~~
main.cpp:98:23: warning: 'ansk' may be used uninitialized [-Wmaybe-uninitialized]
   98 |                 printf("%d %d\n",ansj,ansk);
      |                 ~~~~~~^~~~~~~~~~~~~~~~~~~~~
main.cpp:84:27: note: 'ansk' was declared here
   84 |                 int ansj, ansk;
      |                           ^~~~
main.cpp:87:25: warning: 'ans_min' may be used uninitialized [-Wmaybe-uninitialized]
   87 |                         if (ans_min == x[i]) {
      |                         ^~
main.cpp:63:21: note: 'ans_min' was declared here
   63 |         ll ans_max, ans_min;
      |                     ^~~~~~~
main.cpp:93:25: warning: 'ans_max' may be used uninitialized [-Wmaybe-uninitialized]
   93 |                         if (ans_max == x[i]) {
      |                         ^~
main.cpp:63:12: note: 'ans_max' was declared here
   63 |         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+5) { 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++) {
			if (ans_min == x[i]) {
				ansj = i;
				break;
			}
		}
		for (int i = ansj + 1; i < N; i++) {
			if (ans_max == x[i]) {
				ansk = i;
				break;
			}
		}
		printf("%d %d\n",ansj,ansk);
	}

	return 0;
}
0