結果

問題 No.648  お や す み 
ユーザー バカらっく
提出日時 2018-02-09 23:07:54
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,948 bytes
コンパイル時間 869 ms
コンパイル使用メモリ 112,476 KB
実行使用メモリ 18,176 KB
最終ジャッジ日時 2024-09-13 21:02:25
合計ジャッジ時間 4,898 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 84
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        long inpt = long.Parse(Reader.ReadLine());
        this.Sheep = inpt;
        Nullable<long> ans = GetAns(1, inpt);
        if(ans == null) {
            Console.WriteLine("NO");
            return;
        }
        Console.WriteLine("YES");
        Console.WriteLine(ans.Value);
    }

    private long Sheep;

    private Nullable<long> GetAns(long min, long max) {
        if(max-min<=1) {
            if(GetNum(max)==this.Sheep) {
                return max;
            } 
            if(GetNum(min)==this.Sheep) {
                return min;
            }

            return null;
        }
        long mid = (max + min) / 2;
        if(mid.ToString().Length>=11) {
            return GetAns(min, mid);
        }
        decimal midNum = GetNum(mid);
        if(midNum==Sheep) {
            return mid;
        }
        if(midNum>Sheep) {
            return GetAns(min, mid);
        } else {
            return GetAns(mid, max);
        }
    }

    private decimal GetNum(long n) {
        decimal tmp = n;
        return n * (n + 1m) / 2m;
    }

    public class Reader
    {
        private static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"


2000000000000000000


";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}
0