제출 #913551

#제출 시각아이디문제언어결과실행 시간메모리
913551PqrsawBitaro the Brave (JOI19_ho_t1)C++17
100 / 100
252 ms150936 KiB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast", "unroll-loops")
#define int long long 
const int maxn = 3e3 + 10, block = 320, mod = 1e9 + 7, inf = 2e9 + 10, lg = 22;
int n, m, o[maxn][maxn], ii[maxn][maxn], ans = 0;
char a[maxn][maxn];
void solve(){
	cin >> n >> m;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			cin >> a[i][j];
			if(a[i][j] == 'I'){
				ii[i][j]++;
			}
			else if(a[i][j] == 'O'){
				o[i][j]++;
			}
		}
	}
	for(int i = n; i >= 1; i--){
		for(int j = m; j >= 1; j--){
			ii[i][j] += ii[i + 1][j];
		}
	}
	for(int i = n; i >= 1; i--){
		for(int j = m; j >= 1; j--){
			o[i][j] += o[i][j + 1];
		}
	}
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(a[i][j] == 'J'){
				ans += ii[i + 1][j] * o[i][j + 1];
			}
		}
	}
	cout << ans << "\n";
}
signed main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int T = 1;
	//cin >> T;
	while(T--){
		solve();
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...