結果
問題 | No.505 カードの数式2 |
ユーザー |
|
提出日時 | 2019-03-27 16:28:00 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 26 ms / 2,000 ms |
コード長 | 2,903 bytes |
コンパイル時間 | 2,034 ms |
コンパイル使用メモリ | 110,088 KB |
実行使用メモリ | 26,276 KB |
最終ジャッジ日時 | 2024-11-14 07:32:45 |
合計ジャッジ時間 | 2,522 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace AtTest.DP { class yuki505 { static void Main(string[] args) { Method(args); ReadLine(); } static void Method(string[] args) { int n = ReadInt(); int[] array = ReadInts(); long[,] dp = new long[n, 2];//plus max/minus max dp[0, 0] = array[0]; dp[0, 1] = array[0]; for(int i = 1; i < n; i++) { if (array[i] == 0) { dp[i, 0] = Max( Max( Max(dp[i - 1, 0] + array[i], dp[i - 1, 0] - array[i]), dp[i - 1, 0] * array[i]), Max( Max(dp[i - 1, 1] + array[i], dp[i - 1, 1] - array[i]), dp[i - 1, 1] * array[i])); dp[i, 1] = Min( Min( Min(dp[i - 1, 0] + array[i], dp[i - 1, 0] - array[i]), dp[i - 1, 0] * array[i]), Min( Min(dp[i - 1, 1] + array[i], dp[i - 1, 1] - array[i]), dp[i - 1, 1] * array[i])); } else { dp[i, 0] = Max( Max( Max(dp[i - 1, 0] + array[i], dp[i - 1, 0] - array[i]), Max(dp[i - 1, 0] * array[i], dp[i - 1, 0] / array[i])), Max( Max(dp[i - 1, 1] + array[i], dp[i - 1, 1] - array[i]), Max(dp[i - 1, 1] * array[i], dp[i - 1, 1] / array[i]))); dp[i, 1] = Min( Min( Min(dp[i - 1, 0] + array[i], dp[i - 1, 0] - array[i]), Min(dp[i - 1, 0] * array[i], dp[i - 1, 0] / array[i])), Min( Min(dp[i - 1, 1] + array[i], dp[i - 1, 1] - array[i]), Min(dp[i - 1, 1] * array[i], dp[i - 1, 1] / array[i]))); } } WriteLine(dp[n - 1, 0]); } private static string Read() { return ReadLine(); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }