結果
問題 |
No.165 四角で囲え!
|
ユーザー |
|
提出日時 | 2018-07-13 11:59:05 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 781 ms / 5,000 ms |
コード長 | 1,325 bytes |
コンパイル時間 | 1,035 ms |
コンパイル使用メモリ | 122,688 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-13 01:29:25 |
合計ジャッジ時間 | 9,539 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 19 |
ソースコード
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; }