結果
問題 | No.165 四角で囲え! |
ユーザー | nebukuro09 |
提出日時 | 2017-01-05 16:47:59 |
言語 | D (dmd 2.106.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,875 bytes |
コンパイル時間 | 1,447 ms |
コンパイル使用メモリ | 124,288 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-12 06:15:41 |
合計ジャッジ時間 | 3,589 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | OLE | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
ソースコード
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, core.stdc.stdio, std.bitmanip; void main() { alias Tuple!(int, "x", int, "y", int, "p") Point; int N, B; Point[] p; scanf("%d %d", &N, &B); p = new Point[](N); foreach (i; 0..N) { int x, y, po; scanf("%d %d %d", &x, &y, &po); p[i] = Point(x, y, po); } p.sort!"a.x < b.x"(); int prev = p[0].x; p[0].x = 0; foreach (i; 1..N) { int cur = p[i].x; p[i].x = (p[i].x == prev) ? p[i-1].x : p[i-1].x + 1; prev = cur; } p.sort!"a.y < b.y"(); prev = p[0].y; p[0].y = 0; foreach (i; 1..N) { int cur = p[i].y; p[i].y = (p[i].y == prev) ? p[i-1].y : p[i-1].y + 1; prev = cur; } auto acm_score = new int[][](N+1, N+1); auto acm_exist = new int[][](N+1, N+1); foreach (i; 0..N) { acm_score[p[i].x+1][p[i].y+1] = p[i].p; acm_exist[p[i].x+1][p[i].y+1] = 1; } foreach (i; 0..N+1) { foreach (j; 0..N) { acm_score[i][j+1] += acm_score[i][j]; acm_exist[i][j+1] += acm_exist[i][j]; } } foreach (j; 0..N+1) { foreach (i; 0..N) { acm_score[i+1][j] += acm_score[i][j]; acm_exist[i+1][j] += acm_exist[i][j]; } } int hi = N*N+1; int lo = 0; while (hi - lo > 1) { int mid = (hi + lo) / 2; bool ok; a:foreach (h; 1..mid+1) { if (mid % h != 0) continue; int w = mid / h; foreach (i; 0..N-h+1) { foreach (j; 0..N-w+1) { if (acm_score[i+h][j+w] - acm_score[i+h][j] - acm_score[i][j+w] + acm_score[i][j] <= B) { ok = true; break a; } } } } if (ok) lo = mid; else hi = mid; } int ans = 0; foreach (h; 1..lo+1) { if (lo % h != 0) continue; int w = lo / h; foreach (i; 0..N-h+1) { foreach (j; 0..N-w+1) { writeln(h, " ", w, " ", i, " ", j); if (acm_score[i+h][j+w] - acm_score[i+h][j] - acm_score[i][j+w] + acm_score[i][j] <= B) { ans = max(ans, acm_exist[i+h][j+w] - acm_exist[i+h][j] - acm_exist[i][j+w] + acm_exist[i][j]); } } } } ans.writeln; }