結果
| 問題 |
No.440 2次元チワワ問題
|
| コンテスト | |
| ユーザー |
しらっ亭
|
| 提出日時 | 2016-10-31 04:50:36 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 3,051 bytes |
| コンパイル時間 | 2,023 ms |
| コンパイル使用メモリ | 182,172 KB |
| 実行使用メモリ | 13,568 KB |
| 最終ジャッジ日時 | 2024-11-24 23:57:20 |
| 合計ジャッジ時間 | 11,844 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 RE * 14 |
ソースコード
#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;}
void Main() {
int H = read<int>();
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 conv1= [&](int y, int x) -> pii {
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);
};
auto conv2= [&](int y, int x) -> pii {
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);
};
auto get = [&](int y, int x) {
pii yx = conv1(y, x);
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);
pii br = conv2(b, r);
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;
}
swap(H, W);
}
rep(q, Q) {
cout << ans[q] << endl;
}
}
int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Main(); return 0; }
しらっ亭