Submission #5067948


Source Code Expand

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    class Program
    {
        static void Main()
        {
            Console.WriteLine(new Program().Calc());
        }

        public object Calc()
        {
            ReadLine();
            var yamaA = ReadLineSplitInt32();
            var yamaB = ReadLineSplitInt32();

            var dp = new int[yamaA.Length + 3, yamaB.Length + 3];
            var which = new bool[yamaA.Length + 1, yamaB.Length + 1]; // Aから取るのが良いとtrue, Bから取るのが良いとfalse

            dp[yamaA.Length, yamaB.Length - 1] = yamaB[yamaB.Length - 1];
            dp[yamaA.Length - 1, yamaB.Length] = yamaA[yamaA.Length - 1];
            which[yamaA.Length - 1, yamaB.Length] = true;
            which[yamaA.Length, yamaB.Length - 1] = false;

            for (int i = yamaA.Length - 2; i >= 0; i--)
            {
                dp[i, yamaB.Length] = yamaA[i] + dp[i + 2, yamaB.Length];
                which[i, yamaB.Length] = true;
            }
            for (int i = yamaB.Length - 2; i >= 0; i--)
            {
                dp[yamaA.Length, i] = yamaB[i] + dp[yamaA.Length, i + 2];
                which[yamaA.Length, i] = false;
            }
            for (int i = yamaA.Length - 1; i >= 0; i--)
            {
                for (int j = yamaB.Length - 1; j >= 0; j--)
                {
                    var oldA = which[i + 1, j] ? dp[i + 2, j] : dp[i + 1, j + 1];
                    var a = yamaA[i] + oldA;
                    var oldB = which[i, j + 1] ? dp[i + 1, j + 1] : dp[i, j + 2];
                    var b = yamaB[j] + oldB;

                    if (which[i, j] = a > b)
                        dp[i, j] = a;
                    else
                        dp[i, j] = b;
                }
            }
            return dp[0, 0];
        }

#if DEBUG
#pragma warning disable IDE0051 // 使用されていないプライベート メンバーを削除する
#pragma warning disable IDE1006 // 命名スタイル
        static string _ReadLineImpl() => queue.Dequeue();
#pragma warning restore IDE1006 // 命名スタイル
        static readonly Queue<string> queue;
        static Program()
        {
            string input = @"
5 5
2 4 5 4 2
2 8 3 4 5
";
            queue = new Queue<string>();
            foreach (var line in input.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries))
                queue.Enqueue(line);
        }
#else
        private static string _ReadLineImpl() => Console.ReadLine();
#endif
        static string ReadLine() => _ReadLineImpl();
        static int ReadLineInt32() => int.Parse(ReadLine());
        static long ReadLineInt64() => long.Parse(ReadLine());
        static ulong ReadLineUInt64() => ulong.Parse(ReadLine());
        static double ReadLineDouble() => double.Parse(ReadLine());
        static string[] ReadLineSplit() => ReadLine().Split().ToArray();
        static int[] ReadLineSplitInt32() => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        static long[] ReadLineSplitInt64() => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        static ulong[] ReadLineSplitUInt64() => ReadLine().Split().Select(s => ulong.Parse(s)).ToArray();
        static double[] ReadLineSplitDouble() => ReadLine().Split().Select(s => double.Parse(s)).ToArray();

        static IEnumerable<string> RepeatReadLines(int count)
        {
            for (int i = 0; i < count; i++)
                yield return ReadLine();
        }
        static IEnumerable<int> RepeatReadLinesInt32(int count)
        {
            for (int i = 0; i < count; i++)
                yield return ReadLineInt32();
        }
        static IEnumerable<string[]> RepeatReadLinesSplit(int count)
        {
            for (int i = 0; i < count; i++)
                yield return ReadLineSplit();
        }
    }
    static class BitArrayUtils
    {
        static BitArray ToBitArray(this long l)
        {
            return new BitArray(BitConverter.GetBytes(l));
        }
        static long ToInt64(this BitArray bitArray)
        {
            var array = new byte[8];
            bitArray.CopyTo(array, 0);
            return BitConverter.ToInt64(array, 0);
        }
        static BitArray ToBitArray(this ulong l)
        {
            return new BitArray(BitConverter.GetBytes(l));
        }
        static ulong ToUInt64(this BitArray bitArray)
        {
            var array = new byte[8];
            bitArray.CopyTo(array, 0);
            return BitConverter.ToUInt64(array, 0);
        }
    }
}

Submission Info

Submission Time
Task B - ゲーム
User kzrnm
Language C# (Mono 4.6.2.0)
Score 3
Code Size 4885 Byte
Status AC
Exec Time 48 ms
Memory 18016 KB

Judge Result

Set Name All
Score / Max Score 3 / 3
Status
AC × 5
Set Name Test Cases
All 00, 01, 02, 90, 91
Case Name Status Exec Time Memory
00 AC 24 ms 11348 KB
01 AC 40 ms 14432 KB
02 AC 48 ms 18016 KB
90 AC 24 ms 11348 KB
91 AC 24 ms 11348 KB