結果
問題 | No.489 株に挑戦 |
ユーザー | mban |
提出日時 | 2017-07-25 09:49:59 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 197 ms / 1,000 ms |
コード長 | 3,449 bytes |
コンパイル時間 | 2,643 ms |
コンパイル使用メモリ | 115,116 KB |
実行使用メモリ | 33,208 KB |
最終ジャッジ日時 | 2024-07-19 23:55:24 |
合計ジャッジ時間 | 8,839 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 155 ms
30,956 KB |
testcase_01 | AC | 108 ms
25,644 KB |
testcase_02 | AC | 32 ms
25,244 KB |
testcase_03 | AC | 32 ms
25,120 KB |
testcase_04 | AC | 31 ms
24,992 KB |
testcase_05 | AC | 31 ms
25,008 KB |
testcase_06 | AC | 30 ms
23,088 KB |
testcase_07 | AC | 31 ms
27,140 KB |
testcase_08 | AC | 30 ms
24,968 KB |
testcase_09 | AC | 31 ms
25,000 KB |
testcase_10 | AC | 32 ms
25,132 KB |
testcase_11 | AC | 31 ms
25,376 KB |
testcase_12 | AC | 32 ms
26,912 KB |
testcase_13 | AC | 32 ms
27,168 KB |
testcase_14 | AC | 32 ms
27,012 KB |
testcase_15 | AC | 39 ms
25,348 KB |
testcase_16 | AC | 166 ms
29,132 KB |
testcase_17 | AC | 47 ms
25,352 KB |
testcase_18 | AC | 107 ms
25,776 KB |
testcase_19 | AC | 90 ms
25,864 KB |
testcase_20 | AC | 163 ms
27,084 KB |
testcase_21 | AC | 59 ms
25,908 KB |
testcase_22 | AC | 41 ms
25,092 KB |
testcase_23 | AC | 109 ms
28,108 KB |
testcase_24 | AC | 196 ms
29,116 KB |
testcase_25 | AC | 30 ms
27,040 KB |
testcase_26 | AC | 170 ms
29,496 KB |
testcase_27 | AC | 197 ms
29,104 KB |
testcase_28 | AC | 30 ms
24,968 KB |
testcase_29 | AC | 31 ms
27,008 KB |
testcase_30 | AC | 165 ms
33,208 KB |
testcase_31 | AC | 162 ms
31,276 KB |
testcase_32 | AC | 119 ms
27,724 KB |
testcase_33 | AC | 186 ms
29,084 KB |
testcase_34 | AC | 173 ms
27,060 KB |
testcase_35 | AC | 84 ms
27,452 KB |
testcase_36 | AC | 49 ms
27,152 KB |
testcase_37 | AC | 104 ms
27,584 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Text; using System.Text.RegularExpressions; using System.Linq; using System.IO; class Program { static void Main() { new Magatro().Solve(); } } struct S { public int Index, Num; public S(int index, int num) { Index = index; Num = num; } } class Magatro { private int N, D, K; private S[] X; private void Scan() { var line = Console.ReadLine().Split(' '); N = int.Parse(line[0]); D = int.Parse(line[1]); K = int.Parse(line[2]); X = new S[N]; for (int i = 0; i < N; i++) { X[i] = new S(i, int.Parse(Console.ReadLine())); } } private int Compare(S a, S b) { if (a.Num != b.Num) { return -a.Num.CompareTo(b.Num); } else { return -a.Index.CompareTo(b.Index); } } public void Solve() { Scan(); int max = 0; int l = -1, r = -1; bool flag = false; var segtree = new SegmentTree<S>(X, Compare, new S(-1, int.MaxValue)); for (int i = 1; i < N; i++) { int left = Math.Max(i - D, 0); S min = segtree.Query(left, i); if (X[i].Num - min.Num > max) { flag = true; l = min.Index; r = i; max = X[i].Num - min.Num; } } if (flag) { Console.WriteLine((long)K * max); Console.WriteLine($"{l} {r}"); } else { Console.WriteLine(0); } } } class SegmentTree<T> { private Comparison<T> Comparison; private int N; private T[] Tree; private T Min; public SegmentTree(int length, Comparison<T> comparition, T min) { for (N = 1; N <= length; N *= 2) ; Comparison = comparition; Tree = (new T[2 * N - 1]).Select(i => min).ToArray(); Min = min; } public SegmentTree(T[] array, Comparison<T> comparition, T min) : this(array.Length, comparition, min) { for (int i = 0; i < array.Length; i++) { Update(i, array[i]); } } /// <summary> /// index(0_indexed)をvに更新 /// </summary> /// <param name="index"></param> /// <param name="v"></param> public void Update(int index, T v) { int i = index + N - 1; Tree[i] = v; while (i > 0) { i = (i - 1) / 2; Tree[i] = Max(Tree[i * 2 + 1], Tree[i * 2 + 2]); } } /// <summary> /// [left,right)の最大値 /// </summary> /// <param name="left"></param> /// <param name="right"></param> /// <returns></returns> public T Query(int left, int right) { return Query(left, right, 0, 0, N); } private T Query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return Min; if (a <= l && r <= b) { return Tree[k]; } else { T vl = Query(a, b, k * 2 + 1, l, (l + r) / 2); T vr = Query(a, b, k * 2 + 2, (l + r) / 2, r); return Max(vl, vr); } } private T Max(T a, T b) { return Comparison(a, b) >= 0 ? a : b; } }