結果
| 問題 | No.335 門松宝くじ |
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-05-23 07:50:20 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,118 bytes |
| 記録 | |
| コンパイル時間 | 1,017 ms |
| コンパイル使用メモリ | 115,752 KB |
| 実行使用メモリ | 24,576 KB |
| 最終ジャッジ日時 | 2024-10-07 00:08:44 |
| 合計ジャッジ時間 | 4,856 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 1 TLE * 1 -- * 8 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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();
}
}
14番