Submission #588130


Source Code Expand

Copy
using System;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using StringBuilder = System.Text.StringBuilder;
using System.Numerics;
using Number = System.Int64;
namespace Program
{

    public class Solver
    {
        public void Solve()
        {
            var w = sc.Integer();
            var h = sc.Integer();
            var n = sc.Integer();
            var xs = new List<int>() { 0, w - 1 };
            var ys = new List<int>() { 0, h - 1 };
            var X = new int[n];
            var Y = new int[n];
            for (int i = 0; i < n; i++)
            {
                X[i] = sc.Integer() - 1;
                Y[i] = sc.Integer() - 1;
                for (int d = -1; d <= 1; d++)
                {
                    if (0 <= X[i] + d && X[i] + d <= w - 1)
                        xs.Add(X[i] + d);
                    if (0 <= Y[i] + d && Y[i] + d <= h - 1)
                        ys.Add(Y[i] + d);
                }
            }
            xs = xs.Distinct().ToList();
            ys = ys.Distinct().ToList();
            xs.Sort();
            ys.Sort();
            var dp = new long[xs.Count + 1, ys.Count + 1, xs.Count + 1, ys.Count + 1];
            for (int i = 0; i <= xs.Count; i++)
                for (int j = 0; j <= ys.Count; j++)
                    for (int k = 0; k <= xs.Count; k++)
                        for (int l = 0; l <= ys.Count; l++)
                            dp[i, j, k, l] = -1000000000;
            Func<int, int, int, int, long> dfs = null;
            dfs = (l, t, r, b) =>
            {
                if (l < 0 || t < 0 || r < 0 || b < 0) return 0;
                if (l >= xs.Count || t >= ys.Count || r >= xs.Count || b >= ys.Count) return 0;
                if (dp[l, t, r, b] >= 0) return dp[l, t, r, b];
                long max = 0;
                for (int i = 0; i < n; i++)
                {
                    var p = xs.BinarySearch(X[i]);
                    var q = ys.BinarySearch(Y[i]);
                    if (p < l || r < p) continue;
                    if (q < t || b < q) continue;
                    long val = (xs[r] - xs[l] + ys[b] - ys[t] + 1);
                    val += dfs(l, t, p - 1, q - 1);
                    val += dfs(p + 1, t, r, q - 1);
                    val += dfs(l, q + 1, p - 1, b);
                    val += dfs(p + 1, q + 1, r, b);
                    max = Math.Max(max, val);
                }
                return dp[l, t, r, b] = max;
            };
            IO.Printer.Out.WriteLine(dfs(0, 0, xs.Count - 1, ys.Count - 1));

        }
        public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());
        static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; }
        static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
    }
}

#region main
static class Ex
{
    static public string AsString(this IEnumerable<char> ie) { return new string(System.Linq.Enumerable.ToArray(ie)); }
    static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); }
    static public void Main()
    {
        var solver = new Program.Solver();
        solver.Solve();
        Program.IO.Printer.Out.Flush();
    }
}
#endregion
#region Ex
namespace Program.IO
{
    using System.IO;
    using System.Text;
    using System.Globalization;
    public class Printer : StreamWriter
    {
        static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; }
        public static Printer Out { get; set; }
        public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
        public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
        public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) { }
        public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); }
        public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); }
    }
    public class StreamScanner
    {
        public StreamScanner(Stream stream) { str = stream; }
        public readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }
        private byte read()
        {
            if (isEof) return 0;
            if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } }
            return buf[ptr++];
        }
        public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; }

        public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        public string ScanLine()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b != '\n'; b = (char)read())
                if (b == 0) break;
                else if (b != '\r') sb.Append(b);
            return sb.ToString();
        }
        public long Long()
        {
            if (isEof) return long.MinValue;
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != 0 && b != '-' && (b < '0' || '9' < b));
            if (b == 0) return long.MinValue;
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }
        public double Double() { var s = Scan(); return s != "" ? double.Parse(Scan(), CultureInfo.InvariantCulture) : double.NaN; }
        private T[] enumerate<T>(int n, Func<T> f)
        {
            var a = new T[n];
            for (int i = 0; i < n; ++i) a[i] = f();
            return a;
        }

        public char[] Char(int n) { return enumerate(n, Char); }
        public string[] Scan(int n) { return enumerate(n, Scan); }
        public double[] Double(int n) { return enumerate(n, Double); }
        public int[] Integer(int n) { return enumerate(n, Integer); }
        public long[] Long(int n) { return enumerate(n, Long); }
    }
}
#endregion

Submission Info

