結果

問題 No.40 多項式の割り算
ユーザー sekiya9311sekiya9311
提出日時 2017-10-10 23:25:08
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 40 ms / 5,000 ms
コード長 3,551 bytes
コンパイル時間 1,024 ms
コンパイル使用メモリ 116,712 KB
実行使用メモリ 28,232 KB
最終ジャッジ日時 2024-04-28 15:30:57
合計ジャッジ時間 3,382 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
25,172 KB
testcase_01 AC 32 ms
27,292 KB
testcase_02 AC 31 ms
25,124 KB
testcase_03 AC 31 ms
27,212 KB
testcase_04 AC 38 ms
28,060 KB
testcase_05 AC 38 ms
28,232 KB
testcase_06 AC 39 ms
26,184 KB
testcase_07 AC 38 ms
26,024 KB
testcase_08 AC 36 ms
25,504 KB
testcase_09 AC 38 ms
26,020 KB
testcase_10 AC 39 ms
26,168 KB
testcase_11 AC 38 ms
27,780 KB
testcase_12 AC 40 ms
25,584 KB
testcase_13 AC 38 ms
26,284 KB
testcase_14 AC 38 ms
25,776 KB
testcase_15 AC 38 ms
27,932 KB
testcase_16 AC 39 ms
26,432 KB
testcase_17 AC 37 ms
25,904 KB
testcase_18 AC 38 ms
26,096 KB
testcase_19 AC 40 ms
26,608 KB
testcase_20 AC 37 ms
26,164 KB
testcase_21 AC 37 ms
27,656 KB
testcase_22 AC 36 ms
27,392 KB
testcase_23 AC 39 ms
25,892 KB
testcase_24 AC 38 ms
26,188 KB
testcase_25 AC 32 ms
27,208 KB
testcase_26 AC 32 ms
27,036 KB
testcase_27 AC 32 ms
27,340 KB
testcase_28 AC 32 ms
25,396 KB
testcase_29 AC 31 ms
23,092 KB
testcase_30 AC 32 ms
25,256 KB
testcase_31 AC 32 ms
25,124 KB
testcase_32 AC 32 ms
25,252 KB
testcase_33 AC 32 ms
25,252 KB
testcase_34 AC 32 ms
27,336 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.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProgrammingContest
{
    class MainClass
    {
        Scanner sc;
        static void Main(string[] args)
        {
            new MainClass().Solve();
        }

        void Solve()
        {
#if DEBUG
            string backPath = "..";
            char dirSep = System.IO.Path.DirectorySeparatorChar;
            string inFilePath = backPath + dirSep + backPath + dirSep + "in.txt";
            sc = new Scanner(new System.IO.StreamReader(inFilePath));
#else
            sc = new Scanner();
#endif

            int D = sc.NextInt;
            int[] a = new int[D + 1].Select(val => sc.NextInt).ToArray();
            Array.Reverse(a);
            for (int i = 0; i < D - 2; i++)
            {
                a[i + 2] += a[i];
            }
            int dd = Math.Min(2, D);
            List<int> ans = new List<int>();
            if (dd == 2 && a[D - 2] != 0)
            {
                for (int i = D - 2; i <= D; i++)
                {
                    ans.Add(a[i]);
                }
            }
            else if (dd >= 1 && a[D - 1] != 0)
            {
                for (int i = D - 1; i <= D; i++)
                {
                    ans.Add(a[i]);
                }
            }
            else
            {
                ans.Add(a[D]);
            }
            ans.Reverse();
            Write(ans.Count - 1);
            Write(ArrayToString(ans.ToArray()));
        }
        string ArrayToString<T>(T[] ar, string sep = " ")
        {
            return string.Join(sep, Array.ConvertAll(ar, el => el.ToString()));
        }
        void Write(object val)
        {
            Console.WriteLine(val.ToString());
        }
        void Write(string format, params object[] vals)
        {
            Console.WriteLine(format, vals);
        }
        void fill<T>(T[] ar, T val)
        {
            for (int i = 0; i < ar.Length; i++)
            {
                ar[i] = val;
            }
        }
    }
    class Scanner
    {
        Queue<String> buffer;
        char[] sep;
        System.IO.TextReader reader;
        public Scanner(System.IO.TextReader reader = null)
        {
            this.buffer = new Queue<string>();
            this.sep = new char[] { ' ' };
            this.reader = (reader ?? Console.In);
        }
        private void CheckBuffer()
        {
            if (this.buffer.Count == 0 && this.reader.Peek() >= 0)
            {
                string[] sreArray = this.reader.ReadLine().Split(this.sep);
                foreach (String elStr in sreArray)
                {
                    this.buffer.Enqueue(elStr);
                }
            }
        }

        public String Next
        {
            get
            {
                this.CheckBuffer();
                return this.buffer.Dequeue();
            }
        }

        public int NextInt
        {
            get
            {
                return int.Parse(this.Next);
            }
        }
        public double NextDouble
        {
            get
            {
                return double.Parse(this.Next);
            }
        }

        public long NextLong
        {
            get
            {
                return long.Parse(this.Next);
            }
        }
        public bool IsEmpty
        {
            get
            {
                this.CheckBuffer();
                return this.buffer.Count == 0;
            }
        }
    }
}
0