Submission #588132


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 int[xs.Count, ys.Count, xs.Count, ys.Count];
            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, int> 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];
                var 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;
                    var 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 100
Code Size 6783 Byte
Status
Exec Time 2214 ms
Memory 291016 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 1 / 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 146 ms 10556 KB
sample_02.txt 142 ms 10556 KB
sample_03.txt 146 ms 10552 KB
subtask1_01.txt 141 ms 10552 KB
subtask1_02.txt 148 ms 10548 KB
subtask1_03.txt 144 ms 10548 KB
subtask1_04.txt 149 ms 10936 KB
subtask1_05.txt 142 ms 10552 KB
subtask1_06.txt 145 ms 10556 KB
subtask1_07.txt 145 ms 10672 KB
subtask1_08.txt 143 ms 10532 KB
subtask1_09.txt 160 ms 10684 KB
subtask1_10.txt 146 ms 10488 KB
subtask1_11.txt 143 ms 10680 KB
subtask1_12.txt 143 ms 10560 KB
subtask1_13.txt 144 ms 10684 KB
subtask1_14.txt 145 ms 10808 KB
subtask1_15.txt 152 ms 11584 KB
subtask1_16.txt 151 ms 11576 KB
subtask1_17.txt 146 ms 10968 KB
subtask1_18.txt 157 ms 10688 KB
subtask1_19.txt 143 ms 10548 KB
subtask1_20.txt 142 ms 10552 KB
subtask1_21.txt 151 ms 11068 KB
subtask1_22.txt 148 ms 10996 KB
subtask1_23.txt 145 ms 10672 KB
subtask1_24.txt 147 ms 11272 KB
subtask1_25.txt 151 ms 11540 KB
subtask2_01.txt 160 ms 11964 KB
subtask2_02.txt 155 ms 11580 KB
subtask2_03.txt 211 ms 17852 KB
subtask2_04.txt 266 ms 25144 KB
subtask2_05.txt 288 ms 27320 KB
subtask2_06.txt 281 ms 24416 KB
subtask2_07.txt 228 ms 17460 KB
subtask2_08.txt 221 ms 16700 KB
subtask2_09.txt 490 ms 41028 KB
subtask2_10.txt 587 ms 62900 KB
subtask2_11.txt 294 ms 22072 KB
subtask2_12.txt 623 ms 68284 KB
subtask2_13.txt 463 ms 50232 KB
subtask2_14.txt 553 ms 62868 KB
subtask2_15.txt 163 ms 12740 KB
subtask2_16.txt 240 ms 18616 KB
subtask2_17.txt 282 ms 20028 KB
subtask2_18.txt 488 ms 46624 KB
subtask2_19.txt 388 ms 33088 KB
subtask2_20.txt 477 ms 38964 KB
subtask2_21.txt 393 ms 34872 KB
subtask2_22.txt 532 ms 54844 KB
subtask2_23.txt 623 ms 66384 KB
subtask2_24.txt 705 ms 77884 KB
subtask2_25.txt 555 ms 56380 KB
subtask3_01.txt 150 ms 11164 KB
subtask3_02.txt 301 ms 29596 KB
subtask3_03.txt 161 ms 12472 KB
subtask3_04.txt 368 ms 40248 KB
subtask3_05.txt 663 ms 80308 KB
subtask3_06.txt 572 ms 68408 KB
subtask3_07.txt 305 ms 31164 KB
subtask3_08.txt 386 ms 38976 KB
subtask3_09.txt 1166 ms 148156 KB
subtask3_10.txt 586 ms 63532 KB
subtask3_11.txt 2172 ms 291008 KB
subtask3_12.txt 2186 ms 284824 KB
subtask3_13.txt 2175 ms 291016 KB
subtask3_14.txt 755 ms 86848 KB
subtask3_15.txt 1173 ms 146232 KB
subtask3_16.txt 591 ms 63548 KB
subtask3_17.txt 2153 ms 291000 KB
subtask3_18.txt 606 ms 72376 KB
subtask3_19.txt 2164 ms 291008 KB
subtask3_20.txt 371 ms 37308 KB
subtask3_21.txt 2214 ms 290992 KB
subtask3_22.txt 2200 ms 290908 KB
subtask3_23.txt 2181 ms 291012 KB
subtask3_24.txt 2170 ms 290996 KB
subtask3_25.txt 2176 ms 290908 KB