Submission #3981678


Source Code Expand

#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
long long solve(vector<string> S) {
	int H = S.size(), W = S[0].size();
	long long ans = 0;
	for (int i = 0; i <= H + W - 2; ++i) {
		for (int j = i + 2; j <= H + W - 2; j += 2) {
			int B = (j - i) / 2;
			for (int k = 0; k < H - B; ++k) {
				if (i - k >= W || i - k - B < 0 || S[k][i - k] == '.' || S[k + B][i - k - B] == '.') continue;
				int llim = max(k + B, j - W + 1);
				int rlim = min({ k + 2 * B, H - 1, j }) + 1;
				for (int l = llim; l < rlim; ++l) {
					ans += (S[l][j - l] == '#' ? 1 : 0) * 2;
				}
				ans -= (0 <= j - (k + B) && j - (k + B) < W && S[k + B][j - (k + B)] == '#' ? 1 : 0);
				ans -= (k + 2 * B < H && 0 <= j - (k + 2 * B) && j - (k + 2 * B) < W && S[k + 2 * B][j - (k + 2 * B)] == '#' ? 1 : 0);
			}
		}
	}
	return ans;
}
vector<string> rotate(vector<string> S) {
	int H = S.size(), W = S[0].size();
	vector<string> ans(W, string(H, '?'));
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			ans[j][H - i - 1] = S[i][j];
		}
	}
	return ans;
}
int main() {
	int H, W;
	cin >> H >> W;
	vector<string> S(H);
	for (int i = 0; i < H; ++i) {
		cin >> S[i];
	}
	long long ans = 0;
	for (int i = 0; i < 4; ++i) {
		ans += solve(S);
		S = rotate(S);
	}
	cout << ans / 2 << endl;
	return 0;
}

Submission Info

Submission Time
Task E - Equilateral
User square1001
Language C++14 (Clang 3.8.0)
Score 0
Code Size 1380 Byte
Status TLE
Exec Time 2014 ms
Memory 640 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
AC × 2
AC × 39
TLE × 1
Set Name Test Cases
Sample s1.txt, s2.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, s1.txt, s2.txt
Case Name Status Exec Time Memory
01.txt AC 784 ms 640 KB
02.txt AC 769 ms 640 KB
03.txt AC 771 ms 640 KB
04.txt AC 787 ms 640 KB
05.txt AC 774 ms 640 KB
06.txt AC 784 ms 640 KB
07.txt AC 767 ms 640 KB
08.txt AC 783 ms 640 KB
09.txt AC 183 ms 640 KB
10.txt AC 181 ms 640 KB
11.txt AC 179 ms 640 KB
12.txt AC 181 ms 640 KB
13.txt AC 181 ms 640 KB
14.txt AC 180 ms 640 KB
15.txt AC 1697 ms 640 KB
16.txt AC 1720 ms 640 KB
17.txt AC 1700 ms 640 KB
18.txt AC 1713 ms 640 KB
19.txt AC 1687 ms 640 KB
20.txt AC 1709 ms 640 KB
21.txt TLE 2014 ms 640 KB
22.txt AC 1990 ms 640 KB
23.txt AC 113 ms 640 KB
24.txt AC 116 ms 640 KB
25.txt AC 1058 ms 640 KB
26.txt AC 1046 ms 640 KB
27.txt AC 15 ms 256 KB
28.txt AC 16 ms 256 KB
29.txt AC 15 ms 256 KB
30.txt AC 16 ms 256 KB
31.txt AC 15 ms 256 KB
32.txt AC 16 ms 256 KB
33.txt AC 16 ms 256 KB
34.txt AC 16 ms 256 KB
35.txt AC 1 ms 256 KB
36.txt AC 1 ms 256 KB
37.txt AC 1 ms 256 KB
38.txt AC 1 ms 256 KB
s1.txt AC 1 ms 256 KB
s2.txt AC 1 ms 256 KB