結果

問題 No.335 門松宝くじ
ユーザー 14番14番
提出日時 2016-05-23 07:50:20
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 3,118 bytes
コンパイル時間 2,332 ms
コンパイル使用メモリ 109,184 KB
実行使用メモリ 28,672 KB
最終ジャッジ日時 2024-04-16 08:38:50
合計ジャッジ時間 5,943 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
24,832 KB
testcase_01 AC 32 ms
19,328 KB
testcase_02 AC 34 ms
19,328 KB
testcase_03 AC 35 ms
19,200 KB
testcase_04 AC 35 ms
19,456 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Generic;
using System.Text;
using System.Linq;

class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        int [] inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray();
        int numCount = inpt[0];
        int kujiCount = inpt[1];
        
        int maxTotal = 0;
        int maxIdx = 0;
        
        for(int i=0; i<kujiCount; i++) {
            int total = 0;
            List<int> numList = new List<int>();
            inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray();
            numList.Add(inpt[0]);
            numList.Add(inpt[1]);
            for(int j=2; j<inpt.Length; j++) {
                int max = 0;
                for(int k=0; k<j; k++) {
                    int numBig = Math.Max(inpt[j], inpt[k]);
                    int numSmall = Math.Min(inpt[j], inpt[k]);
                    Nullable<int> ret = null;
                    if(j - k > 1) {
                        int[] tmp = numList.Skip(k + 1).Where(a=>a > numBig || a < numSmall).ToArray();
                        if(tmp.Length > 0) {
                            ret = tmp.Max();
                            max = Math.Max(max, Math.Max(ret.Value, numBig));
                        }
                    }
                    if(k > 0) {
                        int[] tmp = numList.Take(k).Where(a=> (inpt[j] > inpt[k] && a > inpt[k]) || (inpt[j] < inpt[k] && a < inpt[k])).ToArray();
                        if(tmp.Length > 0) {
                            ret = tmp.Max();
                            max = Math.Max(max, Math.Max(ret.Value, numBig));
                        }
                    }
                    if(j < inpt.Length - 1) {
                        int[] tmp = inpt.Skip(j).Where(a=>(inpt[j] > inpt[k] && inpt[j] > a) || (inpt[j] < inpt[k] && inpt[j] < a)).ToArray();
                        if(tmp.Length > 0) {
                            ret = tmp.Max();
                            max = Math.Max(max, Math.Max(ret.Value, numBig));
                        }
                    }
                    total += max;
                }
                numList.Add(inpt[j]);
            }
            if(maxTotal < total) {
                maxTotal = total;
                maxIdx = i;
            }
        }
        if(maxIdx < 0) {
            maxIdx = 0;
        }
        Console.WriteLine(maxIdx);
    }


    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"


5 3
2 1 3 4 5
3 2 1 5 4
5 2 4 1 3


 
";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0