結果
| 問題 | No.2520 L1 Explosion |
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2024-06-19 23:18:51 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 93 ms / 2,000 ms |
| コード長 | 3,104 bytes |
| 記録 | |
| コンパイル時間 | 702 ms |
| コンパイル使用メモリ | 46,720 KB |
| 最終ジャッジ日時 | 2025-02-21 23:24:05 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:71:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
71 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:73:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
73 | scanf("%d%d%d", xs + i, ys + i, hs + i);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
/* -*- 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;
}
tnakao0123