結果
問題 | No.2520 L1 Explosion |
ユーザー | tnakao0123 |
提出日時 | 2024-06-19 23:18:51 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 108 ms / 2,000 ms |
コード長 | 3,104 bytes |
コンパイル時間 | 697 ms |
コンパイル使用メモリ | 50,304 KB |
実行使用メモリ | 62,592 KB |
最終ジャッジ日時 | 2024-06-19 23:18:55 |
合計ジャッジ時間 | 3,575 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 77 ms
62,592 KB |
testcase_07 | AC | 36 ms
27,904 KB |
testcase_08 | AC | 108 ms
58,240 KB |
testcase_09 | AC | 33 ms
50,432 KB |
testcase_10 | AC | 88 ms
58,624 KB |
testcase_11 | AC | 88 ms
59,008 KB |
testcase_12 | AC | 89 ms
58,880 KB |
testcase_13 | AC | 87 ms
57,856 KB |
testcase_14 | AC | 87 ms
57,984 KB |
testcase_15 | AC | 10 ms
9,216 KB |
testcase_16 | AC | 72 ms
49,664 KB |
testcase_17 | AC | 65 ms
39,168 KB |
testcase_18 | AC | 53 ms
40,192 KB |
testcase_19 | AC | 45 ms
35,456 KB |
testcase_20 | AC | 5 ms
6,400 KB |
testcase_21 | AC | 67 ms
49,152 KB |
testcase_22 | AC | 16 ms
13,440 KB |
testcase_23 | AC | 10 ms
9,984 KB |
testcase_24 | AC | 61 ms
45,312 KB |
ソースコード
/* -*- coding: utf-8 -*- * * 2520.cc: No.2520 L1 Explosion - yukicoder */ #include<cstdio> #include<algorithm> using namespace std; /* constant */ const int MAX_N = 1500; const int MAX_N2 = MAX_N * 2; const int MOD = 998244353; /* typedef */ using ll = long long; template<const int MOD> struct MI { int v; MI(): v() {} MI(int _v): v(_v % MOD) { if (v < 0) v += MOD; } MI(long long _v): v(_v % MOD) { if (v < 0) v += MOD; } explicit operator int() const { return v; } MI operator+(const MI m) const { return MI(v + m.v); } MI operator-(const MI m) const { return MI(v + MOD - m.v); } MI operator*(const MI m) const { return MI((long long)v * m.v); } MI &operator+=(const MI m) { return (*this = *this + m); } MI &operator-=(const MI m) { return (*this = *this - m); } MI &operator*=(const MI m) { return (*this = *this * m); } bool operator==(const MI m) const { return v == m.v; } bool operator!=(const MI m) const { return v != m.v; } MI pow(int n) const { // a^n % MOD MI pm = 1, a = *this; while (n > 0) { if (n & 1) pm *= a; a *= a; n >>= 1; } return pm; } MI inv() const { return pow(MOD - 2); } MI operator/(const MI m) const { return *this * m.inv(); } MI &operator/=(const MI m) { return (*this = *this / m); } }; using mi = MI<MOD>; /* global variables */ int xs[MAX_N], ys[MAX_N], hs[MAX_N]; ll uxs[MAX_N2], uys[MAX_N2]; int cs[MAX_N2][MAX_N2], css[MAX_N2 + 1][MAX_N2 + 1]; mi ss[MAX_N + 1]; /* subroutines */ /* main */ int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%d%d%d", xs + i, ys + i, hs + i); // let di=m-hi, // 1. (y-Yi)<=-(x-Xi)+di -> (x-Xi)+(y-Yi)<=di -> x+y<=Xi+Yi+di // 2. (y-Yi)>=-(x-Xi)-di -> (x-Xi)+(y-Yi)>=-di -> x+y>=Xi+Yi-di // 3. (y-Yi)<=(x-Xi)+di -> (x-Xi)-(y-Yi)>=-di -> x-y>=Xi-Yi-di // 4. (y-Yi)>=(x-Xi)-di -> (x-Xi)-(y-Yi)<=di -> x-y<=Xi-Yi+di int xn = 0, yn = 0; for (int i = 0; i < n; i++) { int di = m - hs[i]; uxs[xn++] = (ll)xs[i] + ys[i] - di; uxs[xn++] = (ll)xs[i] + ys[i] + di; uys[yn++] = (ll)xs[i] - ys[i] - di; uys[yn++] = (ll)xs[i] - ys[i] + di; } sort(uxs, uxs + xn); xn = unique(uxs, uxs + xn) - uxs; sort(uys, uys + yn); yn = unique(uys, uys + yn) - uys; for (int i = 0; i < n; i++) { int di = m - hs[i]; int xi0 = lower_bound(uxs, uxs + xn, (ll)xs[i] + ys[i] - di) - uxs; int xi1 = lower_bound(uxs, uxs + xn, (ll)xs[i] + ys[i] + di) - uxs; int yi0 = lower_bound(uys, uys + yn, (ll)xs[i] - ys[i] - di) - uys; int yi1 = lower_bound(uys, uys + yn, (ll)xs[i] - ys[i] + di) - uys; cs[yi0][xi0]++, cs[yi0][xi1]--; cs[yi1][xi0]--, cs[yi1][xi1]++; } for (int i = 0; i < yn; i++) for (int j = 0; j < xn; j++) { css[i + 1][j + 1] = cs[i][j] + css[i + 1][j] + css[i][j + 1] - css[i][j]; int cij = css[i + 1][j + 1]; if (cij > 0) ss[cij] += mi(uys[i + 1] - uys[i]) * (uxs[j + 1] - uxs[j]); } mi inv2 = mi(2).inv(); for (int i = 1; i <= n; i++) printf("%d\n", (int)(ss[i] * inv2)); return 0; }