結果

問題 No.555 世界史のレポート
ユーザー RisenRisen
提出日時 2017-08-12 00:00:39
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 2,595 bytes
コンパイル時間 1,801 ms
コンパイル使用メモリ 111,888 KB
実行使用メモリ 50,668 KB
最終ジャッジ日時 2024-04-21 00:01:47
合計ジャッジ時間 11,119 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
36,280 KB
testcase_01 AC 43 ms
29,096 KB
testcase_02 AC 75 ms
33,188 KB
testcase_03 AC 72 ms
35,232 KB
testcase_04 AC 91 ms
33,428 KB
testcase_05 AC 91 ms
29,220 KB
testcase_06 AC 86 ms
33,308 KB
testcase_07 AC 104 ms
33,324 KB
testcase_08 AC 96 ms
31,524 KB
testcase_09 AC 140 ms
33,452 KB
testcase_10 TLE -
testcase_11 AC 1,878 ms
44,716 KB
testcase_12 TLE -
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Linq;

public class PriorityQueue<TKey, TValue>
{
    SortedDictionary<TKey, HashSet<TValue>> dict = new SortedDictionary<TKey, HashSet<TValue>>();
    int count = 0;

    public int Count
    {
        get
        {
            return count;
        }
    }

    public void Enqueue(TKey key, TValue value)
    {
        if (!dict.ContainsKey(key))
        {
            dict[key] = new HashSet<TValue>();
        }

        dict[key].Add(value);
        count++;
    }

    public KeyValuePair<TKey, TValue> Dequeue()
    {
        var queue = dict.First();
        if (queue.Value.Count <= 1)
        {
            dict.Remove(queue.Key);
        }

        var val = queue.Value.First();
        queue.Value.Remove(val);
        count--;
        return new KeyValuePair<TKey, TValue>(queue.Key, val);
    }

    public KeyValuePair<TKey, TValue> Peek()
    {
        var queue = dict.First();
        var val = queue.Value.First();
        return new KeyValuePair<TKey, TValue>(queue.Key, val);
    }

    public void ChangePriority(TKey prevKey, TKey newKey, TValue value)
    {
        var set = dict[prevKey];
        set.Remove(value);
        if (set.Count == 0)
        {
            dict.Remove(prevKey);
        }
        count--;

        Enqueue(newKey, value);
    }
}

class Solution
{
    internal struct State
    {
        internal int Cost;
        internal int Length;
        internal int CopiedLength;

        internal State(int c, int l, int cl)
        {
            Cost = c;
            Length = l;
            CopiedLength = cl;
        }
    }

    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var c = vals[0];
        var v = vals[1];

        // cost -> length, copied length
        var states = new PriorityQueue<int, State>();
        states.Enqueue(0, new State(0, 1, 0) );

        State best = states.Peek().Value;
        while (states.Count > 0)
        {
            var cur = states.Dequeue().Value;

            if (cur.Length >= n)
            {
                best = cur;
                break;
            }

            // copy
            var copied = new State(cur.Cost + c, cur.Length, cur.Length);
            states.Enqueue(copied.Cost, copied);
            // paste
            var paste = new State(cur.Cost + v, cur.Length + cur.CopiedLength, cur.CopiedLength);
            states.Enqueue(paste.Cost, paste);
        }

        Console.WriteLine(best.Cost);
    }
}
0