結果

問題 No.440 2次元チワワ問題
ユーザー しらっ亭しらっ亭
提出日時 2016-10-31 04:54:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,997 bytes
コンパイル時間 2,031 ms
コンパイル使用メモリ 178,904 KB
実行使用メモリ 13,480 KB
最終ジャッジ日時 2023-08-16 11:33:08
合計ジャッジ時間 11,560 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 2 ms
4,384 KB
testcase_04 WA -
testcase_05 RE -
testcase_06 WA -
testcase_07 RE -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 WA -
testcase_16 AC 17 ms
4,384 KB
testcase_17 AC 254 ms
13,384 KB
testcase_18 AC 244 ms
13,332 KB
testcase_19 AC 247 ms
13,428 KB
testcase_20 AC 246 ms
13,360 KB
testcase_21 AC 1,216 ms
13,328 KB
testcase_22 AC 1,219 ms
13,480 KB
testcase_23 AC 1,216 ms
13,356 KB
testcase_24 AC 1,228 ms
13,368 KB
testcase_25 AC 1,222 ms
13,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define bit(n) (1LL<<(n))
#define sz(x) ((int)(x).size())
#define fst first
#define snd second
using ll=long long;using pii=pair<int,int>;using vb=vector<bool>;
using vi=vector<int>;using vvi=vector<vi>;using vvvi=vector<vvi>;
using vl=vector<ll>;using vvl=vector<vl>;using vvvl=vector<vvl>;
using vd=vector<double>;using vvd=vector<vd>;using vvvd=vector<vvd>;
using vpii=vector<pii>;using vvpii=vector<vpii>;using vvvpii=vector<vvpii>;
template <typename T> T read() {T t; cin >> t; return t;}

int H, W;

pii conv1(int y, int x, int rot) {
  if (rot == 0) return {y, x};
  if (rot == 1) return {W-x-1, y};
  if (rot == 2) return {H-y-1, W-x-1};
  if (rot == 3) return {x, H-y-1};
  assert(false);
};

pii conv2(int y, int x, int rot) {
  if (rot == 0) return {y, x};
  if (rot == 1) return {x, H-y-1};
  if (rot == 2) return {H-y-1, W-x-1};
  if (rot == 3) return {W-x-1, y};
  assert(false);
};

void Main() {
  H = read<int>();
  W = read<int>();
  vector<string> M(H);
  rep(i, H) M[i] = read<string>();
  int Q = read<int>();
  vi T(Q), L(Q), B(Q), R(Q);
  rep(i, Q) {
    T[i] = read<int>()-1;
    L[i] = read<int>()-1;
    B[i] = read<int>()-1;
    R[i] = read<int>()-1;
  }

  vl ans(Q);

  rep(rot, 4) {
    vvl c(H, vl(W+1)), w(H, vl(W+1)), cw(H, vl(W+1)), ww(H, vl(W+1)), cww(H, vl(W+1));

    auto get = [&](int y, int x) -> char {
      pii yx = conv1(y, x, rot);
      return M[yx.fst][yx.snd];
    };

    rep(y, H) rep(x, W) {
      c[y][x+1] = c[y][x];
      w[y][x+1] = w[y][x];
      cw[y][x+1] = cw[y][x];
      ww[y][x+1] = ww[y][x];
      cww[y][x+1] = cww[y][x];

      if (get(y, x) == 'c') {
        c[y][x+1]++;
      }
      else {
        w[y][x+1]++;
        cw[y][x+1] += c[y][x];
        ww[y][x+1] += w[y][x];
        cww[y][x+1] += cw[y][x];
      }
    }

    rep(q, Q) {
      int t = T[q];
      int l = L[q];
      int b = B[q];
      int r = R[q];
      {
        pii tl = conv2(t, l, rot);
        pii br = conv2(b, r, rot);
        t = min(tl.fst, br.fst);
        b = max(tl.fst, br.fst) + 1;
        l = min(tl.snd, br.snd);
        r = max(tl.snd, br.snd) + 1;
      }

      ll n = 0;
      rep(y, t, b) {
        n += cww[y][r] - cww[y][l]
            - cw[y][l] * (w[y][r] - w[y][l])
            - c[y][l] * (ww[y][r] - ww[y][l] - (w[y][l] * (w[y][r] - w[y][l])));
      }
      ans[q] += n;
    }
  }

  rep(q, Q) {
    cout << ans[q] << endl;
  }
}
int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Main(); return 0; }
0