結果

問題 No.887 Collatz
ユーザー CroweaCrowea
提出日時 2019-10-14 17:54:59
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,500 bytes
コンパイル時間 1,713 ms
コンパイル使用メモリ 63,452 KB
実行使用メモリ 22,824 KB
最終ジャッジ日時 2023-08-25 20:04:19
合計ジャッジ時間 4,615 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
20,564 KB
testcase_01 AC 59 ms
20,684 KB
testcase_02 AC 58 ms
20,680 KB
testcase_03 AC 58 ms
22,824 KB
testcase_04 AC 58 ms
22,696 KB
testcase_05 AC 58 ms
22,792 KB
testcase_06 AC 57 ms
22,728 KB
testcase_07 AC 59 ms
20,748 KB
testcase_08 AC 58 ms
20,760 KB
testcase_09 AC 58 ms
20,728 KB
testcase_10 AC 58 ms
20,788 KB
testcase_11 AC 57 ms
20,684 KB
testcase_12 AC 57 ms
20,624 KB
testcase_13 AC 58 ms
20,768 KB
testcase_14 AC 58 ms
22,688 KB
testcase_15 AC 58 ms
20,760 KB
testcase_16 AC 57 ms
22,784 KB
testcase_17 AC 58 ms
22,700 KB
testcase_18 AC 57 ms
22,732 KB
testcase_19 AC 58 ms
22,784 KB
testcase_20 AC 58 ms
22,676 KB
testcase_21 AC 58 ms
20,692 KB
testcase_22 AC 58 ms
20,804 KB
testcase_23 AC 57 ms
20,688 KB
testcase_24 AC 58 ms
22,752 KB
testcase_25 AC 58 ms
20,700 KB
testcase_26 AC 57 ms
20,776 KB
testcase_27 AC 57 ms
20,624 KB
testcase_28 AC 58 ms
20,908 KB
testcase_29 AC 58 ms
20,688 KB
testcase_30 AC 58 ms
22,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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;
        }
    }
}
0