結果
| 問題 |
No.27 板の準備
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-05-29 15:05:15 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 3,352 bytes |
| コンパイル時間 | 2,371 ms |
| コンパイル使用メモリ | 109,184 KB |
| 実行使用メモリ | 25,088 KB |
| 最終ジャッジ日時 | 2024-10-14 17:13:09 |
| 合計ジャッジ時間 | 2,616 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 WA * 1 |
コンパイルメッセージ
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 ans = int.MaxValue;
int[] ita = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
for (int i = 1; i <= 30 - 2; i++)
{
for(int j=i+1; j<=30-1; j++) {
for (int k = j + 1; k <= 30; k++)
{
int cnt = 0;
bool cannot = false;
foreach (int num in ita)
{
int key = (1 << i) + (i << j) + (i << k);
int ret = this.GetAns(key, i, j, k, num);
if (ret == 0)
{
cannot = true;
break;
}
else
{
cnt += ret;
}
}
if (!cannot)
{
ans = Math.Min(cnt, ans);
}
}
}
}
Console.WriteLine(ans);
}
private Dictionary<int, Dictionary<int, int>> dic = new Dictionary<int, Dictionary<int, int>>();
private int GetAns(int key, int a, int b, int c, int target)
{
if (!dic.ContainsKey(key))
{
dic.Add(key, new Dictionary<int, int>());
}
if (dic[key].ContainsKey(target))
{
return dic[key][target];
}
int ans = int.MaxValue;
if (c == target)
{
ans = 1;
}
else if (target > c)
{
int ret = this.GetAns(key, a, b, c, target - c);
if (ret > 0)
{
ret++;
ans = Math.Min(ans, ret);
}
}
if (b == target)
{
ans = 1;
}
else if (target > b)
{
int ret = this.GetAns(key, a, b, c, target - b);
if (ret > 0)
{
ret++;
ans = Math.Min(ans, ret);
}
}
if (a == target)
{
ans = 1;
}
else if (target > a)
{
int ret = this.GetAns(key, a, b, c, target - a);
if (ret > 0)
{
ret++;
ans = Math.Min(ans, ret);
}
}
if (ans == int.MaxValue)
{
ans = 0;
}
dic[key].Add(target, ans);
return ans;
}
public class Reader
{
public static bool IsDebug = true;
private static String PlainInput = @"
2 3 7 15
";
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番