結果

問題 No.412 花火大会
ユーザー 14番14番
提出日時 2016-09-02 02:22:35
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 3,309 bytes
コンパイル時間 3,119 ms
コンパイル使用メモリ 104,888 KB
実行使用メモリ 24,160 KB
最終ジャッジ日時 2023-08-09 20:11:04
合計ジャッジ時間 5,973 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
22,040 KB
testcase_01 AC 68 ms
24,088 KB
testcase_02 AC 71 ms
22,044 KB
testcase_03 AC 67 ms
24,028 KB
testcase_04 AC 65 ms
19,888 KB
testcase_05 AC 68 ms
22,044 KB
testcase_06 AC 68 ms
24,160 KB
testcase_07 AC 67 ms
20,052 KB
testcase_08 AC 65 ms
21,952 KB
testcase_09 AC 66 ms
24,036 KB
testcase_10 AC 69 ms
22,188 KB
testcase_11 AC 68 ms
22,100 KB
testcase_12 AC 69 ms
21,928 KB
testcase_13 AC 68 ms
24,156 KB
testcase_14 AC 67 ms
21,980 KB
testcase_15 AC 67 ms
21,948 KB
testcase_16 AC 66 ms
22,100 KB
testcase_17 AC 68 ms
22,136 KB
testcase_18 AC 67 ms
22,100 KB
testcase_19 AC 69 ms
22,092 KB
testcase_20 AC 67 ms
21,924 KB
testcase_21 AC 67 ms
22,188 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
        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();
    }
}
0