Submission Time
Task D - 金塊ゲーム
User camypaper
Language C# (Mono 2.10.8.1)
Score 99
Code Size 6807 Byte
Status
Exec Time 3250 ms
Memory 596008 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01.txt, sample_02.txt, sample_03.txt
Subtask1 80 / 80 subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_20.txt, subtask1_21.txt, subtask1_22.txt, subtask1_23.txt, subtask1_24.txt, subtask1_25.txt
Subtask2 19 / 19 subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_20.txt, subtask1_21.txt, subtask1_22.txt, subtask1_23.txt, subtask1_24.txt, subtask1_25.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt, subtask2_13.txt, subtask2_14.txt, subtask2_15.txt, subtask2_16.txt, subtask2_17.txt, subtask2_18.txt, subtask2_19.txt, subtask2_20.txt, subtask2_21.txt, subtask2_22.txt, subtask2_23.txt, subtask2_24.txt, subtask2_25.txt
Subtask3 0 / 1 subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_20.txt, subtask1_21.txt, subtask1_22.txt, subtask1_23.txt, subtask1_24.txt, subtask1_25.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt, subtask2_13.txt, subtask2_14.txt, subtask2_15.txt, subtask2_16.txt, subtask2_17.txt, subtask2_18.txt, subtask2_19.txt, subtask2_20.txt, subtask2_21.txt, subtask2_22.txt, subtask2_23.txt, subtask2_24.txt, subtask2_25.txt, subtask3_01.txt, subtask3_02.txt, subtask3_03.txt, subtask3_04.txt, subtask3_05.txt, subtask3_06.txt, subtask3_07.txt, subtask3_08.txt, subtask3_09.txt, subtask3_10.txt, subtask3_11.txt, subtask3_12.txt, subtask3_13.txt, subtask3_14.txt, subtask3_15.txt, subtask3_16.txt, subtask3_17.txt, subtask3_18.txt, subtask3_19.txt, subtask3_20.txt, subtask3_21.txt, subtask3_22.txt, subtask3_23.txt, subtask3_24.txt, subtask3_25.txt
Case Name Status Exec Time Memory
sample_01.txt 141 ms 10336 KB
sample_02.txt 144 ms 10348 KB
sample_03.txt 142 ms 10592 KB
subtask1_01.txt 142 ms 10332 KB
subtask1_02.txt 140 ms 10336 KB
subtask1_03.txt 141 ms 10460 KB
subtask1_04.txt 147 ms 11480 KB
subtask1_05.txt 142 ms 10460 KB
subtask1_06.txt 139 ms 10296 KB
subtask1_07.txt 140 ms 10680 KB
subtask1_08.txt 141 ms 10336 KB
subtask1_09.txt 144 ms 10828 KB
subtask1_10.txt 141 ms 10332 KB
subtask1_11.txt 149 ms 10696 KB
subtask1_12.txt 146 ms 10460 KB
subtask1_13.txt 148 ms 10584 KB
subtask1_14.txt 150 ms 11236 KB
subtask1_15.txt 156 ms 12896 KB
subtask1_16.txt 155 ms 12768 KB
subtask1_17.txt 148 ms 11356 KB
subtask1_18.txt 144 ms 10624 KB
subtask1_19.txt 140 ms 10336 KB
subtask1_20.txt 145 ms 10332 KB
subtask1_21.txt 158 ms 11744 KB
subtask1_22.txt 156 ms 11596 KB
subtask1_23.txt 154 ms 10596 KB
subtask1_24.txt 163 ms 12140 KB
subtask1_25.txt 157 ms 12628 KB
subtask2_01.txt 165 ms 13660 KB
subtask2_02.txt 164 ms 13020 KB
subtask2_03.txt 240 ms 26584 KB
subtask2_04.txt 312 ms 42456 KB
subtask2_05.txt 337 ms 46816 KB
subtask2_06.txt 315 ms 40792 KB
subtask2_07.txt 250 ms 25820 KB
subtask2_08.txt 238 ms 24280 KB
subtask2_09.txt 517 ms 76120 KB
subtask2_10.txt 733 ms 122204 KB
subtask2_11.txt 327 ms 35804 KB
subtask2_12.txt 801 ms 133476 KB
subtask2_13.txt 599 ms 95576 KB
subtask2_14.txt 729 ms 122200 KB
subtask2_15.txt 174 ms 15456 KB
subtask2_16.txt 260 ms 28388 KB
subtask2_17.txt 315 ms 31452 KB
subtask2_18.txt 594 ms 88012 KB
subtask2_19.txt 448 ms 59352 KB
subtask2_20.txt 499 ms 71764 KB
subtask2_21.txt 461 ms 63192 KB
subtask2_22.txt 652 ms 105180 KB
subtask2_23.txt 802 ms 129628 KB
subtask2_24.txt 937 ms 153616 KB
subtask2_25.txt 698 ms 108328 KB
subtask3_01.txt 188 ms 11876 KB
subtask3_02.txt 399 ms 51928 KB
subtask3_03.txt 219 ms 14928 KB
subtask3_04.txt 472 ms 74512 KB
subtask3_05.txt 907 ms 158556 KB
subtask3_06.txt 793 ms 133724 KB
subtask3_07.txt 391 ms 55192 KB
subtask3_08.txt 517 ms 72024 KB
subtask3_09.txt 1564 ms 300128 KB
subtask3_10.txt 748 ms 124180 KB
subtask3_11.txt 3250 ms 595928 KB
subtask3_12.txt 2883 ms 583496 KB
subtask3_13.txt 2901 ms 595920 KB
subtask3_14.txt 980 ms 172900 KB
subtask3_15.txt 1563 ms 296412 KB
subtask3_16.txt 787 ms 124124 KB
subtask3_17.txt 2918 ms 595936 KB
subtask3_18.txt 791 ms 142164 KB
subtask3_19.txt 2933 ms 595928 KB
subtask3_20.txt 461 ms 68700 KB
subtask3_21.txt 2983 ms 595968 KB
subtask3_22.txt 3042 ms 596008 KB
subtask3_23.txt 2992 ms 595936 KB
subtask3_24.txt 2906 ms 595936 KB
subtask3_25.txt 2971 ms 595928 KB