結果

問題 No.165 四角で囲え!
ユーザー te-shte-sh
提出日時 2016-09-13 17:50:05
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,823 bytes
コンパイル時間 856 ms
コンパイル使用メモリ 119,520 KB
実行使用メモリ 4,748 KB
最終ジャッジ日時 2023-09-02 22:07:08
合計ジャッジ時間 26,012 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,835 ms
4,368 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 1 ms
4,368 KB
testcase_03 AC 1 ms
4,372 KB
testcase_04 AC 1 ms
4,368 KB
testcase_05 AC 2,953 ms
4,412 KB
testcase_06 AC 721 ms
4,372 KB
testcase_07 AC 2 ms
4,368 KB
testcase_08 AC 1 ms
4,368 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 1,112 ms
4,368 KB
testcase_12 AC 382 ms
4,368 KB
testcase_13 AC 507 ms
4,372 KB
testcase_14 AC 266 ms
4,368 KB
testcase_15 AC 270 ms
4,368 KB
testcase_16 AC 4,304 ms
4,748 KB
testcase_17 AC 3,857 ms
4,744 KB
testcase_18 TLE -
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;

class BiTree(T) {
  T[] b; // buffer
  size_t s; // size

  this(size_t t) {
    s = t;
    b = new int[](s + 1);
  }

  int get(size_t i) {
    if (!i) return 0;
    return b[i] + get(i - (i & -i));
  }

  void add(size_t i, T v) {
    if (i > s) return;
    b[i] += v;
    add(i + (i & -i), v);
  }
}

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 bitCi = new BiTree!int[](h);
  auto bitQi = new BiTree!int[](h);
  foreach (i; 0..h) {
    bitCi[i] = new BiTree!int(w);
    bitQi[i] = new BiTree!int(w);
  }

  foreach (p; pi) {
    bitCi[hy[p[1]]].add(hx[p[0]] + 1, 1);
    bitQi[hy[p[1]]].add(hx[p[0]] + 1, p[2]);
  }

  auto maxC = 0;
  foreach (i; 0..w-1)
    foreach (j; i..w) {
      auto ci = iota(h).map!(k => bitCi[k].get(j + 1) - bitCi[k].get(i));
      auto qi = iota(h).map!(k => bitQi[k].get(j + 1) - bitQi[k].get(i));

      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