結果
問題 | No.165 四角で囲え! |
ユーザー | やまぞう |
提出日時 | 2015-03-16 01:04:30 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 175 ms / 5,000 ms |
コード長 | 2,249 bytes |
コンパイル時間 | 1,267 ms |
コンパイル使用メモリ | 90,896 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-07 19:01:46 |
合計ジャッジ時間 | 3,003 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 66 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 98 ms
5,376 KB |
testcase_06 | AC | 20 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | AC | 1 ms
5,376 KB |
testcase_10 | AC | 1 ms
5,376 KB |
testcase_11 | AC | 36 ms
5,376 KB |
testcase_12 | AC | 13 ms
5,376 KB |
testcase_13 | AC | 14 ms
5,376 KB |
testcase_14 | AC | 11 ms
5,376 KB |
testcase_15 | AC | 8 ms
5,376 KB |
testcase_16 | AC | 134 ms
5,376 KB |
testcase_17 | AC | 90 ms
5,376 KB |
testcase_18 | AC | 175 ms
5,376 KB |
testcase_19 | AC | 118 ms
5,376 KB |
testcase_20 | AC | 95 ms
5,376 KB |
testcase_21 | AC | 97 ms
5,376 KB |
testcase_22 | AC | 95 ms
5,376 KB |
ソースコード
#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() + 1); } 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 + 1; 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(); 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) { if (count > best_count) { best_count = count; } 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++; } } } return best_count; } int main(int argc, char **argv) { input(cin); cout << resolve() << endl; return 0; }