結果

問題 No.1199 お菓子配り-2
ユーザー Lily89164763Lily89164763
提出日時 2020-08-28 21:46:01
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 460 ms / 1,000 ms
コード長 2,623 bytes
コンパイル時間 3,895 ms
コンパイル使用メモリ 104,492 KB
実行使用メモリ 55,732 KB
最終ジャッジ日時 2023-08-08 22:30:37
合計ジャッジ時間 22,101 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
21,856 KB
testcase_01 AC 63 ms
21,864 KB
testcase_02 AC 63 ms
23,984 KB
testcase_03 AC 155 ms
36,480 KB
testcase_04 AC 285 ms
47,100 KB
testcase_05 AC 76 ms
22,384 KB
testcase_06 AC 82 ms
24,732 KB
testcase_07 AC 174 ms
41,392 KB
testcase_08 AC 212 ms
42,964 KB
testcase_09 AC 156 ms
38,480 KB
testcase_10 AC 91 ms
27,292 KB
testcase_11 AC 137 ms
35,232 KB
testcase_12 AC 135 ms
35,464 KB
testcase_13 AC 92 ms
26,736 KB
testcase_14 AC 88 ms
28,216 KB
testcase_15 AC 85 ms
26,168 KB
testcase_16 AC 209 ms
48,144 KB
testcase_17 AC 137 ms
34,136 KB
testcase_18 AC 213 ms
46,204 KB
testcase_19 AC 106 ms
28,832 KB
testcase_20 AC 330 ms
47,080 KB
testcase_21 AC 226 ms
44,512 KB
testcase_22 AC 146 ms
29,404 KB
testcase_23 AC 187 ms
40,448 KB
testcase_24 AC 231 ms
45,712 KB
testcase_25 AC 94 ms
30,720 KB
testcase_26 AC 257 ms
45,116 KB
testcase_27 AC 220 ms
47,776 KB
testcase_28 AC 455 ms
51,716 KB
testcase_29 AC 453 ms
51,548 KB
testcase_30 AC 451 ms
51,800 KB
testcase_31 AC 453 ms
55,732 KB
testcase_32 AC 454 ms
53,764 KB
testcase_33 AC 454 ms
51,632 KB
testcase_34 AC 452 ms
53,588 KB
testcase_35 AC 454 ms
51,816 KB
testcase_36 AC 456 ms
53,676 KB
testcase_37 AC 457 ms
53,772 KB
testcase_38 AC 460 ms
53,604 KB
testcase_39 AC 459 ms
51,616 KB
testcase_40 AC 457 ms
51,864 KB
testcase_41 AC 457 ms
53,940 KB
testcase_42 AC 455 ms
53,624 KB
testcase_43 AC 457 ms
54,048 KB
testcase_44 AC 453 ms
53,752 KB
testcase_45 AC 451 ms
53,624 KB
testcase_46 AC 455 ms
53,904 KB
testcase_47 AC 452 ms
53,564 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.Linq;
using CompLib.Util;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        int m = sc.NextInt();

        long[][] a = new long[n][];
        for (int i = 0; i < n; i++)
        {
            a[i] = sc.LongArray();
        }

        long[] s = new long[n];
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                s[i] += a[i][j];
            }
        }

        long[] dp = new long[2];
        dp[0] = 0;
        dp[1] = s[0];

        for (int i = 1; i < n; i++)
        {
            var next = new long[2];
            next[1] = Math.Max(dp[1], dp[0] + s[i]);
            next[0] = Math.Max(dp[0], dp[1] - s[i]);
            dp = next;
        }

        Console.WriteLine(dp.Max());
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}
0