結果
| 問題 |
No.165 四角で囲え!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-09-13 17:34:56 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,288 bytes |
| コンパイル時間 | 1,110 ms |
| コンパイル使用メモリ | 132,568 KB |
| 実行使用メモリ | 9,504 KB |
| 最終ジャッジ日時 | 2024-06-12 04:20:29 |
| 合計ジャッジ時間 | 13,460 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 4 |
| other | TLE * 1 -- * 18 |
ソースコード
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;
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 pij = new int[][](h, w);
foreach (p; pi)
pij[hy[p[1]]][hx[p[0]]] = p[2];
auto maxC = 0;
foreach (i; 0..w)
foreach (j; i+1..w+1) {
auto ci = pij.map!(l => l[i..j].count!("a > 0").to!int);
auto qi = pij.map!(l => l[i..j].sum);
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;
}