結果

問題 No.165 四角で囲え!
ユーザー FF256grhyFF256grhy
提出日時 2017-07-05 08:54:23
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,890 bytes
コンパイル時間 1,670 ms
コンパイル使用メモリ 173,060 KB
実行使用メモリ 12,580 KB
最終ジャッジ日時 2024-04-15 17:47:02
合計ジャッジ時間 23,420 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3,487 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 4,520 ms
6,940 KB
testcase_06 AC 418 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 1,562 ms
6,944 KB
testcase_12 AC 545 ms
6,944 KB
testcase_13 AC 490 ms
6,944 KB
testcase_14 AC 293 ms
6,940 KB
testcase_15 AC 372 ms
6,940 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

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 fn[400][400], fp[400][400];
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) {
		fn[mx[x[i]]][my[y[i]]] = 1;
		fp[mx[x[i]]][my[y[i]]] = p[i];
	}
	
	/*
	inc(i, xs + 1) {
	inc(j, ys + 1) {
		printf("%2d ", fn[i][j]);
	} cout << endl;
	} cout << endl;
	*/
	
	inc1(i, xs) {
	inc1(j, ys) {
		sn[i][j] = fn[i - 1][j - 1];
		sp[i][j] = fp[i - 1][j - 1];
	}
	}
	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];
	}
	}
	
	/*
	inc(i, xs + 1) {
	inc(j, ys + 1) {
		printf("%2d ", sn[i][j]);
	} cout << endl;
	} cout << endl;
	*/
	
	int ans = 0;
	inc(i2, xs + 1) {
	inc(j2, ys + 1) {
	inc(i1, i2) {
	inc(j1, j2) {
		int rn = sn[i2][j2] - sn[i1][j2] - sn[i2][j1] + sn[i1][j1];
		int rp = sp[i2][j2] - sp[i1][j2] - sp[i2][j1] + sp[i1][j1];
		if(rp <= b) { setmax(ans, rn); }
	}
	}
	}
	}
	
	cout << ans << endl;
	
	return 0;
}
0