結果
| 問題 |
No.555 世界史のレポート
|
| ユーザー |
Risen
|
| 提出日時 | 2017-08-12 00:00:39 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,595 bytes |
| コンパイル時間 | 1,238 ms |
| コンパイル使用メモリ | 115,044 KB |
| 実行使用メモリ | 45,496 KB |
| 最終ジャッジ日時 | 2024-10-12 22:20:25 |
| 合計ジャッジ時間 | 10,931 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 TLE * 4 -- * 6 |
コンパイルメッセージ
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(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);
}
}
Risen