結果

問題 No.60 魔法少女
ユーザー nanasilinanasili
提出日時 2014-11-09 23:50:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 241 ms / 5,000 ms
コード長 1,824 bytes
コンパイル時間 635 ms
コンパイル使用メモリ 78,912 KB
実行使用メモリ 144,820 KB
最終ジャッジ日時 2023-08-30 02:52:07
合計ジャッジ時間 3,485 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
144,064 KB
testcase_01 AC 38 ms
143,928 KB
testcase_02 AC 38 ms
143,956 KB
testcase_03 AC 45 ms
143,904 KB
testcase_04 AC 151 ms
144,068 KB
testcase_05 AC 164 ms
144,780 KB
testcase_06 AC 231 ms
144,676 KB
testcase_07 AC 185 ms
144,820 KB
testcase_08 AC 136 ms
144,384 KB
testcase_09 AC 88 ms
144,116 KB
testcase_10 AC 220 ms
144,680 KB
testcase_11 AC 67 ms
144,152 KB
testcase_12 AC 128 ms
144,744 KB
testcase_13 AC 241 ms
144,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <string>
#include <cstring>

using namespace std;

typedef long long ll;

ll field[3000][3000];
ll memo[3000][3000];

int main() {
  int bias = 1000;
  memset(field, 0, sizeof(field));
  memset(memo, 0, sizeof(memo));
  ll n, k;
  cin >> n >> k;
  vector <pair<int, int> > vpii;
  for (int i = 0; i < n; i++) {
    int x, y, h;
    cin >> x >> y >> h;
    x += bias; y += bias;
    field[x][y] = h;
    vpii.push_back(make_pair(x, y));
  }
  int minx, miny, maxx, maxy;
  minx = miny = 1e9;
  maxx = maxy = -1e9;
  for (int i = 0; i < k; i++) {
    int ax, ay, w, h, d;
    cin >> ax >> ay >> w >> h >> d;
    ax += bias; ay += bias;
    memo[ax][ay] += d;
    memo[ax+w+1][ay] -= d;
    memo[ax][ay+h+1] -= d;
    memo[ax+w+1][ay+h+1] += d;
    minx = min(minx, ax);
    miny = min(miny, ay);
    maxx = max(maxx, ax+w+1);
    maxy = max(maxy, ay+h+1);
  }

  for (int i = minx+1; i <= maxx; i++) {
    for (int j = miny; j <= maxy; j++) {
      memo[i][j] += memo[i-1][j];
    }
  }

  for (int i = miny+1; i <= maxy; i++) {
    for (int j = minx; j <= maxx; j++) {
      memo[j][i] += memo[j][i-1];
    }
  }

  // for (int i = miny; i <= maxy; i++) {
  //   for (int j = minx; j <= maxx; j++) {
  //     cout << memo[j][i];
  //   }
  //   cout << endl;
  // }


  ll ans = 0;
  for (int i = 0; i < vpii.size(); i++) {
    int px = vpii[i].first, py = vpii[i].second;
    if (field[px][py]-memo[px][py] > 0) ans += ll(field[px][py]-memo[px][py]);
  }

  cout << ans << endl;
}
0