結果

問題 No.489 株に挑戦
ユーザー mbanmban
提出日時 2017-07-25 09:49:38
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 3,448 bytes
コンパイル時間 2,208 ms
コンパイル使用メモリ 114,140 KB
実行使用メモリ 30,036 KB
最終ジャッジ日時 2024-04-17 23:19:10
合計ジャッジ時間 5,927 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 154 ms
23,936 KB
testcase_01 AC 103 ms
21,888 KB
testcase_02 AC 30 ms
19,072 KB
testcase_03 AC 30 ms
19,328 KB
testcase_04 AC 31 ms
19,072 KB
testcase_05 AC 31 ms
19,072 KB
testcase_06 AC 32 ms
19,072 KB
testcase_07 AC 30 ms
18,944 KB
testcase_08 AC 30 ms
19,328 KB
testcase_09 AC 30 ms
19,200 KB
testcase_10 AC 30 ms
19,328 KB
testcase_11 AC 30 ms
19,200 KB
testcase_12 AC 31 ms
19,328 KB
testcase_13 AC 31 ms
19,328 KB
testcase_14 AC 31 ms
19,328 KB
testcase_15 AC 37 ms
19,428 KB
testcase_16 AC 165 ms
23,808 KB
testcase_17 AC 46 ms
19,556 KB
testcase_18 AC 109 ms
21,504 KB
testcase_19 AC 90 ms
20,992 KB
testcase_20 AC 167 ms
24,704 KB
testcase_21 AC 60 ms
20,480 KB
testcase_22 AC 42 ms
19,452 KB
testcase_23 AC 112 ms
22,016 KB
testcase_24 AC 193 ms
25,344 KB
testcase_25 AC 30 ms
19,200 KB
testcase_26 AC 173 ms
24,448 KB
testcase_27 WA -
testcase_28 AC 30 ms
19,200 KB
testcase_29 AC 30 ms
19,200 KB
testcase_30 AC 167 ms
25,216 KB
testcase_31 AC 161 ms
24,448 KB
testcase_32 AC 118 ms
21,888 KB
testcase_33 AC 188 ms
25,216 KB
testcase_34 AC 174 ms
24,576 KB
testcase_35 AC 86 ms
21,120 KB
testcase_36 AC 47 ms
19,680 KB
testcase_37 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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;
    }
}
0