結果
問題 | No.440 2次元チワワ問題 |
ユーザー | pekempey |
提出日時 | 2016-10-29 01:56:20 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,599 bytes |
コンパイル時間 | 1,586 ms |
コンパイル使用メモリ | 163,548 KB |
実行使用メモリ | 12,288 KB |
最終ジャッジ日時 | 2024-11-24 07:05:30 |
合計ジャッジ時間 | 7,547 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
5,248 KB |
testcase_01 | AC | 3 ms
5,248 KB |
testcase_02 | WA | - |
testcase_03 | AC | 3 ms
5,248 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 | 8 ms
5,248 KB |
testcase_17 | AC | 115 ms
12,160 KB |
testcase_18 | AC | 112 ms
12,032 KB |
testcase_19 | AC | 114 ms
12,160 KB |
testcase_20 | AC | 110 ms
12,032 KB |
testcase_21 | AC | 853 ms
12,032 KB |
testcase_22 | AC | 854 ms
12,160 KB |
testcase_23 | AC | 862 ms
12,288 KB |
testcase_24 | AC | 867 ms
12,288 KB |
testcase_25 | AC | 869 ms
12,032 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]); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#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]); }