結果
問題 | No.489 株に挑戦 |
ユーザー | fine |
提出日時 | 2017-02-24 23:10:34 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 30 ms / 1,000 ms |
コード長 | 1,880 bytes |
コンパイル時間 | 1,407 ms |
コンパイル使用メモリ | 170,832 KB |
実行使用メモリ | 4,540 KB |
最終ジャッジ日時 | 2023-09-27 05:06:17 |
合計ジャッジ時間 | 3,114 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 22 ms
4,412 KB |
testcase_01 | AC | 12 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 1 ms
4,376 KB |
testcase_04 | AC | 2 ms
4,380 KB |
testcase_05 | AC | 1 ms
4,376 KB |
testcase_06 | AC | 1 ms
4,384 KB |
testcase_07 | AC | 2 ms
4,380 KB |
testcase_08 | AC | 2 ms
4,376 KB |
testcase_09 | AC | 2 ms
4,376 KB |
testcase_10 | AC | 1 ms
4,376 KB |
testcase_11 | AC | 2 ms
4,376 KB |
testcase_12 | AC | 1 ms
4,376 KB |
testcase_13 | AC | 1 ms
4,376 KB |
testcase_14 | AC | 1 ms
4,376 KB |
testcase_15 | AC | 3 ms
4,376 KB |
testcase_16 | AC | 23 ms
4,412 KB |
testcase_17 | AC | 4 ms
4,376 KB |
testcase_18 | AC | 14 ms
4,380 KB |
testcase_19 | AC | 10 ms
4,376 KB |
testcase_20 | AC | 23 ms
4,404 KB |
testcase_21 | AC | 6 ms
4,376 KB |
testcase_22 | AC | 4 ms
4,376 KB |
testcase_23 | AC | 15 ms
4,376 KB |
testcase_24 | AC | 28 ms
4,456 KB |
testcase_25 | AC | 2 ms
4,380 KB |
testcase_26 | AC | 24 ms
4,408 KB |
testcase_27 | AC | 30 ms
4,416 KB |
testcase_28 | AC | 1 ms
4,380 KB |
testcase_29 | AC | 2 ms
4,376 KB |
testcase_30 | AC | 22 ms
4,416 KB |
testcase_31 | AC | 21 ms
4,492 KB |
testcase_32 | AC | 16 ms
4,376 KB |
testcase_33 | AC | 27 ms
4,420 KB |
testcase_34 | AC | 25 ms
4,540 KB |
testcase_35 | AC | 10 ms
4,380 KB |
testcase_36 | AC | 4 ms
4,376 KB |
testcase_37 | AC | 12 ms
4,376 KB |
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内: main.cpp:81:37: 警告: ‘idx’ may be used uninitialized [-Wmaybe-uninitialized] 81 | cout << i << " " << idx << endl; | ^~~ main.cpp:64:13: 備考: ‘idx’ はここで定義されています 64 | int idx, x_min; | ^~~
ソースコード
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100000; const int INF = INT_MAX; struct SegmentTree { int n, data[MAX_N * 4]; //多めに確保 void init(int size) { n = 1; while (n < size) n *= 2; //INFで初期化 for (int i = 0; i < 2 * n - 1; i++) data[i] = INF; } void update(int k, int a) { k += n - 1; //葉の節点 data[k] = a; while (k > 0) { k = (k - 1) / 2; data[k] = min(data[k * 2 + 1], data[k * 2 + 2]); } } //[a, b)の最小値を求める //k:節点番号, [l, r):節点に対応する区間 int getmin(int a, int b, int k, int l, int r) { //[a, b)と[l, r)が交差しない場合 if (r <= a || b <= l) return INF; //[a, b)が[l, r)を含む場合、節点の値 if (a <= l && r <= b) return data[k]; else { //二つの子の最小値 int vl = getmin(a, b, k * 2 + 1, l, (l + r) / 2); int vr = getmin(a, b, k * 2 + 2, (l + r) / 2, r); return min(vl, vr); } } //外から呼ぶ用 int getmin(int a, int b) { return getmin(a, b, 0, 0, n); } }; typedef long long ll; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, d; ll k; cin >> n >> d >> k; vector<int> x(n); SegmentTree s; s.init(n); for (int i = 0; i < n; i++) { cin >> x[i]; s.update(i, x[i]); } ll ans = -1e14; int idx, x_min; for (int i = 1; i < n; i++) { int tmp = s.getmin(max(i - d, 0), i); ll b = k * (x[i] - tmp); if (ans < b) { ans = b; idx = i; x_min = tmp; } } if (ans <= 0) { cout << 0 << endl; return 0; } cout << ans << endl; for (int i = max(idx - d, 0); i < idx; i++) { if (x[i] != x_min) continue; cout << i << " " << idx << endl; break; } return 0; }