結果

問題 No.320 眠れない夜に
ユーザー mban
提出日時 2017-07-25 19:39:14
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,134 bytes
コンパイル時間 3,075 ms
コンパイル使用メモリ 113,240 KB
実行使用メモリ 27,928 KB
最終ジャッジ日時 2024-10-09 17:18:18
合計ジャッジ時間 5,059 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 25 WA * 6
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.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; i >= 1; i--)
        {
            if (Fib[i] <= sa)
            {
                ans++;
                sa -= Fib[i];
            }
        }
        if (sa == 0)
        {
            Console.WriteLine(ans);
        }
        else
        {
            Console.WriteLine(-1);
        }
    }
}

0