結果
問題 | No.320 眠れない夜に |
ユーザー |
![]() |
提出日時 | 2016-05-18 22:50:29 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 38 ms / 2,000 ms |
コード長 | 2,981 bytes |
コンパイル時間 | 1,029 ms |
コンパイル使用メモリ | 113,672 KB |
実行使用メモリ | 28,000 KB |
最終ジャッジ日時 | 2024-10-06 05:42:36 |
合計ジャッジ時間 | 2,950 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 31 |
コンパイルメッセージ
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.Text;using System.Linq;class Program{public void Proc(){Reader.IsDebug = false;long[] inpt = Reader.ReadLine().Split(' ').Select(a=>long.Parse(a)).ToArray();long times = inpt[0];long count = inpt[1];long[] list = new long[times + 1];list[1] = 1;list[2] = 1;for(long i = 3; i<= times; i++) {int idx = (int)i;list[idx] = list[idx-1] + list[idx - 2];}long sa = list[times] - count;this.NumList = list.Reverse().Skip(2).ToArray();int ans = this.GetAns(0, sa);Console.WriteLine(ans);}Dictionary<int, Dictionary<long, int>> dic = new Dictionary<int, Dictionary<long, int>>();private int GetAns(int idx, long remain) {if(!this.dic.ContainsKey(idx)) {this.dic.Add(idx, new Dictionary<long, int>());}if(dic[idx].ContainsKey(remain)) {return dic[idx][remain];}if(remain == 0) {return 0;}if(idx == this.NumList.Length - 1) {if(remain == this.NumList.Last()) {return 1;} else{return -1;}}int ans = -1;if(this.NumList.ToList().IndexOf(remain) >= idx) {ans = 1;} else if(this.NumList.Skip(idx).Sum(a=>a) < remain) {ans = -1;} else {int ret = this.GetAns(idx+1, remain);if(ret >= 0) {if(ans < 0) {ans = ret;} else{ans = Math.Min(ans, ret);}}if(remain >= this.NumList[idx]) {ret = this.GetAns(idx+1, remain - this.NumList[idx]);if(ret >= 0) {ret++;if(ans < 0) {ans = ret;} else{ans = Math.Min(ans, ret);}}}}this.dic[idx].Add(remain, ans);return ans;}private long[] NumList;public class Reader{public static bool IsDebug = true;private static String PlainInput = @"80 1";private static System.IO.StringReader Sr = null;public static string ReadLine(){if (IsDebug){if (Sr == null){Sr = new System.IO.StringReader(PlainInput.Trim());}return Sr.ReadLine();}else{return Console.ReadLine();}}}static void Main(){Program prg = new Program();prg.Proc();}}