結果
| 問題 | No.165 四角で囲え! |
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2019-06-21 17:25:52 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 260 ms / 5,000 ms |
| コード長 | 1,812 bytes |
| コンパイル時間 | 572 ms |
| コンパイル使用メモリ | 31,744 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-25 19:37:45 |
| 合計ジャッジ時間 | 3,755 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 19 |
コンパイルメッセージ
main.c: In function 'in':
main.c:8:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
8 | #define gc() getchar_unlocked()
| ^~~~~~~~~~~~~~~~
main.c:15:24: note: in expansion of macro 'gc'
15 | int n = 0, c = gc();
| ^~
ソースコード
// 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;
}
bal4u