結果
問題 | No.320 眠れない夜に |
ユーザー |
![]() |
提出日時 | 2017-07-25 19:40:37 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 25 ms / 2,000 ms |
コード長 | 1,138 bytes |
コンパイル時間 | 1,089 ms |
コンパイル使用メモリ | 110,044 KB |
実行使用メモリ | 26,132 KB |
最終ジャッジ日時 | 2024-10-09 17:18:49 |
合計ジャッジ時間 | 2,926 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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; using System.Collections.Generic; using System.Collections.Specialized; using System.Text; using System.Text.RegularExpressions; using System.Linq; using System.IO; class Program { static void Main() { new Magatro().Solve(); } } class Magatro { private int N; private long M; private long[] Fib; private void Scan() { var line = Console.ReadLine().Split(' '); N = int.Parse(line[0]); M = long.Parse(line[1]); } public void Solve() { Scan(); Fib = new long[81]; Fib[0] = 0; Fib[1] = 1; Fib[2] = 1; for (int i = 3; i <= 80; i++) { Fib[i] = Fib[i - 1] + Fib[i - 2]; } long sa = Fib[N] - M; int ans = 0; for (int i = N - 2; i >= 1; i--) { if (Fib[i] <= sa) { ans++; sa -= Fib[i]; } } if (sa == 0) { Console.WriteLine(ans); } else { Console.WriteLine(-1); } } }