結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 220 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 296 ms
4,376 KB
testcase_06 AC 64 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 145 ms
4,380 KB
testcase_12 AC 78 ms
4,380 KB
testcase_13 AC 79 ms
4,376 KB
testcase_14 AC 67 ms
4,380 KB
testcase_15 AC 67 ms
4,380 KB
testcase_16 AC 417 ms
4,380 KB
testcase_17 AC 391 ms
4,376 KB
testcase_18 AC 477 ms
4,376 KB
testcase_19 AC 411 ms
4,376 KB
testcase_20 AC 397 ms
4,380 KB
testcase_21 AC 394 ms
4,376 KB
testcase_22 AC 398 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.d(50): Deprecation: foreach: loop index implicitly converted from `size_t` to `int`
Main.d(51): 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 r = 0;
  foreach (x0; 0..nx)
    foreach (x1; x0..nx) {
      auto npi = new int[](ny), pti = new int[](ny);
      foreach (p; cpi)
        if (p.x >= x0 && p.x <= x1) {
          ++npi[p.y];
          pti[p.y] += p.pt;
        }

      auto cnpi = new int[](ny + 1);
      auto cpti = new int[](ny + 1);
      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