結果

問題 No.489 株に挑戦
ユーザー 14番14番
提出日時 2017-05-31 15:53:43
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 3,336 bytes
コンパイル時間 1,273 ms
コンパイル使用メモリ 114,888 KB
実行使用メモリ 52,756 KB
最終ジャッジ日時 2023-10-21 19:04:31
合計ジャッジ時間 5,992 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
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];
        this.range = inpt[1];

        SortedDictionary<int, List<int>> dic = new SortedDictionary<int, List<int>>();

        for(int i=0; i<dayCount; i++) {
            int prev = Math.Max(0, i-range);
            int tmp = int.Parse(Reader.ReadLine());
            
            if(!dic.ContainsKey(tmp)) {
                dic.Add(tmp, new List<int>());
            }
            dic[tmp].Add(i);
        }
        int ans = GetAns(0, dic.Last().Key, dic);
        Console.WriteLine(ans * amount);
        if(ans > 0) {
            Console.WriteLine(fromIdx + " " + toIdx);
        }

    }

    private int GetAns(int min, int max, SortedDictionary<int, List<int>> dic) {
        if(max-min<=1) {
            if(CanSet(max, dic)) {
                return max;
            } else {
                return min;
            }
        }
        int mid = (max+min)/2;
        if(CanSet(mid, dic)) {
            return GetAns(mid, max, dic);
        } else {
            return GetAns(min, mid, dic);
        }
    }
    private int range = 0;
    private int fromIdx = -1;
    private int toIdx = -1;
    private bool CanSet(int target , SortedDictionary<int, List<int>> dic) {
        if(target <= 0) {
            return true;
        }
        int[] keys = dic.Keys.ToArray();
        for(int i=0; i<keys.Length - 1; i++) {
            for(int j=i+1; j<keys.Length; j++) {
                if(keys[i]+target>keys[j]) {
                    continue;
                }
                if(dic[keys[i]].First() > dic[keys[j]].Last()) {
                    continue;
                }
                int subIdx = 0;
                for(int k=0; k<dic[keys[i]].Count; k++) {
                    for(int l=subIdx; l<dic[keys[j]].Count; l++) {
                        subIdx = l;
                        if(dic[keys[j]][l] < dic[keys[i]][k]) {
                            continue;
                        }
                        if(dic[keys[j]][l] > dic[keys[i]][k] + range) {
                            break;
                        }
                        this.fromIdx = dic[keys[i]][k];
                        this.toIdx = dic[keys[j]][l];
                        return true;
                    }
                }
            }
        }
        return false;
    }


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




7 2 1000
1
3
5
1
4
4
7




";
        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