Submission #1226712

#TimeUsernameProblemLanguageResultExecution timeMemory
1226712wedonttalkanymoreBitaro the Brave (JOI19_ho_t1)C++20
100 / 100
397 ms176836 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const ll N = 3005, inf = 1e9;

int h, w;
int a[N][N];
ll pfs[N][N], pfs1[N][N]; 

signed main() {
	cin >> h >> w;
	for (int i = 1; i <= h; i++) {
		string s;
		cin >> s;
		for (int j = 1; j <= w; j++) {
			if (s[j - 1] == 'J') a[i][j] = 0;
			else if (s[j - 1] == 'O') a[i][j] = 1;
			else a[i][j] = 2;
		}
	}
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			pfs[i][j] = pfs[i][j - 1] + (a[i][j] == 1);
		}
	}
	for (int j = 1; j <= w; j++) {
		for (int i = 1; i <= h; i++) {
			pfs1[i][j] = pfs1[i - 1][j] + (a[i][j] == 2);
		}
	}
	ll ans = 0;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (a[i][j] == 0) {
//				cout << i << ' ' << j << ' ';
//				cout << (pfs[i][w] - pfs[i][j]) << ' ' << (pfs1[h][j] - pfs1[i][j]) << '\n';
				ans += (pfs[i][w] - pfs[i][j]) * (pfs1[h][j] - pfs1[i][j]);
			}
		}
	}
	cout << ans;
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...