結果
問題 | No.555 世界史のレポート |
ユーザー | Risen |
提出日時 | 2017-08-12 00:07:17 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 1,201 ms / 2,000 ms |
コード長 | 2,679 bytes |
コンパイル時間 | 944 ms |
コンパイル使用メモリ | 108,416 KB |
実行使用メモリ | 30,208 KB |
最終ジャッジ日時 | 2024-04-21 00:06:23 |
合計ジャッジ時間 | 4,119 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
20,736 KB |
testcase_01 | AC | 38 ms
20,864 KB |
testcase_02 | AC | 38 ms
20,992 KB |
testcase_03 | AC | 41 ms
21,248 KB |
testcase_04 | AC | 42 ms
21,632 KB |
testcase_05 | AC | 43 ms
21,888 KB |
testcase_06 | AC | 41 ms
21,632 KB |
testcase_07 | AC | 41 ms
21,760 KB |
testcase_08 | AC | 41 ms
21,376 KB |
testcase_09 | AC | 44 ms
22,528 KB |
testcase_10 | AC | 108 ms
25,176 KB |
testcase_11 | AC | 83 ms
25,148 KB |
testcase_12 | AC | 127 ms
25,472 KB |
testcase_13 | AC | 214 ms
26,240 KB |
testcase_14 | AC | 1,201 ms
30,208 KB |
testcase_15 | AC | 54 ms
25,216 KB |
testcase_16 | AC | 80 ms
25,136 KB |
testcase_17 | AC | 60 ms
25,216 KB |
testcase_18 | AC | 87 ms
25,128 KB |
testcase_19 | AC | 81 ms
25,292 KB |
コンパイルメッセージ
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.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(c, 1, 1) ); State best = states.Peek().Value; while (states.Count > 0) { var cur = states.Dequeue().Value; if (cur.Length >= n) { best = cur; break; } // copy if (cur.Length != cur.CopiedLength) { 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); } }