Submission #486870

#TimeUsernameProblemLanguageResultExecution timeMemory
486870PoPularPlusPlusBitaro the Brave (JOI19_ho_t1)C++17
100 / 100
314 ms159808 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long 
#define pb(e) push_back(e)
#define sv(a) sort(a.begin(),a.end())
#define sa(a,n) sort(a,a+n)
#define mp(a,b) make_pair(a,b)
#define vf first
#define vs second
#define ar array
#define all(x) x.begin(),x.end()
const int inf = 0x3f3f3f3f;
const int mod = 1000000007; 
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
bool remender(ll a , ll b){return a%b;}

void solve(){
	int n;
	cin >> n;
	int m;
	cin >> m;
	string s[n];
	for(int i = 0; i < n; i++)cin >> s[i];
	ll cnt[n][m] , cnt1[n][m];
	for(int i = 0; i < n; i++){
		cnt[i][0] = 0;
		for(int j = 1; j < m; j++){
			cnt[i][j] = cnt[i][j-1];
			if(s[i][j] == 'O')cnt[i][j]++;
		}
	}
	for(int j = 0; j < m; j++){
		cnt1[0][j] = 0;
		for(int i = 1; i < n; i++){
			cnt1[i][j] = cnt1[i-1][j];
			if(s[i][j] == 'I')cnt1[i][j]++;
		}
	}
	ll ans = 0;
	for(ll i = 0; i < n; i++){
		for(ll j = 0; j < m; j++){
			if(s[i][j] == 'J'){
				ans += (cnt[i][m-1] - cnt[i][j]) * (cnt1[n-1][j] - cnt1[i][j]);
			}
		}
	}
	cout << ans << '\n';
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
	//int t;cin >> t;while(t--)
	solve();
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...