結果
問題 | No.634 硬貨の枚数1 |
ユーザー |
![]() |
提出日時 | 2018-09-09 18:42:09 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 57 ms / 2,000 ms |
コード長 | 969 bytes |
コンパイル時間 | 906 ms |
コンパイル使用メモリ | 103,296 KB |
実行使用メモリ | 17,792 KB |
最終ジャッジ日時 | 2024-12-23 21:07:08 |
合計ジャッジ時間 | 5,979 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 75 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; public class Hello { public static void Main() { var c = getC(); var n = int.Parse(Console.ReadLine().Trim()); if (n == 1) { Console.WriteLine(1); goto end; } var a = getP(c, n); if (c[a] == n) { Console.WriteLine(1); goto end; } var cL = c.Length; for (int i = 0; i <= a; i++) for (int j = 0; j <= a; j++) if (c[i] + c[j] == n) { Console.WriteLine(2); goto end; } Console.WriteLine(3); end:; } public static int[] getC() { var c = new int[4471]; for (int i = 1; i <= 4471; i++) c[i - 1] = i * (i + 1) / 2; return c; } public static int getP(int[] c, int n) { var ng = 0; var ok = c.Length - 1; while (ok - ng > 1) { var mid = ng + (ok - ng) / 2; if (c[mid] >= n) ok = mid; else ng = mid; } return ok; } }