結果
問題 | No.165 四角で囲え! |
ユーザー | やまぞう |
提出日時 | 2015-03-16 00:44:05 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,237 bytes |
コンパイル時間 | 1,137 ms |
コンパイル使用メモリ | 91,032 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-28 23:00:53 |
合計ジャッジ時間 | 2,506 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | WA | - |
testcase_05 | AC | 97 ms
5,376 KB |
testcase_06 | WA | - |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
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 | AC | 81 ms
5,376 KB |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | AC | 83 ms
5,376 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
ソースコード
#include <cstdint> #include <iostream> #include <vector> #include <map> #include <set> #include <algorithm> using namespace std; int N; int B; struct Point { Point() {} Point(int x, int y, int p) : x(x), y(y), p(p) {} int x; int y; int p; int ix; int iy; }; vector<Point> points; void input(istream& in) { in >> N >> B; points.resize(N); for (int i = 0; i < N; i++) { in >> points[i].x >> points[i].y >> points[i].p; } } int resolve() { map<int, vector<Point*>> Xmap; map<int, vector<Point*>> Ymap; for (int i = 0; i < N; i++) { Point &pt = points[i]; Xmap[pt.x].push_back(&pt); Ymap[pt.y].push_back(&pt); } vector<int> X; for (auto ite : Xmap) { X.push_back(ite.first); } map<int, int> X_to_index; int ix = 0; for (auto ite : X) { X_to_index[ite] = ix++; } vector<int> Y; for (auto ite : Ymap) { Y.push_back(ite.first); } map<int, int> Y_to_index; int iy = 0; for (auto ite : Y) { Y_to_index[ite] = iy++; } vector<vector<pair<int,int>>> sum_scores(Y.size()); for (size_t iy = 0; iy < Y.size(); iy++) { sum_scores[iy].resize(X.size()); } for (int i = 0; i < N; i++) { Point &pt = points[i]; pt.ix = X_to_index[pt.x]; pt.iy = Y_to_index[pt.y]; auto& sum_score = sum_scores[pt.iy]; for (size_t ix = pt.ix; ix < X.size(); ix++) { sum_score[ix].first++; sum_score[ix].second += pt.p; } } int best_count = 0; for (size_t ix1 = 0; ix1 < X.size()-1; ix1++) { for (size_t ix2 = ix1+1; ix2 < X.size(); ix2++) { size_t iy1 = 0; size_t iy2 = 0; int score = 0; int count = 0; while (iy1 < Y.size()) { while (iy2 < Y.size() && score <= B) { count += sum_scores[iy2][ix2].first - sum_scores[iy2][ix1].first; score += sum_scores[iy2][ix2].second - sum_scores[iy2][ix1].second; iy2++; } if (score <= B) { if (count > best_count) { best_count = count; } break; } count -= sum_scores[iy1][ix2].first - sum_scores[iy1][ix1].first; score -= sum_scores[iy1][ix2].second - sum_scores[iy1][ix1].second; iy1++; if (count > best_count) { best_count = count; } } } } return best_count; } int main(int argc, char **argv) { input(cin); cout << resolve() << endl; return 0; }