結果

問題 No.1199 お菓子配り-2
ユーザー Lily89164763
提出日時 2020-08-28 21:46:01
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 440 ms / 1,000 ms
コード長 2,623 bytes
コンパイル時間 3,012 ms
コンパイル使用メモリ 113,544 KB
実行使用メモリ 57,444 KB
最終ジャッジ日時 2024-11-14 03:15:45
合計ジャッジ時間 17,956 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45
権限があれば一括ダウンロードができます
コンパイルメッセージ
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();
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0