結果

問題 No.3044 April Sum of Odd
ユーザー AreTrashAreTrash
提出日時 2019-04-01 22:48:27
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 2,687 bytes
コンパイル時間 4,559 ms
コンパイル使用メモリ 106,796 KB
実行使用メモリ 29,476 KB
最終ジャッジ日時 2023-08-18 01:56:36
合計ジャッジ時間 5,606 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
21,660 KB
testcase_01 AC 64 ms
23,620 KB
testcase_02 AC 64 ms
19,600 KB
testcase_03 AC 72 ms
24,288 KB
testcase_04 AC 74 ms
22,352 KB
testcase_05 AC 76 ms
22,428 KB
testcase_06 AC 76 ms
22,608 KB
testcase_07 AC 73 ms
24,024 KB
testcase_08 AC 73 ms
22,236 KB
testcase_09 AC 74 ms
22,388 KB
testcase_10 AC 104 ms
29,476 KB
testcase_11 AC 94 ms
26,784 KB
testcase_12 AC 62 ms
21,568 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.IO;
using System.Collections.Generic;
using System.Linq;

namespace No3044
{
    public partial class Program
    {
        void Solve(StreamScanner ss, StreamWriter sw)
        {
            //---------------------------------
            var N = ss.Next(int.Parse);
            var M = ss.Next(int.Parse);
            var A = ss.Next(long.Parse, N);

            var cnt = 0L;
            var sum = 0L;
            var ans = new List<long>();

            foreach (var a in A.Concat(new long[] {0}))
            {
                if (a % 2 == 0)
                {
                    if (cnt >= M) ans.Add(sum);
                    cnt = 0;
                    sum = 0;
                }
                else
                {
                    cnt++;
                    sum += a;
                }
            }

            sw.WriteLine(string.Join("\n", ans));
            //---------------------------------
        }
    }

    public class StreamScanner
    {
        static readonly char[] Separator = { ' ' };
        readonly StreamReader streamReader;

        string[] line = new string[0];
        int index = 0;

        public StreamScanner(Stream stream)
        {
            this.streamReader = new StreamReader(stream);
        }

        public string Next()
        {
            return Next(s => s);
        }

        public string[] Next(int x)
        {
            return Next(s => s, x);
        }

        public string[][] Next(int x, int y)
        {
            return Next(s => s, x, y);
        }

        public T Next<T>(Func<string, T> parser)
        {
            if (index < line.Length) return parser(line[index++]);
            index = 0;
            line = streamReader.ReadLine()?.Split(Separator, StringSplitOptions.RemoveEmptyEntries);
            return Next(parser);
        }

        public T[] Next<T>(Func<string, T> parser, int x)
        {
            var ret = new T[x];
            for (var i = 0; i < x; ++i) ret[i] = Next(parser);
            return ret;
        }

        public T[][] Next<T>(Func<string, T> parser, int x, int y)
        {
            var ret = new T[y][];
            for (var i = 0; i < y; ++i) ret[i] = Next(parser, x);
            return ret;
        }
    }

    public partial class Program
    {
        static void Main()
        {
            Excute(Console.OpenStandardInput(), Console.OpenStandardOutput());
        }

        public static void Excute(Stream input, Stream output)
        {
            var ss = new StreamScanner(input);
            var sw = new StreamWriter(output);
            new Program().Solve(ss, sw);
            sw.Flush();
        }
    }
}
0