結果
問題 | No.489 株に挑戦 |
ユーザー | uafr_cs |
提出日時 | 2017-02-24 23:40:23 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 820 ms / 1,000 ms |
コード長 | 2,897 bytes |
コンパイル時間 | 3,217 ms |
コンパイル使用メモリ | 90,448 KB |
実行使用メモリ | 60,664 KB |
最終ジャッジ日時 | 2024-07-19 23:11:07 |
合計ジャッジ時間 | 21,615 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 749 ms
49,148 KB |
testcase_01 | AC | 623 ms
48,856 KB |
testcase_02 | AC | 164 ms
42,316 KB |
testcase_03 | AC | 148 ms
41,964 KB |
testcase_04 | AC | 138 ms
41,272 KB |
testcase_05 | AC | 153 ms
42,232 KB |
testcase_06 | AC | 172 ms
42,644 KB |
testcase_07 | AC | 170 ms
42,304 KB |
testcase_08 | AC | 157 ms
42,624 KB |
testcase_09 | AC | 175 ms
42,644 KB |
testcase_10 | AC | 167 ms
42,772 KB |
testcase_11 | AC | 167 ms
42,416 KB |
testcase_12 | AC | 175 ms
42,724 KB |
testcase_13 | AC | 166 ms
42,568 KB |
testcase_14 | AC | 167 ms
42,292 KB |
testcase_15 | AC | 275 ms
47,916 KB |
testcase_16 | AC | 735 ms
54,412 KB |
testcase_17 | AC | 343 ms
47,800 KB |
testcase_18 | AC | 589 ms
48,656 KB |
testcase_19 | AC | 547 ms
48,768 KB |
testcase_20 | AC | 772 ms
52,364 KB |
testcase_21 | AC | 438 ms
48,144 KB |
testcase_22 | AC | 309 ms
47,996 KB |
testcase_23 | AC | 603 ms
48,696 KB |
testcase_24 | AC | 813 ms
55,488 KB |
testcase_25 | AC | 138 ms
41,288 KB |
testcase_26 | AC | 674 ms
49,828 KB |
testcase_27 | AC | 662 ms
55,120 KB |
testcase_28 | AC | 152 ms
42,544 KB |
testcase_29 | AC | 131 ms
41,088 KB |
testcase_30 | AC | 782 ms
55,472 KB |
testcase_31 | AC | 788 ms
60,664 KB |
testcase_32 | AC | 622 ms
48,992 KB |
testcase_33 | AC | 815 ms
56,160 KB |
testcase_34 | AC | 820 ms
50,496 KB |
testcase_35 | AC | 567 ms
48,540 KB |
testcase_36 | AC | 375 ms
47,824 KB |
testcase_37 | AC | 635 ms
48,756 KB |
ソースコード
import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.Scanner; import java.util.Set; public class Main { public static class MaxSegTree{ int n; long[] dat; int[] index; public MaxSegTree(int n_) { int n = 1; while(n < n_){ n *= 2; } this.n = n; dat = new long[this.n * 2 - 1]; index = new int[this.n * 2 - 1]; for(int i = 0; i < this.n * 2 - 1 ; i++){ dat[i] = 0; index[i] = i; } } public void update(int k, long a){ k += n - 1; dat[k] = a; index[k] = (k - (n - 1)); while(k > 0){ k = (k - 1) / 2; if(dat[k * 2 + 1] >= dat[k * 2 + 2]){ dat[k] = dat[k * 2 + 1]; index[k] = index[k * 2 + 1]; }else{ dat[k] = dat[k * 2 + 2]; index[k] = index[k * 2 + 2]; } } } public int query_index(int a, int b, int k, int l, int r){ //System.out.println(a + " " + b + " " + k + " " + l + " " + r); if(r <= a || b <= l){ return -1; } if(a <= l && r <= b){ return index[k]; } final int left_index = query_index(a, b, k * 2 + 1, l, (l + r) / 2); final int right_index = query_index(a, b, k * 2 + 2, (l + r) / 2, r); assert(left_index >= 0 || right_index >= 0); if(right_index < 0){ return left_index; } if(left_index < 0){ return right_index; } //System.out.println(dat[left_index] + " " + dat[right_index]); if(dat[left_index + (this.n - 1)] >= dat[right_index + (this.n - 1)]){ return left_index; }else{ return right_index; } } public int query_index(int a, int b){ return query_index(a, b, 0, 0, n); } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); final int D = sc.nextInt(); final int K = sc.nextInt(); long[] price = new long[N]; for(int i = 0; i < N; i++){ price[i] = sc.nextLong(); } MaxSegTree seg = new MaxSegTree(N); for(int i = 0; i < N; i++){ seg.update(i, price[i]); } //System.out.println(Arrays.toString(seg.index)); long answer = Long.MIN_VALUE; int a_begin = -1, b_begin = -1; for(int begin = 0; begin < N; begin++){ final int end = Math.min(N, begin + D + 1); //System.out.println(begin + " " + end); final int max_pos = seg.query_index(begin, end); final long range_max = price[max_pos]; final long begin_price = price[begin]; final long money = (range_max - begin_price) * K; //System.out.printf("[%d, %d) => %d - %d = %d\n", begin, end, range_max , begin_price, money); if(answer < money){ answer = money; a_begin = begin; b_begin = max_pos; } } System.out.println(answer); if(answer != 0){ System.out.println(a_begin + " " + b_begin); } } }