結果
問題 | No.440 2次元チワワ問題 |
ユーザー | yuki681 |
提出日時 | 2016-10-30 06:18:02 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 737 ms / 5,000 ms |
コード長 | 3,499 bytes |
コンパイル時間 | 1,336 ms |
コンパイル使用メモリ | 162,580 KB |
実行使用メモリ | 36,352 KB |
最終ジャッジ日時 | 2024-05-03 19:44:40 |
合計ジャッジ時間 | 7,818 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 5 ms
6,784 KB |
testcase_05 | AC | 4 ms
5,760 KB |
testcase_06 | AC | 3 ms
5,376 KB |
testcase_07 | AC | 25 ms
16,256 KB |
testcase_08 | AC | 52 ms
18,560 KB |
testcase_09 | AC | 109 ms
27,392 KB |
testcase_10 | AC | 29 ms
19,584 KB |
testcase_11 | AC | 30 ms
12,032 KB |
testcase_12 | AC | 35 ms
20,608 KB |
testcase_13 | AC | 94 ms
29,824 KB |
testcase_14 | AC | 9 ms
6,144 KB |
testcase_15 | AC | 100 ms
31,232 KB |
testcase_16 | AC | 23 ms
5,376 KB |
testcase_17 | AC | 150 ms
36,096 KB |
testcase_18 | AC | 152 ms
36,352 KB |
testcase_19 | AC | 153 ms
36,224 KB |
testcase_20 | AC | 152 ms
36,352 KB |
testcase_21 | AC | 737 ms
36,352 KB |
testcase_22 | AC | 729 ms
36,096 KB |
testcase_23 | AC | 735 ms
36,352 KB |
testcase_24 | AC | 727 ms
36,352 KB |
testcase_25 | AC | 728 ms
36,224 KB |
ソースコード
#include<bits/stdc++.h> #define int long long int using namespace std; int H, W, Q; char S[514][514]; int A[10010], B[10010], C[10010], D[10010]; int c[4][514][514], cw[4][514][514], cww[4][514][514], w[4][514][514]; int ans[10010]; signed main() { cin >> H >> W; for(int i = 1; i <= H; i++){ for(int j = 1; j <= W; j++){ cin >> S[i][j]; } } cin >> Q; for(int i = 1; i <= Q; i++){ cin >> A[i] >> B[i] >> C[i] >> D[i]; } for(int i = 1; i <= H; i++){ for(int j = 1; j <= W; j++){ if(S[i][j] == 'c'){ c[0][i][j] = c[0][i][j - 1] + 1; cw[0][i][j] = cw[0][i][j - 1]; cww[0][i][j] = cww[0][i][j - 1]; w[0][i][j] = w[0][i][j - 1]; } if(S[i][j] == 'w'){ c[0][i][j] = c[0][i][j - 1]; cw[0][i][j] = cw[0][i][j - 1] + c[0][i][j - 1]; cww[0][i][j] = cww[0][i][j - 1] + cw[0][i][j - 1]; w[0][i][j] = w[0][i][j - 1] + 1; } } } for(int i = 1; i <= Q; i++){ for(int j = A[i]; j <= C[i]; j++){ ans[i] += cww[0][j][D[i]] - cww[0][j][B[i] - 1] - cw[0][j][B[i] - 1] * (w[0][j][D[i]] - w[0][j][B[i] - 1]) - c[0][j][B[i] - 1] * ((w[0][j][D[i]] - w[0][j][B[i] - 1] - 1) * (w[0][j][D[i]] - w[0][j][B[i] - 1]) / 2); } } for(int i = 1; i <= H; i++){ for(int j = W; j >= 1; j--){ if(S[i][j] == 'c'){ c[1][i][j] = c[1][i][j + 1] + 1; cw[1][i][j] = cw[1][i][j + 1]; cww[1][i][j] = cww[1][i][j + 1]; w[1][i][j] = w[1][i][j + 1]; } if(S[i][j] == 'w'){ c[1][i][j] = c[1][i][j + 1]; cw[1][i][j] = cw[1][i][j + 1] + c[1][i][j + 1]; cww[1][i][j] = cww[1][i][j + 1] + cw[1][i][j + 1]; w[1][i][j] = w[1][i][j + 1] + 1; } } } for(int i = 1; i <= Q; i++){ for(int j = A[i]; j <= C[i]; j++){ ans[i] += cww[1][j][B[i]] - cww[1][j][D[i] + 1] - cw[1][j][D[i] + 1] * (w[1][j][B[i]] - w[1][j][D[i] + 1]) - c[1][j][D[i] + 1] * ((w[1][j][B[i]] - w[1][j][D[i] + 1] - 1) * (w[1][j][B[i]] - w[1][j][D[i] + 1]) / 2); } } for(int i = 1; i <= W; i++){ for(int j = 1; j <= H; j++){ if(S[j][i] == 'c'){ c[2][i][j] = c[2][i][j - 1] + 1; cw[2][i][j] = cw[2][i][j - 1]; cww[2][i][j] = cww[2][i][j - 1]; w[2][i][j] = w[2][i][j - 1]; } if(S[j][i] == 'w'){ c[2][i][j] = c[2][i][j - 1]; cw[2][i][j] = cw[2][i][j - 1] + c[2][i][j - 1]; cww[2][i][j] = cww[2][i][j - 1] + cw[2][i][j - 1]; w[2][i][j] = w[2][i][j - 1] + 1; } } } for(int i = 1; i <= Q; i++){ for(int j = B[i]; j <= D[i]; j++){ ans[i] += cww[2][j][C[i]] - cww[2][j][A[i] - 1] - cw[2][j][A[i] - 1] * (w[2][j][C[i]] - w[2][j][A[i] - 1]) - c[2][j][A[i] - 1] * ((w[2][j][C[i]] - w[2][j][A[i] - 1] - 1) * (w[2][j][C[i]] - w[2][j][A[i] - 1]) / 2); } } for(int i = 1; i <= W; i++){ for(int j = H; j >= 1; j--){ if(S[j][i] == 'c'){ c[3][i][j] = c[3][i][j + 1] + 1; cw[3][i][j] = cw[3][i][j + 1]; cww[3][i][j] = cww[3][i][j + 1]; w[3][i][j] = w[3][i][j + 1]; } if(S[j][i] == 'w'){ c[3][i][j] = c[3][i][j + 1]; cw[3][i][j] = cw[3][i][j + 1] + c[3][i][j + 1]; cww[3][i][j] = cww[3][i][j + 1] + cw[3][i][j + 1]; w[3][i][j] = w[3][i][j + 1] + 1; } } } for(int i = 1; i <= Q; i++){ for(int j = B[i]; j <= D[i]; j++){ ans[i] += cww[3][j][A[i]] - cww[3][j][C[i] + 1] - cw[3][j][C[i] + 1] * (w[3][j][A[i]] - w[3][j][C[i] + 1]) - c[3][j][C[i] + 1] * ((w[3][j][A[i]] - w[3][j][C[i] + 1] - 1) * (w[3][j][A[i]] - w[3][j][C[i] + 1]) / 2); } } for(int i = 1; i <= Q; i++){ cout << ans[i] << endl; } return 0; }