結果

問題 No.467 隠されていたゲーム
ユーザー 14番14番
提出日時 2016-12-17 01:53:09
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,518 bytes
コンパイル時間 3,877 ms
コンパイル使用メモリ 108,140 KB
実行使用メモリ 110,176 KB
最終ジャッジ日時 2023-08-20 18:38:03
合計ジャッジ時間 7,793 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 72 ms
22,016 KB
testcase_02 AC 70 ms
22,116 KB
testcase_03 AC 72 ms
19,896 KB
testcase_04 AC 73 ms
24,168 KB
testcase_05 AC 70 ms
22,036 KB
testcase_06 AC 71 ms
20,044 KB
testcase_07 WA -
testcase_08 AC 70 ms
21,904 KB
testcase_09 AC 70 ms
22,180 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.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();
    }
}
0