結果
問題 | No.165 四角で囲え! |
ユーザー | xuzijian629 |
提出日時 | 2018-10-10 19:16:05 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 351 ms / 5,000 ms |
コード長 | 2,408 bytes |
コンパイル時間 | 1,685 ms |
コンパイル使用メモリ | 179,288 KB |
実行使用メモリ | 16,128 KB |
最終ジャッジ日時 | 2024-10-12 17:19:08 |
合計ジャッジ時間 | 5,203 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 157 ms
11,520 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 1 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 203 ms
12,800 KB |
testcase_06 | AC | 53 ms
6,784 KB |
testcase_07 | AC | 1 ms
5,248 KB |
testcase_08 | AC | 1 ms
5,248 KB |
testcase_09 | AC | 1 ms
5,248 KB |
testcase_10 | AC | 2 ms
5,248 KB |
testcase_11 | AC | 96 ms
9,088 KB |
testcase_12 | AC | 44 ms
6,656 KB |
testcase_13 | AC | 46 ms
6,656 KB |
testcase_14 | AC | 33 ms
5,888 KB |
testcase_15 | AC | 34 ms
6,016 KB |
testcase_16 | AC | 279 ms
15,488 KB |
testcase_17 | AC | 239 ms
15,744 KB |
testcase_18 | AC | 351 ms
16,000 KB |
testcase_19 | AC | 264 ms
16,128 KB |
testcase_20 | AC | 247 ms
15,872 KB |
testcase_21 | AC | 248 ms
16,128 KB |
testcase_22 | AC | 247 ms
16,000 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using i64 = int64_t; using vi = vector<i64>; using vvi = vector<vi>; using ii = pair<int, i64>; map<i64, i64> compX, compY, extX, extY; map<ii, i64> point; vvi board, boardp; // all inclusive i64 pointsum(int i0, int i1, int j0, int j1) { i0++; i1++; j0++; j1++; return board[i1][j1] - board[i1][j0 - 1] - board[i0 - 1][j1] + board[i0 - 1][j0 - 1]; } i64 pointnum(int i0, int i1, int j0, int j1) { i0++; i1++; j0++; j1++; return boardp[i1][j1] - boardp[i1][j0 - 1] - boardp[i0 - 1][j1] + boardp[i0 - 1][j0 - 1]; } int main() { int n, b; cin >> n >> b; for (int i = 0; i < n; i++) { i64 x, y, p; cin >> x >> y >> p; compX[x] = compY[y] = 0; point[ii(x, y)] = p; } int k = 0; for (auto& p: compX) { p.second = k++; extX[p.second] = p.first; } k = 0; for (auto& p: compY) { p.second = k++; extY[p.second] = p.first; } int X = compX.size(), Y = compY.size(); board = vvi(X + 1, vi(Y + 1)); boardp = vvi(X + 1, vi(Y + 1)); for (int i = 0; i < X; i++) { for (int j = 0; j < Y; j++) { board[i + 1][j + 1] = point[ii(extX[i], extY[j])]; boardp[i + 1][j + 1] = point[ii(extX[i], extY[j])] > 0; } } for (int i = 0; i <= X; i++) { for (int j = 0; j < Y; j++) { board[i][j + 1] += board[i][j]; boardp[i][j + 1] += boardp[i][j]; } } for (int j = 0; j <= Y; j++) { for (int i = 0; i < X; i++) { board[i + 1][j] += board[i][j]; boardp[i + 1][j] += boardp[i][j]; } } i64 ans = 0; for (int i = 0; i < X; i++) { for (int j = i; j < X; j++) { i64 sum = 0; int l = 0, r = 0; while (1) { if (sum <= b) { sum += pointsum(i, j, r, r); if (sum <= b) { ans = max(ans, pointnum(i, j, l, r)); } r++; if (r == Y) { break; } } if (sum > b) { sum -= pointsum(i, j, l, l); l++; } } } } cout << ans << endl; }