結果

問題 No.165 四角で囲え!
ユーザー bal4ubal4u
提出日時 2019-06-21 17:25:52
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 221 ms / 5,000 ms
コード長 1,812 bytes
コンパイル時間 1,315 ms
コンパイル使用メモリ 30,428 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-26 18:52:23
合計ジャッジ時間 3,284 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 0 ms
4,376 KB
testcase_05 AC 116 ms
4,376 KB
testcase_06 AC 26 ms
4,376 KB
testcase_07 AC 0 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 104 ms
4,376 KB
testcase_12 AC 146 ms
4,380 KB
testcase_13 AC 153 ms
4,380 KB
testcase_14 AC 143 ms
4,376 KB
testcase_15 AC 129 ms
4,380 KB
testcase_16 AC 170 ms
4,380 KB
testcase_17 AC 124 ms
4,380 KB
testcase_18 AC 221 ms
4,380 KB
testcase_19 AC 142 ms
4,380 KB
testcase_20 AC 124 ms
4,376 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:8:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    8 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:15:24: 備考: in expansion of macro ‘gc’
   15 |         int n = 0, c = gc();
      |                        ^~

ソースコード

diff #

// yukicoder: No.165 四角で囲え!
// 2019.6.21 bal4u

#include <stdio.h>
#include <stdlib.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in()   // 整数の入力(負数対応)
{
	int n = 0, c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

typedef struct { int x, y, p; } PP;
PP t[405];
int x[405], y[405];
int map[405][405], no[405][405];
int sum[405][405], cnt[405][405];
int N, B;
int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; }

int bsch(int *a, int x, int r) {
	int m, l = 0;

    while (l < r) {
        m = (l + r) >> 1;
		if (a[m] == x) return m;
        if (a[m] < x) l = m + 1; else r = m;
    }
	return l-1;
}

int main()
{
	int i, a, r, c, rr, cc, ans;

	N = in(), B = in();
	for (i = 0; i < N; i++) {
		t[i].x = x[i] = in(), t[i].y = y[i] = in(), t[i].p = in();
	}
	qsort(x, N, sizeof(int), cmp);
	qsort(y, N, sizeof(int), cmp);

	for (i = 0; i < N; i++) {
		c = bsch(x, t[i].x, N);
		r = bsch(y, t[i].y, N);
		map[r][c] = t[i].p, no[r][c] = 1;
	}

	for (r = 0; r < N; r++) for (c = 0; c < N; c++) {
        sum[r+1][c+1] = sum[r][c+1] + sum[r+1][c] - sum[r][c] + map[r][c];
		cnt[r+1][c+1] = cnt[r][c+1] + cnt[r+1][c] - cnt[r][c] + no[r][c];
	}

	ans = 0;
    for (r = 0; r < N; r++) for (rr = 1; rr <= N; rr++) {
		c = 0, cc = 1; while (cc <= N) {
			while (cc <= N && sum[rr][cc] - sum[r][cc] - sum[rr][c] + sum[r][c] <= B) {
				a = cnt[rr][cc] - cnt[r][cc] - cnt[rr][c] + cnt[r][c];
				if (a > ans) {
					ans = a;
					if (ans == N) goto done;
				}
				cc++;
			}
			while (c < cc && sum[rr][cc] - sum[r][cc] - sum[rr][c] + sum[r][c] > B) c++;
		}
    }
done:
	printf("%d\n", ans);
	return 0;
}
0