結果

問題 No.53 悪の漸化式
ユーザー nanophoto12nanophoto12
提出日時 2014-10-31 01:03:19
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 55 ms / 5,000 ms
コード長 3,392 bytes
コンパイル時間 2,081 ms
コンパイル使用メモリ 106,788 KB
実行使用メモリ 23,340 KB
最終ジャッジ日時 2023-08-28 23:34:38
合計ジャッジ時間 3,814 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
21,152 KB
testcase_01 AC 53 ms
23,340 KB
testcase_02 AC 54 ms
21,036 KB
testcase_03 AC 54 ms
23,140 KB
testcase_04 AC 53 ms
21,176 KB
testcase_05 AC 55 ms
21,176 KB
testcase_06 AC 52 ms
21,100 KB
testcase_07 AC 53 ms
21,264 KB
testcase_08 AC 54 ms
23,216 KB
testcase_09 AC 55 ms
21,096 KB
testcase_10 AC 53 ms
21,080 KB
testcase_11 AC 52 ms
21,228 KB
testcase_12 AC 54 ms
21,116 KB
testcase_13 AC 55 ms
23,196 KB
testcase_14 AC 54 ms
21,084 KB
testcase_15 AC 52 ms
21,116 KB
testcase_16 AC 54 ms
21,116 KB
testcase_17 AC 52 ms
21,180 KB
testcase_18 AC 53 ms
21,100 KB
testcase_19 AC 54 ms
23,208 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Globalization;
using System.Text;

class Program
{
    internal class BigInt
    {
        private static readonly int _size = 56;
        private static readonly int _decimalDigits = _size - 2;
        private readonly int[] _buffer = new int[_size];
        private static readonly int _upThreshold = 100000000;

        public BigInt(int source)
        {
            _buffer[_decimalDigits] = source;
        }


        public BigInt(BigInt source)
        {
            Array.Copy(source._buffer, _buffer, _buffer.Length);
        }

        public override string ToString()
        {
            var buider = new StringBuilder();
            for (int i = _buffer.Length - 1; i >= _decimalDigits; i--)
            {
                if (_buffer[i] != 0)
                {
                    buider.Append(_buffer[i].ToString(CultureInfo.InvariantCulture));
                }
            }
            if (buider.Length == 0)
            {
                buider.Append("0.");
            }
            else
            {
                buider.Append(".");
            }
            for (int i = _decimalDigits-1; i >= _decimalDigits - 5; i--)
            {
                buider.Append(_buffer[i].ToString("00000000"));
            }

            return buider.ToString();
        }

        public BigInt Mul(int value)
        {
            var newInt = new BigInt(this);
            var up = 0;
            for (int i = 0; i < _size; i++)
            {
                newInt._buffer[i] *= value;
                newInt._buffer[i] += up;
                if (newInt._buffer[i] >= 1e8)
                {
                    up = newInt._buffer[i]/_upThreshold;
                    newInt._buffer[i] %= _upThreshold;
                }
                else
                {
                    up = 0;
                }
            }
            return newInt;
        }

        public BigInt Subtract(BigInt value)
        {
            var newInt = new BigInt(this);
            for (int i = 0; i < _size; i++)
            {
                newInt._buffer[i] -= value._buffer[i];
                if (newInt._buffer[i] < 0)
                {
                    newInt._buffer[i] += _upThreshold;
                    newInt._buffer[i + 1] -= 1;
                }
            }
            return newInt;            
        }

        public BigInt Divide(int value)
        {
            var newInt = new BigInt(this);
            for (int i = 0; i < _size; i++)
            {
                var down = newInt._buffer[i] % value;
                if (down > 0)
                {
                    newInt._buffer[i - 1] += _upThreshold*down/value;
                }
                newInt._buffer[i] /= value;
            }
            return newInt;            
        }
    }

    public static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());

        BigInt[] bigInts = new BigInt[101];
        bigInts[0] = new BigInt(4);
        bigInts[1] = new BigInt(3);
        for (int i = 2; i <= n; i++)
        {
            bigInts[i] = bigInts[i - 1].Mul(19).Subtract(bigInts[i - 2].Mul(12));
            bigInts[i] = bigInts[i].Divide(4);
        }
        Console.WriteLine(bigInts[n].ToString());
    }
}
0