結果
| 問題 |
No.440 2次元チワワ問題
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-11-03 22:12:47 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 723 ms / 5,000 ms |
| コード長 | 2,217 bytes |
| コンパイル時間 | 1,621 ms |
| コンパイル使用メモリ | 186,236 KB |
| 実行使用メモリ | 12,028 KB |
| 最終ジャッジ日時 | 2024-11-25 02:28:01 |
| 合計ジャッジ時間 | 4,243 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
int H, W, Q;
vector<string> S, T;
typedef tuple<int, int, int, int> Query;
vector<Query> q, qs[501];
int sy, sx, ey, ex;
ll ans[10001], c[501][501], w[501][501], cw[501][501], cww[501][501];
void calc() {
rep(ii, 2) {
MEM(c, 0); MEM(w, 0); MEM(cw, 0); MEM(cww, 0);
rep(y, H) {
rep(x, W) {
c[y][x + 1] = c[y][x] + (S[y][x] == 'c');
w[y][x + 1] = w[y][x] + (S[y][x] == 'w');
cw[y][x + 1] = cw[y][x] + (S[y][x] == 'w' ? c[y][x] : 0);
cww[y][x + 1] = cww[y][x] + (S[y][x] == 'w' ? cw[y][x] : 0);
}
}
rep(i, Q) {
tie(sy, sx, ey, ex) = q[i];
FOR(y, sy, ey) {
ll wa = w[y][ex] - w[y][sx];
ll ww = wa*(wa - 1) / 2;
ans[i] += cww[y][ex] - cww[y][sx] - c[y][sx] * ww - cw[y][sx] * wa;
}
}
rep(y, H)reverse(all(S[y]));
rep(i, Q) {
tie(sy, sx, ey, ex) = q[i];
int t = W - sx;
sx = W - ex;
ex = t;
q[i] = tie(sy, sx, ey, ex);
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> H >> W;
S.resize(H);
rep(y, H)cin >> S[y];
cin >> Q;
q.resize(Q);
rep(i, Q) {
cin >> sy >> sx >> ey >> ex;
--sy; --sx;
q[i] = make_tuple(sy, sx, ey, ex);
}
T = vector<string>(W, string(H, ' '));
rep(y, H)rep(x, W)T[x][y] = S[y][x];
calc();
S = T;
swap(W, H);
rep(i, Q) {
tie(sy, sx, ey, ex) = q[i];
swap(sy, sx); swap(ey, ex);
q[i] = tie(sy, sx, ey, ex);
}
calc();
rep(i, Q)cout << ans[i] << endl;
}