結果

問題 No.165 四角で囲え!
ユーザー te-shte-sh
提出日時 2017-02-06 16:55:07
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 498 ms / 5,000 ms
コード長 1,511 bytes
コンパイル時間 778 ms
コンパイル使用メモリ 107,900 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-03 01:21:29
合計ジャッジ時間 5,955 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 213 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,388 KB
testcase_05 AC 290 ms
4,376 KB
testcase_06 AC 64 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 141 ms
4,380 KB
testcase_12 AC 75 ms
4,380 KB
testcase_13 AC 79 ms
4,380 KB
testcase_14 AC 63 ms
4,376 KB
testcase_15 AC 65 ms
4,384 KB
testcase_16 AC 414 ms
4,376 KB
testcase_17 AC 378 ms
4,380 KB
testcase_18 AC 498 ms
4,380 KB
testcase_19 AC 404 ms
4,384 KB
testcase_20 AC 384 ms
4,376 KB
testcase_21 AC 385 ms
4,376 KB
testcase_22 AC 386 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.d(52): Deprecation: foreach: loop index implicitly converted from `size_t` to `int`
Main.d(53): Deprecation: foreach: loop index implicitly converted from `size_t` to `int`

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.typecons;  // Tuple, Nullable, BigFlags

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

  auto rd3 = compress(pi), cpi = rd3[0], nx = rd3[1], ny = rd3[2];

  auto npi = new int[](ny), pti = new int[](ny);
  auto cnpi = new int[](ny + 1), cpti = new int[](ny + 1);

  auto r = 0;
  foreach (x0; 0..nx)
    foreach (x1; x0..nx) {
      npi[] = 0; pti[] = 0;
      foreach (p; cpi)
        if (p.x >= x0 && p.x <= x1) {
          ++npi[p.y];
          pti[p.y] += p.pt;
        }

      cnpi[0] = cpti[0] = 0;
      foreach (i; ny.iota) {
        cnpi[i + 1] = npi[i] + cnpi[i];
        cpti[i + 1] = pti[i] + cpti[i];
      }

      auto y0 = 0, y1 = 0;
      while (y1 < ny) {
        auto pt = cpti[y1 + 1] - cpti[y0];
        if (pt <= b) {
          auto np = cnpi[y1 + 1] - cnpi[y0];
          r = max(r, np);
          ++y1;
        } else {
          ++y0;
        }
      }
    }

  writeln(r);
}

auto compress(point[] pi)
{
  auto xi = pi.map!"a.x".array, yi = pi.map!"a.y".array;
  auto cxi = xi.sort().uniq.array, cyi = yi.sort().uniq.array;

  int[int] mx, my;
  foreach (int i, x; cxi) mx[x] = i;
  foreach (int i, y; cyi) my[y] = i;

  foreach (ref p; pi) {
    p.x = mx[p.x];
    p.y = my[p.y];
  }

  return tuple(pi, cxi.length, cyi.length);
}

struct point {
  int x, y, pt;
}
0