結果
問題 | No.489 株に挑戦 |
ユーザー | tanzaku |
提出日時 | 2017-02-24 21:09:05 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 181 ms / 1,000 ms |
コード長 | 3,192 bytes |
コンパイル時間 | 6,437 ms |
コンパイル使用メモリ | 76,768 KB |
実行使用メモリ | 56,112 KB |
最終ジャッジ日時 | 2023-09-27 04:55:43 |
合計ジャッジ時間 | 9,994 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 162 ms
53,920 KB |
testcase_01 | AC | 150 ms
53,956 KB |
testcase_02 | AC | 69 ms
51,684 KB |
testcase_03 | AC | 69 ms
51,844 KB |
testcase_04 | AC | 43 ms
48,736 KB |
testcase_05 | AC | 72 ms
50,128 KB |
testcase_06 | AC | 71 ms
50,108 KB |
testcase_07 | AC | 76 ms
52,824 KB |
testcase_08 | AC | 69 ms
51,728 KB |
testcase_09 | AC | 69 ms
50,484 KB |
testcase_10 | AC | 67 ms
50,056 KB |
testcase_11 | AC | 73 ms
51,824 KB |
testcase_12 | AC | 69 ms
51,848 KB |
testcase_13 | AC | 70 ms
50,800 KB |
testcase_14 | AC | 78 ms
50,644 KB |
testcase_15 | AC | 103 ms
53,196 KB |
testcase_16 | AC | 165 ms
54,436 KB |
testcase_17 | AC | 117 ms
53,856 KB |
testcase_18 | AC | 149 ms
53,908 KB |
testcase_19 | AC | 147 ms
54,364 KB |
testcase_20 | AC | 176 ms
53,912 KB |
testcase_21 | AC | 143 ms
54,348 KB |
testcase_22 | AC | 110 ms
53,336 KB |
testcase_23 | AC | 155 ms
53,792 KB |
testcase_24 | AC | 173 ms
56,112 KB |
testcase_25 | AC | 41 ms
48,936 KB |
testcase_26 | AC | 133 ms
52,976 KB |
testcase_27 | AC | 171 ms
55,972 KB |
testcase_28 | AC | 71 ms
50,444 KB |
testcase_29 | AC | 41 ms
49,040 KB |
testcase_30 | AC | 181 ms
56,020 KB |
testcase_31 | AC | 181 ms
54,576 KB |
testcase_32 | AC | 157 ms
53,840 KB |
testcase_33 | AC | 179 ms
55,800 KB |
testcase_34 | AC | 164 ms
53,808 KB |
testcase_35 | AC | 147 ms
53,820 KB |
testcase_36 | AC | 131 ms
54,820 KB |
testcase_37 | AC | 156 ms
54,228 KB |
ソースコード
import java.io.*; import java.util.*; public class _489_Validate { public static void main(String[] args) throws IOException { new _489_Validate().solve(); } void solve() throws IOException { try (final InputValidator in = new InputValidator(System.in)) { // try (final Scanner in = new Scanner(System.in)) { int n = in.nextInt(1, 100000); in.space(); int d = in.nextInt(1, n); in.space(); int k = in.nextInt(1, 1000000); in.newLine(); int[] x = new int[n]; for (int i = 0; i < n; i++) { x[i] = -in.nextInt(1, 1000000); in.newLine(); } SlideMinimum slide = new SlideMinimum(x, d + 1); int l = 0, r = 0; long ans = 0; for (int i = n - 1; i >= 0; i--) { // dump(i, slide.min(i), ans, -slide.min(i) + x[i]); final int v = -slide.min(i) + x[i]; if (ans <= v) { ans = v; l = i; r = slide.minIdx(i); } } System.out.println(ans * k); if (ans != 0) { System.out.println(l + " " + r); } } } // [i,i+m) static public class SlideMinimum { int[] b; int[] idx; public SlideMinimum(int[] a, int m) { final int n = a.length; b = new int[n]; idx = new int[n]; int s, t; s = t = 0; int[] deq = new int[n]; for (int i = 0; i < n + m - 1; i++) { while( s < t && i < n && a[deq[t-1]] > a[i]) t--; if (i < n) deq[t++] = i; if (i - m + 1 >= 0) { b[i-m+1] = a[idx[i-m+1] = deq[s]]; if(deq[s] == i - m + 1) { s++; } } } } // min [idx..idx+m) public int min(int idx) { return b[idx]; } public int minIdx(int i) { return idx[i]; } } // for debug static void dump(Object... o) { System.err.println(Arrays.deepToString(o)); } static class InputValidator implements Closeable { final InputStream in; final int NO_BUFFER = -2; int buffer; public InputValidator(final InputStream in) { this.in = in; buffer = NO_BUFFER; } int read() throws IOException { final int res = buffer == NO_BUFFER ? in.read() : buffer; buffer = NO_BUFFER; return res; } void unread(int ch) throws IOException { buffer = ch; } // [low, high] long nextLong(long low, long high) throws IOException { long val = 0; int ch = -1; while (true) { ch = read(); if (!Character.isDigit(ch)) break; val = val * 10 + ch - '0'; check(val <= high); } check(ch >= 0); check(val >= low); unread(ch); return val; } int nextInt(int low, int high) throws IOException { return (int)nextLong(low, high); } int[] nextInts(int n, int low, int high) throws IOException { int[] res = new int[n]; for (int i = 0; i < n; i++) { res[i] = nextInt(low, high); if (i + 1 != n) space(); } newLineOrEOF(); return res; } void space() throws IOException { int ch = read(); check(ch == ' '); } void newLine() throws IOException { int ch = read(); if (ch == '\r') ch = read(); check(ch == '\n'); } void newLineOrEOF() throws IOException { int ch = read(); check(ch == '\r' || ch == '\n' || ch < 0); } void check(boolean b) { if (!b) throw new RuntimeException(); } @Override public void close() throws IOException { } } }