Submission #3271122


Source Code Expand

using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.D_Challenge
{
    class ABC_005
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var d = new int[n, n];
            string[] input;
            for (int i = 0; i < n; i++)
            {
                input = Console.ReadLine().Split(' ');
                for(int j = 0; j < n; j++)
                {
                    d[i, j] = int.Parse(input[j]);
                }
            }
            int q= int.Parse(Console.ReadLine());
            var p = new int[q];
            for(int i = 0; i < q; i++)
            {
                p[i] = int.Parse(Console.ReadLine());
            }

            //0からの距離に関するおいしさを計算
            var squareDel = new int[n, n];
            squareDel[0, 0] = d[0, 0];
            for(int i = 1; i < n; i++)
            {
                squareDel[i, 0] = squareDel[i - 1, 0] + d[i, 0];
                squareDel[0, i] = squareDel[0, i - 1] + d[0, i];
            }
            for(int i = 1; i < n; i++)
            {
                for(int j = 1; j < n; j++)
                {
                    squareDel[i, j] = d[i, j]
                        + squareDel[i - 1, j] + squareDel[i, j - 1]
                        - squareDel[i - 1, j - 1];
                }
            }

            var cntDel = new int[n * n];
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    for (int k = 1; k <= n - i; k++)
                    {
                        for (int l = 1; l <= n - j; l++)
                        {
                            int val = squareDel[i + k - 1, j + l - 1];
                            if (i > 0)
                            {
                                val -= squareDel[i - 1, j + l - 1];
                            }
                            if (j > 0)
                            {
                                val -= squareDel[i + k - 1, j - 1];
                            }
                            if (i > 0 && j > 0)
                            {
                                val += squareDel[i - 1, j - 1];
                            }
                            int square = k * l;
                            if (cntDel[square - 1] < val)
                            {
                                cntDel[square - 1] = val;
                            }
                        }
                    }
                }
            }

            for (int i = 1; i < n * n; i++)
            {
                if (cntDel[i] < cntDel[i - 1])
                {
                    cntDel[i] = cntDel[i - 1];
                }
            }


            for(int i = 0; i < q; i++)
            {
                Console.WriteLine(cntDel[p[i] - 1]);
            }
        }
    }
}

Submission Info

Submission Time
Task D - おいしいたこ焼きの焼き方
User MiuraMiuMiu
Language C# (Mono 4.6.2.0)
Score 100
Code Size 3159 Byte
Status AC
Exec Time 57 ms
Memory 13212 KB

Judge Result

Set Name Subtask1 Subtask2
Score / Max Score 50 / 50 50 / 50
Status
AC × 18
AC × 20
Set Name Test Cases
Subtask1 sub0.txt, sub1.txt, sub2.txt, sub_rand_max0.txt, sub_rand_max1.txt, sub_rand_max2.txt, sub_rand_max3.txt, sub_rand_min0.txt, s1.txt, s2.txt, sub0.txt, sub1.txt, sub2.txt, sub_rand_max0.txt, sub_rand_max1.txt, sub_rand_max2.txt, sub_rand_max3.txt, sub_rand_min0.txt
Subtask2 rand0.txt, rand1.txt, rand2.txt, rand3.txt, rand4.txt, rand_max0.txt, rand_max1.txt, rand_max2.txt, rand_max3.txt, rand_max4.txt, s1.txt, s2.txt, sub0.txt, sub1.txt, sub2.txt, sub_rand_max0.txt, sub_rand_max1.txt, sub_rand_max2.txt, sub_rand_max3.txt, sub_rand_min0.txt
Case Name Status Exec Time Memory
rand0.txt AC 34 ms 9044 KB
rand1.txt AC 32 ms 9044 KB
rand2.txt AC 41 ms 11092 KB
rand3.txt AC 24 ms 11092 KB
rand4.txt AC 20 ms 9044 KB
rand_max0.txt AC 57 ms 11164 KB
rand_max1.txt AC 57 ms 13212 KB
rand_max2.txt AC 57 ms 13212 KB
rand_max3.txt AC 56 ms 11164 KB
rand_max4.txt AC 56 ms 11164 KB
s1.txt AC 20 ms 9044 KB
s2.txt AC 20 ms 9044 KB
sub0.txt AC 20 ms 11092 KB
sub1.txt AC 20 ms 9044 KB
sub2.txt AC 21 ms 11092 KB
sub_rand_max0.txt AC 20 ms 11092 KB
sub_rand_max1.txt AC 20 ms 9044 KB
sub_rand_max2.txt AC 21 ms 9044 KB
sub_rand_max3.txt AC 21 ms 11092 KB
sub_rand_min0.txt AC 20 ms 9044 KB