結果

問題 No.165 四角で囲え!
ユーザー te-shte-sh
提出日時 2016-09-13 17:34:56
言語 D
(dmd 2.106.1)
結果
TLE  
実行時間 -
コード長 1,288 bytes
コンパイル時間 926 ms
コンパイル使用メモリ 120,532 KB
実行使用メモリ 7,756 KB
最終ジャッジ日時 2023-09-02 22:06:22
合計ジャッジ時間 14,121 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

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 pij = new int[][](h, w);
  foreach (p; pi)
    pij[hy[p[1]]][hx[p[0]]] = p[2];

  auto maxC = 0;
  foreach (i; 0..w)
    foreach (j; i+1..w+1) {
      auto ci = pij.map!(l => l[i..j].count!("a > 0").to!int);
      auto qi = pij.map!(l => l[i..j].sum);

      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