結果

問題 No.489 株に挑戦
ユーザー 14番
提出日時 2017-05-31 15:53:43
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 3,336 bytes
コンパイル時間 1,026 ms
コンパイル使用メモリ 116,596 KB
実行使用メモリ 59,564 KB
最終ジャッジ日時 2024-09-21 20:21:19
合計ジャッジ時間 5,905 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other TLE * 1 -- * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
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