結果

問題 No.2520 L1 Explosion
ユーザー MasKoaTSMasKoaTS
提出日時 2023-10-05 11:24:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 2,185 bytes
コンパイル時間 2,459 ms
コンパイル使用メモリ 211,532 KB
実行使用メモリ 73,812 KB
最終ジャッジ日時 2023-10-05 11:24:23
合計ジャッジ時間 5,299 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,504 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 107 ms
73,488 KB
testcase_07 AC 32 ms
20,680 KB
testcase_08 AC 114 ms
73,812 KB
testcase_09 AC 88 ms
73,540 KB
testcase_10 AC 115 ms
73,660 KB
testcase_11 AC 114 ms
73,664 KB
testcase_12 AC 116 ms
73,536 KB
testcase_13 AC 115 ms
73,532 KB
testcase_14 AC 114 ms
73,604 KB
testcase_15 AC 6 ms
5,376 KB
testcase_16 AC 101 ms
53,732 KB
testcase_17 AC 53 ms
34,940 KB
testcase_18 AC 59 ms
36,308 KB
testcase_19 AC 47 ms
30,236 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 77 ms
49,784 KB
testcase_22 AC 11 ms
8,340 KB
testcase_23 AC 7 ms
6,016 KB
testcase_24 AC 66 ms
42,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define MOD 998244353ll
using namespace std;
using ll = long long;

ll powmod(ll a, ll n){
    ll ret = 1;
    while(n){
        if (n & 1) {
            ret = ret * a % MOD;
        }
        a = a * a % MOD;
        n >>= 1;
    }
    return ret;
}
const ll INV2 = powmod(2, MOD - 2);

void set_XY(ll n, ll m, vector<ll>& X1, vector<ll>& Y1, vector<ll>& X2, vector<ll>& Y2, vector<ll>& X, vector<ll>& Y) {
    for(int i = 0; i < n; ++i){
        ll x, y, h;  cin >> x >> y >> h;
        ll d = m - h;
        ll x1 = (x - d) - y, y1 = (x - d) + y;
        X1.push_back(x1);  Y1.push_back(y1);
        X.push_back(x1);  Y.push_back(y1);
        ll x2 = (x + d) - y, y2 = (x + d) + y;
        X2.push_back(x2);  Y2.push_back(y2);
        X.push_back(x2);  Y.push_back(y2);
    }
    sort(all(X));    X.erase(unique(all(X)), X.end());
    sort(all(Y));    Y.erase(unique(all(Y)), Y.end());
}


int main(void) {
    ll n, m;  cin >> n >> m;
    vector<ll> X1 = {}, Y1 = {}, X2 = {}, Y2 = {}, X = {}, Y = {};
    set_XY(n, m, X1, Y1, X2, Y2, X, Y);

    int w = X.size(), h = Y.size();
    vector<vector<ll> > dp(w, vector<ll>(h));
    for(int i = 0; i < n; ++i){
        int x1 = lower_bound(all(X), X1[i]) - X.begin();
        int x2 = lower_bound(all(X), X2[i]) - X.begin();
        int y1 = lower_bound(all(Y), Y1[i]) - Y.begin();
        int y2 = lower_bound(all(Y), Y2[i]) - Y.begin();
        dp[x1][y1]++;  dp[x2][y1]--;  dp[x1][y2]--;  dp[x2][y2]++;
    }
    for(int i = 0; i < w; ++i){
        for(int j = 1; j < h; ++j){
            dp[i][j] += dp[i][j - 1];
        }
    }
    for(int i = 1; i < w; ++i){
        for(int j = 0; j < h; ++j){
            dp[i][j] += dp[i - 1][j];
        }
    }

    vector<ll> area(n + 1);
    for(int i = 0; i < w - 1; ++i){
        for(int j = 0; j < h - 1; ++j){
            if(dp[i][j] < 1){
                continue;
            }
            area[dp[i][j]] += ((X[i + 1] - X[i]) % MOD) * ((Y[j + 1] - Y[j]) % MOD) % MOD;
        }
    }
    
    for(int i = 1; i < n + 1; ++i){
        ll ans = area[i] % MOD * INV2 % MOD;
        cout << ans << endl;
    }

    return 0;
}
0