結果

問題 No.165 四角で囲え!
ユーザー sansaquasansaqua
提出日時 2019-08-07 01:27:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,380 bytes
コンパイル時間 970 ms
コンパイル使用メモリ 92,864 KB
実行使用メモリ 111,384 KB
最終ジャッジ日時 2023-09-25 18:18:00
合計ジャッジ時間 13,518 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}

ll n, b, sup, res;
vector<ll> xs, ys, ps, cache;
vector<vector<ll> > cumuls, exists;

template <class T> T get_2dcumul(const vector<vector<T> >& cumuls, long long y1, long long x1, long long y2, long long 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) {
    ll x, y, p;
    cin >> x >> y >> p;
    xs.push_back(x);
    ys.push_back(y);
    ps.push_back(p);
    cache.push_back(x);
    cache.push_back(y);
  }
  sort(cache.begin(), cache.end(), std::less<ll>());
  cache.erase(unique(cache.begin(), cache.end()), cache.end());

  REP (i, n) {
    xs[i] = lower_bound(cache.begin(), cache.end(), xs[i]) - cache.begin();
    ys[i] = lower_bound(cache.begin(), cache.end(), ys[i]) - cache.begin();
  }
  
  sup = cache.size();
  cumuls = vector<vector<ll> >(sup+1, vector<ll>(sup+1, 0));
  exists = vector<vector<ll> >(sup+1, vector<ll>(sup+1, 0));
  REP (i, n) {
    ll x = xs[i];
    ll 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;
  REP (y1, sup+1) {
    REP (x1, sup+1) {
      for (ll y2 = y1 + 1; y2 <= sup; y2++) {
        for (ll x2 = x1 + 1; x2 <= sup; x2++) {
          if (get_2dcumul(cumuls, y1, x1, y2, x2) <= b)
            res = max(res, get_2dcumul(exists, y1, x1, y2, x2));
        }
      }
    }
  }

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