結果

問題 No.2520 L1 Explosion
ユーザー SSRSSSRS
提出日時 2023-10-27 21:49:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 123 ms / 2,000 ms
コード長 1,880 bytes
コンパイル時間 2,406 ms
コンパイル使用メモリ 216,772 KB
実行使用メモリ 38,640 KB
最終ジャッジ日時 2023-10-27 21:49:41
合計ジャッジ時間 4,558 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 97 ms
38,640 KB
testcase_07 AC 31 ms
12,240 KB
testcase_08 AC 112 ms
38,640 KB
testcase_09 AC 56 ms
38,640 KB
testcase_10 AC 116 ms
38,640 KB
testcase_11 AC 116 ms
38,640 KB
testcase_12 AC 117 ms
38,640 KB
testcase_13 AC 117 ms
38,640 KB
testcase_14 AC 123 ms
38,640 KB
testcase_15 AC 6 ms
4,868 KB
testcase_16 AC 82 ms
28,608 KB
testcase_17 AC 52 ms
19,368 KB
testcase_18 AC 55 ms
19,896 KB
testcase_19 AC 44 ms
16,992 KB
testcase_20 AC 4 ms
4,348 KB
testcase_21 AC 79 ms
27,056 KB
testcase_22 AC 11 ms
6,252 KB
testcase_23 AC 7 ms
5,072 KB
testcase_24 AC 65 ms
23,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
const long long HALF = 499122177;
int main(){
  int N, M;
  cin >> N >> M;
  vector<long long> X(N), Y(N), H(N);
  for (int i = 0; i < N; i++){
    cin >> X[i] >> Y[i] >> H[i];
  }
  for (int i = 0; i < N; i++){
    tie(X[i], Y[i]) = make_pair(X[i] + Y[i], X[i] - Y[i]);
  }
  vector<long long> X2, Y2;
  for (int i = 0; i < N; i++){
    X2.push_back(X[i] - (M - H[i]));
    X2.push_back(X[i] + (M - H[i]));
    Y2.push_back(Y[i] - (M - H[i]));
    Y2.push_back(Y[i] + (M - H[i]));
  }
  sort(X2.begin(), X2.end());
  sort(Y2.begin(), Y2.end());
  X2.erase(unique(X2.begin(), X2.end()), X2.end());
  Y2.erase(unique(Y2.begin(), Y2.end()), Y2.end());
  int h = X2.size();
  int w = Y2.size();
  vector<vector<int>> imos(h, vector<int>(w, 0));
  for (int i = 0; i < N; i++){
    int x1 = lower_bound(X2.begin(), X2.end(), X[i] - (M - H[i])) - X2.begin();
    int x2 = lower_bound(X2.begin(), X2.end(), X[i] + (M - H[i])) - X2.begin();
    int y1 = lower_bound(Y2.begin(), Y2.end(), Y[i] - (M - H[i])) - Y2.begin();
    int y2 = lower_bound(Y2.begin(), Y2.end(), Y[i] + (M - H[i])) - Y2.begin();
    imos[x1][y1]++;
    imos[x1][y2]--;
    imos[x2][y1]--;
    imos[x2][y2]++;
  }
  for (int i = 0; i < h; i++){
    for (int j = 1; j < w; j++){
      imos[i][j] += imos[i][j - 1];
    }
  }
  for (int i = 1; i < h; i++){
    for (int j = 0; j < w; j++){
      imos[i][j] += imos[i - 1][j];
    }
  }
  vector<long long> ans(N + 1, 0);
  for (int i = 0; i < h - 1; i++){
    for (int j = 0; j < w - 1; j++){
      if (imos[i][j] > 0){
        long long dx = (X2[i + 1] - X2[i]) % MOD;
        long long dy = (Y2[j + 1] - Y2[j]) % MOD;
        ans[imos[i][j]] += dx * dy % MOD * HALF % MOD;
        ans[imos[i][j]] %= MOD;
      }
    }
  }
  for (int i = 1; i <= N; i++){
    cout << ans[i] << endl;
  }
}
0