結果
| 問題 |
No.412 花火大会
|
| ユーザー |
14番
|
| 提出日時 | 2016-09-02 02:22:35 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 36 ms / 2,000 ms |
| コード長 | 3,309 bytes |
| コンパイル時間 | 2,669 ms |
| コンパイル使用メモリ | 108,672 KB |
| 実行使用メモリ | 19,584 KB |
| 最終ジャッジ日時 | 2024-11-15 17:30:06 |
| 合計ジャッジ時間 | 3,510 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 18 |
コンパイルメッセージ
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;
this.Requests = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).OrderByDescending(a => a).ToArray();
this.SheetCount = int.Parse(Reader.ReadLine());
this.Sheets = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).OrderBy(a => a).ToArray();
long ans = this.GetAns(0, false, false, false);
Console.WriteLine(ans);
}
private Dictionary<int, Dictionary<int, long>> dic = new Dictionary<int, Dictionary<int, long>>();
private long GetAns(int idx, bool fixA, bool fixB, bool fixC)
{
int fixKey = 0;
if (fixA)
{
fixKey += 1;
}
if (fixB)
{
fixKey += 2;
}
if (fixC)
{
fixKey += 4;
}
if (!dic.ContainsKey(idx))
{
dic.Add(idx, new Dictionary<int, long>());
}
if (dic[idx].ContainsKey(fixKey))
{
return dic[idx][fixKey];
}
if (idx == SheetCount)
{
if (fixA && fixB && fixC)
{
return 1;
}
else
{
return 0;
}
}
long ans = 0;
if (fixA && fixB && fixC)
{
ans += this.GetAns(idx + 1, fixA, fixB, fixC) * 2;
}
else
{
ans += this.GetAns(idx + 1, fixA, fixB, fixC);
bool newFixA = fixA;
bool newFixB = fixB;
bool newFixC = fixC;
bool isfixed = false;
if (!newFixC)
{
if (Sheets[idx] >= Requests[2])
{
newFixC = true;
isfixed = true;
}
}
if ((!newFixB) && (!isfixed))
{
if (Sheets[idx] >= Requests[1])
{
newFixB = true;
isfixed = true;
}
}
if ((!newFixA) && (!isfixed))
{
if (Sheets[idx] >= Requests[0])
{
newFixA = true;
isfixed = true;
}
}
ans += this.GetAns(idx + 1, newFixA, newFixB, newFixC);
}
dic[idx].Add(fixKey, ans);
return ans;
}
private int[] Requests;
private int SheetCount;
private int[] Sheets;
public class Reader
{
public static bool IsDebug = true;
private static String PlainInput = @"
15 25 35
10
10 20 30 40 50 60 70 80 90 100
";
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番