結果

問題 No.165 四角で囲え!
ユーザー te-shte-sh
提出日時 2016-09-14 11:24:06
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,523 bytes
コンパイル時間 955 ms
コンパイル使用メモリ 119,316 KB
実行使用メモリ 4,740 KB
最終ジャッジ日時 2023-09-02 22:07:35
合計ジャッジ時間 13,548 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 477 ms
4,372 KB
testcase_01 AC 1 ms
4,368 KB
testcase_02 AC 1 ms
4,368 KB
testcase_03 AC 1 ms
4,368 KB
testcase_04 AC 1 ms
4,368 KB
testcase_05 AC 892 ms
4,492 KB
testcase_06 AC 186 ms
4,368 KB
testcase_07 AC 2 ms
4,368 KB
testcase_08 AC 2 ms
4,372 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 268 ms
4,372 KB
testcase_12 AC 92 ms
4,368 KB
testcase_13 AC 120 ms
4,372 KB
testcase_14 AC 70 ms
4,372 KB
testcase_15 AC 66 ms
4,368 KB
testcase_16 AC 1,283 ms
4,700 KB
testcase_17 AC 1,108 ms
4,736 KB
testcase_18 AC 2,025 ms
4,740 KB
testcase_19 AC 1,170 ms
4,728 KB
testcase_20 AC 1,130 ms
4,672 KB
testcase_21 AC 1,104 ms
4,684 KB
testcase_22 AC 1,141 ms
4,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.regex, std.conv, std.stdio, std.typecons;

void main()
{
  auto rd = readln.split;
  auto n = rd[0].to!size_t, b = rd[1].to!int;
  auto pi = iota(n).map!(_ => readln.split.map!(to!int)).array;

  auto xi = pi.map!("a[0]").array;
  auto hx = compressMap(xi);
  auto w = hx.length;

  auto yi = pi.map!("a[1]").array;
  auto hy = compressMap(yi);
  auto h = hy.length;

  auto cij = new int[][](h, w);
  auto qij = new int[][](h, w);
  foreach (p; pi) {
    cij[hy[p[1]]][hx[p[0]]] = 1;
    qij[hy[p[1]]][hx[p[0]]] = p[2];
  }

  foreach (i; 0..h)
    foreach (j; 1..w) {
      cij[i][j] += cij[i][j - 1];
      qij[i][j] += qij[i][j - 1];
    }

  auto maxC = 0;
  foreach (i; 0..w-1)
    foreach (j; i..w) {
      auto ci = iota(h).map!(k => cij[k][j] - (i == 0 ? 0 : cij[k][i - 1]));
      auto qi = iota(h).map!(k => qij[k][j] - (i == 0 ? 0 : qij[k][i - 1]));

      auto k = 0, l = 0, sumC = 0, sumQ = 0;
      while (true) {
        ++l;
        if (l > h) break;
        sumC += ci[l - 1];
        sumQ += qi[l - 1];
        if (sumQ <= b)
          maxC = max(maxC, sumC);

        while (sumQ > b) {
          ++k;
          sumC -= ci[k - 1];
          sumQ -= qi[k - 1];
        }
      }
    }

  writeln(maxC);
}

int[int] compressMap(int[] pi)
{
  pi = pi.sort().array.uniq().array;
  int[int] h;
  foreach (i, p; pi) h[p] = i.to!int;
  return h;
}
0