結果

問題 No.489 株に挑戦
ユーザー tkmst201tkmst201
提出日時 2017-05-22 20:35:45
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 31 ms / 1,000 ms
コード長 1,746 bytes
コンパイル時間 1,506 ms
コンパイル使用メモリ 154,664 KB
実行使用メモリ 4,544 KB
最終ジャッジ日時 2023-09-27 05:46:10
合計ジャッジ時間 4,157 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
4,380 KB
testcase_01 AC 15 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 26 ms
4,500 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 15 ms
4,376 KB
testcase_19 AC 12 ms
4,380 KB
testcase_20 AC 27 ms
4,476 KB
testcase_21 AC 7 ms
4,380 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 17 ms
4,376 KB
testcase_24 AC 31 ms
4,544 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 28 ms
4,420 KB
testcase_27 AC 31 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 28 ms
4,376 KB
testcase_31 AC 28 ms
4,380 KB
testcase_32 AC 17 ms
4,376 KB
testcase_33 AC 30 ms
4,488 KB
testcase_34 AC 28 ms
4,432 KB
testcase_35 AC 11 ms
4,376 KB
testcase_36 AC 5 ms
4,380 KB
testcase_37 AC 17 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:83:9: warning: ‘p’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   printf("%d %d\n", anspos, p);
   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> P;

const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

struct SegmentTree {
	int init_val;
	int n;
	vector<int> dat;
	
	SegmentTree(int _n) {
		init_val = 0;
		n = 1;
		while (n < _n) n *= 2;
		dat.resize(2 * n - 1, init_val);
	}
	
	void update(int k, int a) {
		k += n - 1;
		chmax(dat[k], a);
		
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = max(dat[2 * k + 1], dat[2 * k + 2]);
		}
	}
	
	int query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l) return init_val;
		if (a <= l && r <= b) return dat[k];
		return max(query(a, b, k * 2 + 1, l, (l + r) / 2), query(a, b, k * 2 + 2, (l + r) / 2, r));
	}
	
	int query(int a, int b) {
		return query(a, b, 0, 0, n);
	}
};

int N, D, K;
int x[112345];

int main() {
	cin >> N >> D >> K;
	REP(i, N) scanf("%d", x + i);
	
	SegmentTree seg(N);
	REP(i, N) seg.update(i, x[i]);
	
	int ans = 0, anspos = -1;
	
	REP(i, N - 1) {
		int now = seg.query(i + 1, min(N, i + 1 + D));
		if (chmax(ans, now - x[i])) anspos = i;
	}
	
	if (ans == 0) puts("0");
	else {	
		printf("%lld\n", (ll)ans * K);
		
		int p;
		FOR(i, anspos + 1, N) if (x[i] - x[anspos] == ans) {
			p = i;
			break;
		}
		printf("%d %d\n", anspos, p);
	}
	return 0;
}
0