結果

問題 No.165 四角で囲え!
ユーザー FF256grhyFF256grhy
提出日時 2017-07-05 09:40:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 142 ms / 5,000 ms
コード長 2,610 bytes
コンパイル時間 1,754 ms
コンパイル使用メモリ 158,332 KB
実行使用メモリ 4,804 KB
最終ジャッジ日時 2023-08-26 23:49:21
合計ジャッジ時間 3,901 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 91 ms
4,488 KB
testcase_06 AC 20 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 38 ms
4,384 KB
testcase_12 AC 17 ms
4,376 KB
testcase_13 AC 18 ms
4,376 KB
testcase_14 AC 14 ms
4,380 KB
testcase_15 AC 13 ms
4,380 KB
testcase_16 AC 126 ms
4,636 KB
testcase_17 AC 98 ms
4,664 KB
testcase_18 AC 142 ms
4,804 KB
testcase_19 AC 115 ms
4,588 KB
testcase_20 AC 101 ms
4,608 KB
testcase_21 AC 101 ms
4,612 KB
testcase_22 AC 101 ms
4,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, b, x[400], y[400], p[400];
vector<int> vx, vy;
map<int, int> mx, my;
int sn[401][401], sp[401][401];

int main() {
	cin >> n >> b;
	inc(i, n) { cin >> x[i] >> y[i] >> p[i]; }
	
	inc(i, n) { vx.PB(x[i]); }
	inc(i, n) { vy.PB(y[i]); }
	sort(ALL(vx)); int xs = unique(ALL(vx)) - vx.begin();
	sort(ALL(vy)); int ys = unique(ALL(vy)) - vy.begin();
	inc(i, xs) { mx[vx[i]] = i; }
	inc(i, ys) { my[vy[i]] = i; }
	inc(i, n) {
		sn[mx[x[i]] + 1][my[y[i]] + 1] = 1;
		sp[mx[x[i]] + 1][my[y[i]] + 1] = p[i];
	}
	
	inc1(i, xs) {
	inc1(j, ys) {
		sn[i][j] += sn[i - 1][j];
		sp[i][j] += sp[i - 1][j];
	}
	}
	inc1(i, xs) {
	inc1(j, ys) {
		sn[i][j] += sn[i][j - 1];
		sp[i][j] += sp[i][j - 1];
	}
	}
	
	int ans = 0;
	inc(i2, xs + 1) {
	inc(i1, i2    ) {
		int j1 = 0;
		inc(j2, ys + 1) {
			#define RN (sn[i2][j2] - sn[i1][j2] - sn[i2][j1] + sn[i1][j1])
			#define RP (sp[i2][j2] - sp[i1][j2] - sp[i2][j1] + sp[i1][j1])
			while(RP > b) { j1++; }
			if(j1 == j2) { continue; }
			setmax(ans, RN);
		}
	}
	}
	
	cout << ans << endl;
	
	return 0;
}
0