Submission #119277

#TimeUsernameProblemLanguageResultExecution timeMemory
119277tutisBitaro the Brave (JOI19_ho_t1)C++17
100 / 100
118 ms87416 KiB
/*input
4 4
JJOO
JJOO
IIJO
IIIJ
*/
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int II[3030][3030];
int OO[3030][3030];
int main()
{
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	string s[n];
	for (int i = 0; i < n; i++)
		cin >> s[i];
	ll ans = 0;
	for (int i = n - 1; i >= 0; i--)
	{
		for (int j = m - 1; j >= 0; j--)
		{
			OO[i][j] = OO[i][j + 1];
			II[i][j] = II[i + 1][j];
			ll O = OO[i][j];
			ll I = II[i][j];
			if (s[i][j] == 'J')
				ans += O * I;
			OO[i][j] += (s[i][j] == 'O');
			II[i][j] += (s[i][j] == 'I');
		}
	}
	cout << ans << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...