제출 #428241

#제출 시각아이디문제언어결과실행 시간메모리
428241BertedBitaro the Brave (JOI19_ho_t1)C++14
100 / 100
115 ms89348 KiB
#include <iostream>
#define ll long long

using namespace std;

int H, W;
string A[3001];
int hor[3001][3001], ver[3001][3001];

int main()
{
	ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> H >> W;
	for (int i = 0; i < H; i++) cin >> A[i];

	for (int i = 0; i < H; i++)
	{
		for (int j = W - 1; j >= 0; j--)
		{
			hor[i][j] = (A[i][j] == 'O');
			if (j + 1 < W) hor[i][j] += hor[i][j + 1];
		}
	}	

	for (int i = H - 1; i >= 0; i--)
	{
		for (int j = 0; j < W; j++)
		{
			ver[i][j] = (A[i][j] == 'I');
			if (i + 1 < H) ver[i][j] += ver[i + 1][j];
		}
	}

	ll res = 0;
	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			res += 1ll * (A[i][j] == 'J') * hor[i][j] * ver[i][j]; 
		}
	}

	cout << res << "\n";

	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...