예제 #1
0
        public static void Solve()
        {
            var N   = Scanner.Scan <int>();
            var cum = new CumulativeSum2D(1005, 1005);

            for (var i = 0; i < N; i++)
            {
                var(lx, ly, rx, ry) = Scanner.Scan <int, int, int, int>();
                cum.Add(lx, ly, 1);
                cum.Add(lx, ry, -1);
                cum.Add(rx, ly, -1);
                cum.Add(rx, ry, 1);
            }

            var count = new int[N + 1];

            for (var i = 0; i <= 1000; i++)
            {
                for (var j = 0; j <= 1000; j++)
                {
                    count[cum.Sum(i, j)]++;
                }
            }

            for (var i = 1; i <= N; i++)
            {
                Console.WriteLine(count[i]);
            }
        }
예제 #2
0
        public static void Solve()
        {
            var(H, W, K, V) = Scanner.Scan <int, int, long, long>();
            var cum = new CumulativeSum2D(H, W);

            for (var i = 0; i < H; i++)
            {
                var A = Scanner.ScanEnumerable <long>().ToArray();
                for (var j = 0; j < W; j++)
                {
                    cum.Set(i, j, A[j]);
                }
            }

            var answer = 0L;

            for (var i = 0; i < H; i++)
            {
                for (var j = 0; j < W; j++)
                {
                    for (var ii = i + 1; ii <= H; ii++)
                    {
                        for (var jj = j + 1; jj <= W; jj++)
                        {
                            var a = (ii - i) * (jj - j);
                            var v = cum.Sum(i, j, ii, jj) + a * K;
                            if (v <= V)
                            {
                                answer = Math.Max(answer, a);
                            }
                        }
                    }
                }
            }

            Console.WriteLine(answer);
        }
예제 #3
0
        public static void Solve()
        {
            var(H, W) = Scanner.Scan <int, int>();
            var G = new int[H][].Select(_ => Scanner.ScanEnumerable <int>().ToArray()).ToArray();

            var cum2d = new CumulativeSum2D(H, W);

            for (var i = 0; i < H; i++)
            {
                for (var j = 0; j < W; j++)
                {
                    cum2d.Set(i, j, G[i][j] * ((i + j) % 2 == 0 ? 1 : -1));
                }
            }

            var answer = 0L;

            for (var h1 = 1; h1 <= H; h1++)
            {
                for (var h2 = 0; h2 < h1; h2++)
                {
                    for (var w1 = 1; w1 <= W; w1++)
                    {
                        for (var w2 = 0; w2 < w1; w2++)
                        {
                            if (cum2d.Sum(h1, w1, h2, w2) == 0)
                            {
                                answer = Math.Max(answer, (h1 - h2) * (w1 - w2));
                            }
                        }
                    }
                }
            }

            Console.WriteLine(answer);
        }
예제 #4
0
        public static void Solve()
        {
            var(N, K) = Scanner.Scan <int, int>();
            const int max = 5000;
            var       cum = new CumulativeSum2D(max + 1, max + 1);

            for (var i = 0; i < N; i++)
            {
                var(a, b) = Scanner.Scan <int, int>();
                cum.Add(a, b, 1);
            }

            var answer = 0L;

            for (var i = 0; i + K < max; i++)
            {
                for (var j = 0; j + K < max; j++)
                {
                    answer = Math.Max(answer, cum.Sum(i, j, i + K + 1, j + K + 1));
                }
            }

            Console.WriteLine(answer);
        }
예제 #5
0
        public static void Solve()
        {
            var(N, K) = Scanner.Scan <int, int>();
            var G = new int[N][];

            for (var i = 0; i < N; i++)
            {
                G[i] = Scanner.ScanEnumerable <int>().ToArray();
            }

            var border = K * K / 2;

            bool Check(int m)
            {
                var cum = new CumulativeSum2D(N, N);

                for (var i = 0; i < N; i++)
                {
                    for (var j = 0; j < N; j++)
                    {
                        if (G[i][j] > m)
                        {
                            cum.Add(i, j, 1);
                        }
                    }
                }

                for (var i = 0; i < N - K + 1; i++)
                {
                    for (var j = 0; j < N - K + 1; j++)
                    {
                        if (cum.Sum(i, j, i + K, j + K) <= border)
                        {
                            return(true);
                        }
                    }
                }

                return(false);
            }

            const int inf = (int)1e9;

            var(l, r) = (-1, inf);
            while (r - l > 1)
            {
                var m = (l + r) / 2;
                if (Check(m))
                {
                    r = m;
                }
                else
                {
                    l = m;
                }
            }

            var answer = r;

            Console.WriteLine(answer);
        }