結果

問題 No.165 四角で囲え!
ユーザー sansaquasansaqua
提出日時 2019-08-07 02:47:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 799 ms / 5,000 ms
コード長 2,422 bytes
コンパイル時間 1,227 ms
コンパイル使用メモリ 98,304 KB
実行使用メモリ 8,716 KB
最終ジャッジ日時 2023-09-25 19:10:18
合計ジャッジ時間 7,917 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 321 ms
6,796 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 434 ms
7,172 KB
testcase_06 AC 105 ms
4,676 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 181 ms
5,744 KB
testcase_12 AC 74 ms
4,680 KB
testcase_13 AC 84 ms
4,792 KB
testcase_14 AC 14 ms
4,380 KB
testcase_15 AC 55 ms
4,504 KB
testcase_16 AC 600 ms
8,224 KB
testcase_17 AC 494 ms
8,348 KB
testcase_18 AC 799 ms
8,580 KB
testcase_19 AC 572 ms
8,716 KB
testcase_20 AC 523 ms
8,508 KB
testcase_21 AC 520 ms
8,464 KB
testcase_22 AC 520 ms
8,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <utility>
#include <set>
#include <list>
#include <cassert>
#include <queue>
#include <cmath>
#include <map>
#include <algorithm>

using namespace std;
using ll = long long int;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define YES(n) std::cout << ((n) ? "YES" : "NO"  ) << "\n";
#define Yes(n) std::cout << ((n) ? "Yes" : "No" ) << "\n";

#define ALL_INCLUDED_ENVIRONMENT

template <class T, class Alloc, template <class, class> class C> std::ostream& operator<<(std::ostream& o, const C<T, Alloc>& v) {
  o << "{";
  bool init = 1;
  for (auto e : v) {
    if (init) { init = 0; }
    else { o << ", "; }
    o << e;
  }
  o << "}";
  return o;
}

int n, b, sup, res;
vector<int> xs, ys, ps, table;
vector<vector<int> > cumuls, exists;

template <class T> inline T get_2dcumul(const vector<vector<T> >& cumuls, int y1, int x1, int y2, int x2) {
  return cumuls[y2][x2] - cumuls[y2][x1] - cumuls[y1][x2] + cumuls[y1][x1];
}

int main() {
  // cin.tie(0);
  // ios::sync_with_stdio(false);
  cin >> n >> b;
  REP (i, n) {
    int x, y, p;
    cin >> x >> y >> p;
    xs.push_back(x);
    ys.push_back(y);
    ps.push_back(p);
    table.push_back(x);
    table.push_back(y);
  }
  sort(table.begin(), table.end(), std::less<int>());
  table.erase(unique(table.begin(), table.end()), table.end());

  REP (i, n) {
    xs[i] = lower_bound(table.begin(), table.end(), xs[i]) - table.begin();
    ys[i] = lower_bound(table.begin(), table.end(), ys[i]) - table.begin();
  }
  
  sup = table.size();
  cumuls = vector<vector<int> >(sup+1, vector<int>(sup+1, 0));
  exists = vector<vector<int> >(sup+1, vector<int>(sup+1, 0));
  REP (i, n) {
    int x = xs[i];
    int y = ys[i];
    cumuls[y+1][x+1] += ps[i];
    exists[y+1][x+1] += 1;
  }
  REP (i, sup+1) {
    REP (j, sup) {
      cumuls[i][j+1] += cumuls[i][j];
      exists[i][j+1] += exists[i][j];
    }
  }
  REP (j, sup+1) {
    REP (i, sup) {
      cumuls[i+1][j] += cumuls[i][j];
      exists[i+1][j] += exists[i][j];
    }
  }

  res = 0;
  for (int y1 = 0; y1 <= sup; y1++) {
    for (int y2 = y1+1; y2 <= sup; y2++) {
      int x1 = 0;
      for (int x2 = 0; x2 <= sup; x2++) {
        while(get_2dcumul(cumuls, y1, x1, y2, x2) > b) {
          x1++;
        }
        res = max(res, get_2dcumul(exists, y1, x1, y2, x2));
      }
    }
  }

  cout << res << "\n";
  return 0;
}
0