結果
| 問題 |
No.467 隠されていたゲーム
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-12-17 01:53:09 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,518 bytes |
| コンパイル時間 | 2,479 ms |
| コンパイル使用メモリ | 114,020 KB |
| 実行使用メモリ | 169,848 KB |
| 最終ジャッジ日時 | 2024-11-30 22:26:01 |
| 合計ジャッジ時間 | 19,941 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 6 WA * 13 TLE * 5 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
public class Program
{
public void Proc() {
Reader.IsDebug = false;
int itemCount = int.Parse(Reader.ReadLine());
this.items = Reader.ReadLine().Split(' ').Select(a=>long.Parse(a)).OrderByDescending(a=>a).ToArray();
this.range = Reader.ReadLine().Split(' ').Select(a=>Math.Abs(long.Parse(a))).Max();
Dictionary<long, long> dic = new Dictionary<long, long>();
long pos = range;
dic.Add(pos, 0);
Queue<long> que = new Queue<long>();
que.Enqueue(pos);
while(que.Count > 0) {
pos = que.Dequeue();
if(pos == 0) {
break;
}
if(pos % items[0] == 0) {
if((!dic.ContainsKey(0)) || dic[0] > pos / items[0]) {
dic[0] = pos / items[0];
continue;
}
}
long step = dic[pos];
items.ToList().ForEach(a=>{
long[] tmp = new long[]{a, a*-1};
foreach(long item in tmp) {
long nextPos = pos + item;
if(pos >= 0 && nextPos >= 0 && nextPos > pos) {
continue;
}
if(pos <= 0 && nextPos <= 0 && nextPos < pos) {
continue;
}
if(dic.ContainsKey(nextPos) && dic[nextPos] <= step + 1) {
continue;
}
dic[nextPos] = step + 1;
que.Enqueue(nextPos);
}
});
}
if(dic.ContainsKey(0)) {
Console.WriteLine(dic[0]);
} else {
Console.WriteLine(-1);
}
}
private long[] items;
private long range;
public class Reader {
public static bool IsDebug = true;
private static System.IO.StringReader SReader;
private static string InitText = @"
1
1
45 14
";
public static string ReadLine() {
if(IsDebug) {
if(SReader == null) {
SReader = new System.IO.StringReader(InitText.Trim());
}
return SReader.ReadLine();
} else {
return Console.ReadLine();
}
}
}
public static void Main(string[] args)
{
Program prg = new Program();
prg.Proc();
}
}
14番