結果
| 問題 |
No.291 黒い文字列
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-05-15 02:08:39 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 4,094 bytes |
| コンパイル時間 | 1,017 ms |
| コンパイル使用メモリ | 114,048 KB |
| 実行使用メモリ | 53,400 KB |
| 最終ジャッジ日時 | 2024-10-06 03:01:20 |
| 合計ジャッジ時間 | 4,920 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 8 TLE * 1 -- * 17 |
コンパイルメッセージ
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;
string inpt = Reader.ReadLine();
int ans = this.GetAns(inpt, 0, new List<string>());
Console.WriteLine(ans);
}
private int GetAns(string inpt, int idx, List<string> items)
{
if (inpt.Count(a => a == '?') == 0)
{
return Count(inpt);
}
if (inpt.Count(a => a != '?') == 0)
{
return inpt.Length / this.target.Length;
}
for (int i = idx; i < inpt.Length; i++)
{
if (inpt[i] == '?')
{
string[] splt = inpt.Split('?');
string prt1 = splt[0];
string prt2 = string.Join("?", splt.Skip(1).ToArray());
List<string> subItems = new List<string>(items);
subItems.Add("K");
int ans = this.GetAns(prt1 + "K" + prt2, idx+1, subItems);
for (int j = 1; j < target.Length; j++)
{
string str = items.FirstOrDefault(a => a.Length == j);
if (str != null)
{
subItems = new List<string>(items);
int ind = items.IndexOf(str);
subItems[ind] += target[j];
ans = Math.Max(ans, this.GetAns(prt1 + target[j] + prt2, idx + 1, subItems));
}
}
return ans;
}
else
{
for (int j = 0; j < target.Length; j++)
{
if (inpt[i] == target[j])
{
if (j == 0)
{
items.Add(target[0].ToString());
}
else
{
string str = items.FirstOrDefault(a => a.Length == j);
if (str != null)
{
int ind = items.IndexOf(str);
items[ind] += target[j];
}
}
break;
}
}
}
}
return 0;
}
private char[] target = new char[] { 'K', 'U', 'R', 'O', 'I' };
private int Count(string inpt)
{
List<string> tmp = new List<string>();
for (int i = 0; i < inpt.Length; i++)
{
for (int j = 0; j < target.Length; j++)
{
if (inpt[i] == target[j])
{
if (j == 0)
{
tmp.Add(target[0].ToString());
}
else
{
string key = tmp.FirstOrDefault(a => a.Length == j);
if (key != null)
{
int idx = tmp.IndexOf(key);
tmp[idx] += target[j];
}
}
break;
}
}
}
return tmp.Count(a => a.Length == target.Length);
}
public class Reader
{
public static bool IsDebug = true;
private static String PlainInput = @"
KUROIME?UR?CHA?
";
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番