結果
問題 | No.165 四角で囲え! |
ユーザー | tu-sa |
提出日時 | 2018-07-11 04:32:51 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 7,424 bytes |
コンパイル時間 | 2,248 ms |
コンパイル使用メモリ | 190,212 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-14 13:51:14 |
合計ジャッジ時間 | 4,077 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | WA | - |
testcase_06 | AC | 19 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | WA | - |
testcase_11 | AC | 31 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 | 10 ms
5,376 KB |
testcase_16 | AC | 99 ms
5,376 KB |
testcase_17 | AC | 68 ms
5,376 KB |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
ソースコード
//////////////////////////////////////// /// tu3 pro-con template /// //////////////////////////////////////// #include "bits/stdc++.h" using namespace std; // -- loop macros -- // #define REP(i,n) for (int i = 0; i < (n); i++) #define RREP(i,n) for (int i = (n)-1; i >= 0; i--) #define FOR(i,s,n) for (int i = (int)(s); i < (n); i++) #define RFOR(i,s,n) for (int i = (n)-1; i >= (s); i--) #define FOREACH(i,container) for (auto &&i : container) #define allof(c) c.begin(), c.end() #define partof(c,i,n) c.begin() + (i), c.begin() + (i) + (n) // -- functors -- // #define PREDICATE(t,a,exp) [&](const t & a) -> bool { return exp; } #define COMPARISON(t,a,b,exp) [&](const t & a, const t & b) -> bool { return exp; } #define PRED(a,exp) [&](const auto & a) -> bool { return exp; } #define COMP(a,b,exp) [&](const auto & a, const auto & b) -> bool { return exp; } #define CONV1(a,exp) [&](const auto & a) -> auto { return exp; } #define CONV2(a,b,exp) [&](const auto & a, const auto & b) -> auto { return exp; } #define CONV3(a,b,c,exp) [&](const auto & a, const auto & b, const auto & c) -> auto { return exp; } // -- typedefs -- // #define EPS 1e-9 typedef unsigned int uint; typedef long long llong; typedef unsigned long long ullong; // -- I/O Helper -- // struct _Reader { _Reader(istream &cin) :cin(cin) {} istream &cin; template <class T> _Reader operator ,(T &rhs) { cin >> rhs; return *this; } }; struct _Writer { _Writer(ostream &cout) :cout(cout) {} ostream &cout; bool f{ false }; template <class T> _Writer operator ,(const T &rhs) { cout << (f ? " " : "") << rhs; f = true; return *this; } }; #define READ(t,...) t __VA_ARGS__; (_Reader{cin}), __VA_ARGS__ #define WRITE(...) (_Writer{cout}), __VA_ARGS__; cout << '\n' #define DEBUG(...) (_Writer{cerr}), __VA_ARGS__; cerr << '\n' // -- vevector -- // template <class T> struct vevector : public vector<vector<T>> { vevector(int n = 0, int m = 0, const T &initial = T()) : vector<vector<T>>(n, vector<T>(m, initial)) { } }; template <class T> struct vevevector : public vector<vevector<T>> { vevevector(int n = 0, int m = 0, int l = 0, const T &initial = T()) : vector<vevector<T>>(n, vevector<T>(m, l, initial)) { } }; template <class T> struct vevevevector : public vector<vevevector<T>> { vevevevector(int n = 0, int m = 0, int l = 0, int k = 0, const T &initial = T()) : vector<vevevector<T>>(n, vevevector<T>(m, l, k, initial)) { } }; namespace std { template <class T1, class T2> inline istream & operator >> (istream & in, pair<T1, T2> &p) { in >> p.first >> p.second; return in; } template <class T1, class T2> inline ostream & operator << (ostream &out, const pair<T1, T2> &p) { out << p.first << " " << p.second; return out; } } template <class T> T read() { T t; cin >> t; return t; } template <class T> vector<T> read(int n) { vector<T> v; REP(i, n) { v.push_back(read<T>()); } return v; } template <class T> vevector<T> read(int n, int m) { vevector<T> v; REP(i, n) v.push_back(read<T>(m)); return v; } template <class T> vector<T> readjag() { return read<T>(read<int>()); } template <class T> vevector<T> readjag(int n) { vevector<T> v; REP(i, n) v.push_back(readjag<T>()); return v; } template <class T> struct iter_pair_t { T beg, end; }; template <class T> iter_pair_t<T> iter_pair(T beg, T end) { return iter_pair_t<T>{beg, end}; } template <class T> ostream & operator << (ostream &out, const iter_pair_t<T> &v) { if (v.beg != v.end) { out << ++v.beg; while (v.beg != v.end) { out << " " << ++v.beg; } } return out; } template <class T1> ostream & operator << (ostream &out, const vector<T1> &v) { return out << iter_pair(begin(v), end(v)); } // -- etc -- // template <class T> T infinity_value(); #define DEFINE_INFINITY_VALUE(T, val) template <> constexpr T infinity_value<T>() { return (val); } DEFINE_INFINITY_VALUE(int, 1 << 28); DEFINE_INFINITY_VALUE(uint, 1u << 28); DEFINE_INFINITY_VALUE(llong, 1ll << 60); DEFINE_INFINITY_VALUE(ullong, 1ull << 60); DEFINE_INFINITY_VALUE(double, HUGE_VAL); DEFINE_INFINITY_VALUE(float, HUGE_VAL); #define INF(T) infinity_value<T>() inline int sign_of(double x) { return (abs(x) < EPS ? 0 : x > 0 ? 1 : -1); } template <class TInt> bool in_range(TInt val, TInt min, TInt max) { return val >= min && val < max; } template <> bool in_range<double>(double val, double min, double max) { return val - min > -EPS && val - max < EPS; } template <> bool in_range<float>(float val, float min, float max) { return val - min > -EPS && val - max < EPS; } template <class TInt> bool in_range2d(TInt x, TInt y, TInt w, TInt h) { return x >= 0 && x < w && y >= 0 && y < h; } vector<int> iotavn(int start, int count) { vector<int> r(count); iota(allof(r), start); return r; } //// start up //// void solve(); int main() { //// for local debugging //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); //auto classic_table = ctype<char>::classic_table(); //vector<ctype<char>::mask> ctable(classic_table, classic_table + ctype<char>::table_size); //ctable[':'] |= ctype_base::space; // as delimitor //ctable[','] |= ctype_base::space; // as delimitor //cin.imbue(locale(cin.getloc(), new ctype<char>(ctable.data()))); cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed; cout << setprecision(std::numeric_limits<double>::max_digits10); solve(); return 0; } /// 座圧 座標圧縮 template <class T> struct CoordinateCompression { map<T, int> comp{}; vector<T> decomp{}; vector<T> init(const vector<T> &orig) { decomp = orig; sort(allof(decomp)); decomp.erase(unique(allof(decomp)), decomp.end()); REP(i, decomp.size()) { comp[decomp[i]] = i; } vector<T> ret(orig.size()); REP(i, orig.size()) { ret[i] = comp[orig[i]]; } return ret; } size_t size() { return decomp.size(); } T operator[](int x) { return decomp[x]; } }; template <class T> struct CoordinateCompression2D { CoordinateCompression<T> Xs, Ys; template <class P> vector<P> init(const vector<P> &orig) { int N = orig.size(); vector<T> x(N); REP(i, N) { x[i] = orig[i].x; } x = Xs.init(x); vector<T> y(N); REP(i, N) { y[i] = orig[i].y; } y = Ys.init(y); vector<P> ret(N); REP(i, N) { ret[i] = { x[i], y[i] }; } return ret; } struct size2D { size_t x, y; }; size2D size() { return { Xs.size(), Ys.size() }; } template <class P> P operator[](P p) { return { Xs[p.x], Ys[p.y] }; } }; //////////////////// /// template end /// //////////////////// void solve() { READ(int, N, B); struct P { int x, y; }; vector<P> ps; vector<int> ss; REP(i, N) { READ(int, x, y, p); ps.push_back({ x, y }); ss.push_back(p); } N++; ps.push_back({ -INF(int), -INF(int) }); ss.push_back(0); CoordinateCompression2D<int> psx; ps = psx.init(ps); auto sz = psx.size(); vevector<int> scr(sz.x, sz.y), cnt(sz.x, sz.y); REP(i, N) { scr[ps[i].x][ps[i].y] += ss[i]; cnt[ps[i].x][ps[i].y] += 1; } REP(x, sz.x) FOR(y, 1, sz.y) { scr[x][y] += scr[x][y - 1]; cnt[x][y] += cnt[x][y - 1]; } REP(y, sz.y) FOR(x, 1, sz.x) { scr[x][y] += scr[x - 1][y]; cnt[x][y] += cnt[x - 1][y]; } int ans = 0; REP(s, sz.x) FOR(e, s, sz.x) { int l = 0, r = 0; while (r < sz.y) { int sc = scr[s][l] + scr[e][r] - scr[s][r] - scr[e][l]; int ct = cnt[s][l] + cnt[e][r] - cnt[s][r] - cnt[e][l]; if (sc <= B) { ans = max(ans, ct); } if (r > l && sc > B) { l++; } else { r++; } } } WRITE(ans); }