結果

問題 No.440 2次元チワワ問題
ユーザー pekempeypekempey
提出日時 2016-10-29 01:56:20
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,599 bytes
コンパイル時間 1,214 ms
コンパイル使用メモリ 165,340 KB
実行使用メモリ 12,332 KB
最終ジャッジ日時 2024-05-03 08:37:14
合計ジャッジ時間 2,994 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
10,192 KB
testcase_01 AC 3 ms
10,196 KB
testcase_02 WA -
testcase_03 AC 4 ms
10,320 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 7 ms
10,536 KB
testcase_17 AC 86 ms
12,220 KB
testcase_18 AC 82 ms
12,204 KB
testcase_19 AC 75 ms
12,204 KB
testcase_20 AC 74 ms
12,204 KB
testcase_21 AC 79 ms
12,204 KB
testcase_22 AC 86 ms
12,272 KB
testcase_23 AC 81 ms
12,208 KB
testcase_24 AC 86 ms
12,332 KB
testcase_25 AC 80 ms
12,332 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:26:42: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   26 |         for (int i = 0; i < h; i++) scanf("%s", s[i]);
      |                                     ~~~~~^~~~~~~~~~~~
main.cpp:32:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   32 |                 scanf("%d %d %d %d", &y1[i], &x1[i], &y2[i], &x2[i]);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

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

int h, w, q;
char s[501][501], ss[501][501];
long long c[501][501], cw[501][501], cww[501][501], www[501][501];

long long C(long long n) {
	return n * (n - 1) / 2;
}

void calc() {
	for (int i = 0; i < h; i++) {
		c[i][0] = cw[i][0] = cww[i][0] = www[i][0] = 0;
		for (int j = 0; j < w; j++) {
			c[i][j + 1] = c[i][j] + (s[i][j] == 'c');
			cw[i][j + 1] = cw[i][j] + (s[i][j] == 'w' ? c[i][j] : 0);
			cww[i][j + 1] = cww[i][j] + (s[i][j] == 'w' ? cw[i][j] : 0);
			www[i][j + 1] = www[i][j] + (s[i][j] == 'w');
		}
	}
}

int main() {
	cin >> h >> w;
	for (int i = 0; i < h; i++) scanf("%s", s[i]);
	cin >> q;

	vector<int> y1(q), x1(q), y2(q), x2(q);
	vector<long long> ans(q);
	for (int i = 0; i < q; i++) {
		scanf("%d %d %d %d", &y1[i], &x1[i], &y2[i], &x2[i]);
		y1[i]--; x1[i]--; y2[i]--; x2[i]--;
	}

	for (int tmp = 0; tmp < 2; tmp++) {
		for (int tmp2 = 0; tmp2 < 2; tmp2++) {
			calc();
			for (int ii = 0; ii < q; ii++) {
				int L = x1[ii], R = x2[ii] + 1;
				for (int i = y1[ii]; i <= y2[ii]; i++) {
					long long W = www[i][R] - www[i][L];
					ans[ii] += cww[i][R] - cww[i][L] - c[i][L] * C(W) - cw[i][L] * W;
				}
			}
			for (int i = 0; i < h; i++) reverse(s[i], s[i] + w);
			for (int i = 0; i < q; i++) {
				x1[i] = w - 1 - x1[i];
				x2[i] = w - 1 - x2[i];
				swap(x1[i], x2[i]);
			}
		}
		for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) ss[i][j] = s[j][i];
		swap(s, ss);
		swap(h, w);
		for (int i = 0; i < q; i++) swap(y1[i], x1[i]), swap(y2[i], x2[i]);
	}
	for (int i = 0; i < q; i++) printf("%lld\n", ans[i]);
}
0