結果
問題 |
No.648 お や す み
|
ユーザー |
![]() |
提出日時 | 2018-02-09 22:57:52 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,810 bytes |
コンパイル時間 | 2,381 ms |
コンパイル使用メモリ | 105,728 KB |
実行使用メモリ | 828,288 KB |
最終ジャッジ日時 | 2024-10-08 17:35:34 |
合計ジャッジ時間 | 4,897 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 2 MLE * 1 -- * 81 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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; long midNum = GetNum(mid); if(midNum==Sheep) { return mid; } if(midNum>Sheep) { return GetAns(min, mid); } else { return GetAns(mid, max); } } private long GetNum(long n) { return n * (n + 1) / 2; } 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 = @" 10 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }