結果
問題 | No.489 株に挑戦 |
ユーザー | 37zigen |
提出日時 | 2017-02-24 23:30:05 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,220 bytes |
コンパイル時間 | 3,575 ms |
コンパイル使用メモリ | 85,688 KB |
実行使用メモリ | 71,444 KB |
最終ジャッジ日時 | 2023-08-31 00:06:01 |
合計ジャッジ時間 | 21,827 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | AC | 153 ms
56,640 KB |
testcase_03 | AC | 153 ms
56,820 KB |
testcase_04 | AC | 126 ms
55,636 KB |
testcase_05 | AC | 157 ms
56,664 KB |
testcase_06 | AC | 157 ms
56,668 KB |
testcase_07 | AC | 163 ms
56,948 KB |
testcase_08 | AC | 153 ms
56,824 KB |
testcase_09 | AC | 158 ms
56,796 KB |
testcase_10 | AC | 165 ms
57,016 KB |
testcase_11 | AC | 164 ms
56,912 KB |
testcase_12 | AC | 166 ms
54,992 KB |
testcase_13 | AC | 165 ms
56,576 KB |
testcase_14 | AC | 164 ms
56,996 KB |
testcase_15 | AC | 271 ms
61,644 KB |
testcase_16 | AC | 672 ms
69,356 KB |
testcase_17 | AC | 335 ms
60,780 KB |
testcase_18 | AC | 537 ms
63,260 KB |
testcase_19 | AC | 528 ms
63,148 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 135 ms
55,668 KB |
testcase_26 | AC | 728 ms
67,488 KB |
testcase_27 | AC | 840 ms
71,252 KB |
testcase_28 | WA | - |
testcase_29 | AC | 124 ms
55,692 KB |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
ソースコード
package yukicoder; import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class Q485 { static int N, D, K; static int[] x; public static void main(String[] args) { Scanner sc = new Scanner(System.in); N = sc.nextInt(); D = sc.nextInt(); K = sc.nextInt(); x = new int[N]; for (int i = 0; i < N; ++i) { x[i] = sc.nextInt(); } RMQ rmq = new RMQ(N); for (int i = 0; i < N; ++i) { rmq.setVal(i, x[i], i); } int maxProfit = 0; int srcDay = -1, dstDay = -1; for (int i = 0; i < N - 1; ++i) { RMQ.State s = rmq.query(i + 1, i + 1 + D, 0, rmq.n, 0); if (maxProfit < (s.price - x[i]) * K) { maxProfit = (s.price - x[i]) * K; srcDay = i; dstDay = s.day; } } if (maxProfit == 0) { System.out.println(0); } else { System.out.println(maxProfit); System.out.println(srcDay + " " + dstDay); } } static class RMQ { class State implements Comparable<State> { int day, price; public State(int day, int price) { this.day = day; this.price = price; } @Override public int compareTo(State o) { if (price != o.price) { return -Integer.compare(price, o.price); } else { return Integer.compare(day, o.day); } } } int n; State[] val; int INF = Integer.MAX_VALUE / 10; public RMQ(int n_) { n = 1; while (n < n_) n *= 2; val = new State[2 * n - 1]; Arrays.fill(val, new State(INF, -INF)); } void setVal(int k, int price, int day) { k += n - 1; val[k] = new State(day, price); while (k > 0) { k = (k - 1) / 2; val[k] = max(val[2 * k + 1], val[2 * k + 2]); } } State query(int a, int b, int l, int r, int k) { if (b <= l || a >= r) return new State(INF, -INF); if (a <= l && r <= b) return val[k]; else { State vl = query(a, b, l, (l + r) / 2, 2 * k + 1); State vr = query(a, b, (l + r) / 2, r, 2 * k + 2); return max(vl, vr); } } State max(State s1, State s2) { if (s1.compareTo(s2) < 0) { return new State(s1.day, s1.price); } else { return new State(s2.day, s2.price); } } } static void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }