結果

問題 No.489 株に挑戦
ユーザー 14番14番
提出日時 2017-05-31 13:38:30
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 4,235 bytes
コンパイル時間 3,166 ms
コンパイル使用メモリ 114,220 KB
実行使用メモリ 75,012 KB
最終ジャッジ日時 2023-10-21 19:03:55
合計ジャッジ時間 15,143 ms
ジャッジサーバーID
(参考情報)
judge12 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 WA -
testcase_02 AC 41 ms
27,108 KB
testcase_03 AC 39 ms
27,020 KB
testcase_04 AC 41 ms
27,108 KB
testcase_05 AC 42 ms
27,108 KB
testcase_06 AC 43 ms
27,104 KB
testcase_07 AC 42 ms
27,108 KB
testcase_08 AC 41 ms
27,112 KB
testcase_09 AC 43 ms
27,108 KB
testcase_10 AC 42 ms
27,112 KB
testcase_11 AC 44 ms
27,104 KB
testcase_12 AC 43 ms
27,104 KB
testcase_13 AC 43 ms
27,108 KB
testcase_14 AC 43 ms
27,108 KB
testcase_15 AC 99 ms
31,544 KB
testcase_16 TLE -
testcase_17 AC 205 ms
31,292 KB
testcase_18 AC 643 ms
39,400 KB
testcase_19 AC 566 ms
37,832 KB
testcase_20 TLE -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 TLE -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Text;
using System.Net;

    
public class Program
{
    public void Proc() {
        int[] inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray();

        int dayCount = inpt[0];
        int amount = inpt[2];
        int range = inpt[1];

        SortedDictionary<int, Queue<int>> minDic1 = new SortedDictionary<int, Queue<int>>();
        SortedDictionary<int, Queue<int>> maxDic1 = new SortedDictionary<int, Queue<int>>();
        SortedDictionary<int, Queue<int>> minDic2 = new SortedDictionary<int, Queue<int>>();
        SortedDictionary<int, Queue<int>> maxDic2 = new SortedDictionary<int, Queue<int>>();

        int ans = 0;
        int fromIdx = 0;
        int toIdx = 0;
        for(int i=0; i<dayCount; i++) {
            int prev = Math.Max(0, i-range);
            int tmp = int.Parse(Reader.ReadLine());
            if(!minDic1.ContainsKey(tmp)) {
                minDic1.Add(tmp, new Queue<int>());
            }
            minDic1[tmp].Enqueue(i);

            if(!minDic2.ContainsKey(tmp)) {
                minDic2.Add(tmp, new Queue<int>());
            }
            minDic2[tmp].Enqueue(i);

            if(!maxDic1.ContainsKey(tmp*-1)) {
                maxDic1.Add(tmp*-1, new Queue<int>());
            }
            maxDic1[tmp*-1].Enqueue(i);

            if(!maxDic2.ContainsKey(tmp*-1)) {
                maxDic2.Add(tmp*-1, new Queue<int>());
            }
            maxDic2[tmp*-1].Enqueue(i);

            while(minDic1.Count>0&&minDic1.First().Value.Peek() < prev) {
                minDic1.First().Value.Dequeue();
                if(minDic1.First().Value.Count <= 0) {
                    minDic1.Remove(minDic1.First().Key);
                }
            }

            while(maxDic1.Count>0 && (maxDic1.First().Value.Peek() < minDic1.First().Value.Peek() || maxDic1.First().Value.Peek() < prev)) {
                maxDic1.First().Value.Dequeue();
                if(maxDic1.First().Value.Count <= 0) {
                    maxDic1.Remove(maxDic1.First().Key);
                }
            }

            while(maxDic2.Count>0&&maxDic2.First().Value.Peek() < prev) {
                maxDic2.First().Value.Dequeue();
                if(maxDic2.First().Value.Count <= 0) {
                    maxDic2.Remove(maxDic2.First().Key);
                }
            }

            while(minDic2.Count > 0&&(minDic2.First().Value.Peek() > maxDic2.First().Value.Peek() || minDic2.First().Value.Peek() <prev)) {
                minDic2.First().Value.Dequeue();
                if(minDic2.First().Value.Count <= 0) {
                    minDic2.Remove(minDic2.First().Key);
                }
            }


            if(maxDic1.Count > 0 && minDic1.Count > 0 && maxDic1.First().Key*-1 - minDic1.First().Key > ans) {
                ans = maxDic1.First().Key * -1 - minDic1.First().Key;
                fromIdx = minDic1.First().Value.Peek();
                toIdx = maxDic1.First().Value.Peek();
            }
            if(maxDic2.Count > 0 && minDic2.Count > 0 && maxDic2.First().Key*-1 - minDic2.First().Key > ans) {
                ans = maxDic2.First().Key * -1 - minDic2.First().Key;
                fromIdx = minDic2.First().Value.Peek();
                toIdx = maxDic2.First().Value.Peek();
            }
        }
        Console.WriteLine(ans*amount);
        if(ans > 0) {
            Console.WriteLine(fromIdx + " " + toIdx);
        }


    }


    public class Reader {
        public static bool IsDebug = false;
        private static System.IO.StringReader SReader;
        private static string InitText = @"




5 4 100
1
2
1
2
1




";
        public static string ReadLine() {
            if(IsDebug) {
                if(SReader == null) {
                    SReader = new System.IO.StringReader(InitText.Trim());
                }
                return SReader.ReadLine();
            } else {
                return Console.ReadLine();
            }
        }
    }
    public static void Main(string[] args)
    {
        #if DEBUG
        Reader.IsDebug = true;
        #endif
        Program prg = new Program();
        prg.Proc();
    }
}
0