結果
問題 | No.887 Collatz |
ユーザー |
|
提出日時 | 2019-10-14 17:54:59 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 23 ms / 2,000 ms |
コード長 | 1,500 bytes |
コンパイル時間 | 1,118 ms |
コンパイル使用メモリ | 104,704 KB |
実行使用メモリ | 17,792 KB |
最終ジャッジ日時 | 2024-12-24 06:07:55 |
合計ジャッジ時間 | 2,572 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
コンパイルメッセージ
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.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace yukicoder { public class IO { public static string ReadStr() => Console.ReadLine(); public static string[] ReadStrArr() => ReadStr().Split(' '); public static int ReadInt() => int.Parse(ReadStr()); public static int[] ReadIntArr() => Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); public static double ReadDouble() => double.Parse(ReadStr()); public static double[] ReadDoubleArr() => Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); public static long ReadLong() => long.Parse(ReadStr()); public static long[] ReadLongArr() => Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } class Program { static void Main(string[] args) { int init = IO.ReadInt(); var data = new long[400]; data[0] = init; for (var i = 1; i < 400; i++) { data[i] = (data[i-1] % 2 == 0) ? data[i-1] / 2 : 3 * (data[i - 1]) + 1; } int indexOfOne = Array.IndexOf(data, 1); long max = long.MinValue; for (var i = 0; i <= indexOfOne; i++) { max = Math.Max(max, data[i]); } Console.WriteLine("{0}\n{1}",indexOfOne,max); return; } } }