結果

問題 No.1199 お菓子配り-2
ユーザー Lily89164763Lily89164763
提出日時 2020-08-28 21:50:08
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 416 ms / 1,000 ms
コード長 2,761 bytes
コンパイル時間 4,218 ms
コンパイル使用メモリ 112,576 KB
実行使用メモリ 49,536 KB
最終ジャッジ日時 2024-04-26 14:43:23
合計ジャッジ時間 19,291 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
25,004 KB
testcase_01 AC 26 ms
23,224 KB
testcase_02 AC 26 ms
25,116 KB
testcase_03 AC 112 ms
42,016 KB
testcase_04 AC 237 ms
42,572 KB
testcase_05 AC 36 ms
21,108 KB
testcase_06 AC 42 ms
22,400 KB
testcase_07 AC 134 ms
38,656 KB
testcase_08 AC 169 ms
40,064 KB
testcase_09 AC 115 ms
35,712 KB
testcase_10 AC 52 ms
24,704 KB
testcase_11 AC 101 ms
32,512 KB
testcase_12 AC 96 ms
32,896 KB
testcase_13 AC 54 ms
26,240 KB
testcase_14 AC 48 ms
23,952 KB
testcase_15 AC 44 ms
23,740 KB
testcase_16 AC 165 ms
41,216 KB
testcase_17 AC 95 ms
31,488 KB
testcase_18 AC 168 ms
41,472 KB
testcase_19 AC 63 ms
24,064 KB
testcase_20 AC 284 ms
44,228 KB
testcase_21 AC 187 ms
41,728 KB
testcase_22 AC 107 ms
24,960 KB
testcase_23 AC 143 ms
35,840 KB
testcase_24 AC 189 ms
40,960 KB
testcase_25 AC 55 ms
25,984 KB
testcase_26 AC 217 ms
40,576 KB
testcase_27 AC 178 ms
40,960 KB
testcase_28 AC 411 ms
49,536 KB
testcase_29 AC 408 ms
49,096 KB
testcase_30 AC 416 ms
49,104 KB
testcase_31 AC 412 ms
48,892 KB
testcase_32 AC 413 ms
49,260 KB
testcase_33 AC 416 ms
49,280 KB
testcase_34 AC 405 ms
49,448 KB
testcase_35 AC 412 ms
49,040 KB
testcase_36 AC 403 ms
49,312 KB
testcase_37 AC 407 ms
49,284 KB
testcase_38 AC 405 ms
49,272 KB
testcase_39 AC 395 ms
49,500 KB
testcase_40 AC 407 ms
49,360 KB
testcase_41 AC 401 ms
49,088 KB
testcase_42 AC 395 ms
49,260 KB
testcase_43 AC 404 ms
49,376 KB
testcase_44 AC 407 ms
49,328 KB
testcase_45 AC 408 ms
49,060 KB
testcase_46 AC 398 ms
49,256 KB
testcase_47 AC 404 ms
49,068 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, m;
        var ln = Console.ReadLine().Trim().Split(' ');
        n = int.Parse(ln[0]);
        m = int.Parse(ln[1]);

        long[][] a = new long[n][];
        for (int i = 0; i < n; i++)
        {
            a[i] = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
        }

        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(Math.Max(dp[0], dp[1]));
    }

    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