結果

問題 No.165 四角で囲え!
ユーザー te-shte-sh
提出日時 2018-07-13 11:59:05
言語 D
(dmd 2.105.2)
結果
AC  
実行時間 846 ms / 5,000 ms
コード長 1,325 bytes
コンパイル時間 723 ms
コンパイル使用メモリ 109,156 KB
実行使用メモリ 6,424 KB
最終ジャッジ日時 2023-09-03 20:43:39
合計ジャッジ時間 10,315 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 446 ms
4,384 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 557 ms
4,440 KB
testcase_06 AC 117 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 322 ms
5,696 KB
testcase_12 AC 206 ms
5,960 KB
testcase_13 AC 134 ms
6,424 KB
testcase_14 AC 171 ms
5,896 KB
testcase_15 AC 180 ms
6,228 KB
testcase_16 AC 816 ms
4,700 KB
testcase_17 AC 823 ms
4,684 KB
testcase_18 AC 833 ms
5,692 KB
testcase_19 AC 846 ms
5,004 KB
testcase_20 AC 834 ms
4,648 KB
testcase_21 AC 834 ms
6,424 KB
testcase_22 AC 830 ms
4,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=rdsp;foreach(ref j;v.tupleof)pick(r,j);}}

void main()
{
  int n, b; readV(n, b);
  P[] p; readS(n, p);

  p.sort!"a.y<b.y";

  auto x = p.map!"a.x".array;
  int[int] zx;
  foreach (i, xi; x.sort().uniq.enumerate) zx[xi] = i.to!int;
  auto nx = zx.length.to!int;
  foreach (ref pi; p) pi.x = zx[pi.x];

  auto calc(P[] p)
  {
    auto n = p.length, s = 0;

    auto nextL(int l)
    {
      auto y = p[l].y;
      while (l < n && p[l].y == y) s -= p[l++].p;
      return l;
    }

    auto nextR(int r)
    {
      auto y = p[r].y;
      while (r < n && p[r].y == y) s += p[r++].p;
      return r;
    }

    auto l = 0, r = 0, c = 0;
    while (l < n) {
      while (s <= b) {
        c = max(c, r-l);
        if (r < n) r = nextR(r);
        else       break;
      }
      l = nextL(l);
    }

    return c;
  }

  auto r = 0;
  foreach (i; 0..nx)
    foreach (j; i..nx)
      r = max(r, calc(p.filter!(pi => i <= pi.x && pi.x <= j).array));

  writeln(r);
}

struct P { int x, y, p; }
0