結果
問題 | No.489 株に挑戦 |
ユーザー | mban |
提出日時 | 2017-07-25 09:49:38 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,448 bytes |
コンパイル時間 | 1,125 ms |
コンパイル使用メモリ | 115,948 KB |
実行使用メモリ | 31,436 KB |
最終ジャッジ日時 | 2024-10-09 17:01:37 |
合計ジャッジ時間 | 6,472 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 152 ms
31,096 KB |
testcase_01 | AC | 101 ms
27,940 KB |
testcase_02 | AC | 30 ms
25,240 KB |
testcase_03 | AC | 32 ms
25,096 KB |
testcase_04 | AC | 30 ms
27,044 KB |
testcase_05 | AC | 31 ms
25,224 KB |
testcase_06 | AC | 31 ms
25,244 KB |
testcase_07 | AC | 31 ms
25,224 KB |
testcase_08 | AC | 31 ms
25,348 KB |
testcase_09 | AC | 33 ms
25,396 KB |
testcase_10 | AC | 31 ms
25,240 KB |
testcase_11 | AC | 31 ms
25,376 KB |
testcase_12 | AC | 31 ms
25,352 KB |
testcase_13 | AC | 31 ms
25,248 KB |
testcase_14 | AC | 32 ms
25,248 KB |
testcase_15 | AC | 37 ms
25,228 KB |
testcase_16 | AC | 164 ms
31,176 KB |
testcase_17 | AC | 47 ms
25,348 KB |
testcase_18 | AC | 109 ms
28,028 KB |
testcase_19 | AC | 89 ms
23,732 KB |
testcase_20 | AC | 165 ms
29,248 KB |
testcase_21 | AC | 60 ms
26,032 KB |
testcase_22 | AC | 42 ms
25,600 KB |
testcase_23 | AC | 110 ms
27,972 KB |
testcase_24 | AC | 191 ms
29,376 KB |
testcase_25 | AC | 31 ms
27,428 KB |
testcase_26 | AC | 173 ms
31,436 KB |
testcase_27 | WA | - |
testcase_28 | AC | 32 ms
27,292 KB |
testcase_29 | AC | 30 ms
25,356 KB |
testcase_30 | AC | 165 ms
29,628 KB |
testcase_31 | AC | 160 ms
29,368 KB |
testcase_32 | AC | 117 ms
27,732 KB |
testcase_33 | AC | 185 ms
27,160 KB |
testcase_34 | AC | 173 ms
29,236 KB |
testcase_35 | AC | 85 ms
25,904 KB |
testcase_36 | AC | 49 ms
25,352 KB |
testcase_37 | WA | - |
コンパイルメッセージ
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; } }