This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define eb emplace_back
#define vl vector<ll>
#define fi first
#define se second
#define in insert
#define mpr make_pair
#define lg(x) __lg(x)
#define bpc(x) __builtin_popcount(x)
#define all(v) v.begin(), v.end()
#define endl "\n"
using namespace std;
const int sz = 2e5+5;
const int mod = 998244353;
const ll inf = 1000000000000000;
void solve()
{
ll n, m, i, j;
cin>>n>>m;
char a[n+1][m+1];
ll sc[n+2][m+2], sr[n+2][m+2];
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
cin>>a[i][j];
}
}
for(i=1;i<=n;i++){sr[i][m+1] = 0;}
for(i=1;i<=m;i++){sc[n+1][i] = 0;}
ll ans = 0;
for(i=n;i>0;i--){
for(j=m;j>0;j--){
sr[i][j] = sr[i][j+1];
sc[i][j] = sc[i+1][j];
if(a[i][j] == 'O'){sr[i][j]++;}
else if(a[i][j] == 'I'){sc[i][j]++;}
else{
ans += (sr[i][j] * sc[i][j]);
}
}
}
/*for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
cout << sr[i][j] << ' ';
}
cout << endl;
}*/
cout << ans << endl;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//precomp();
ll tst=1;
//cin>>tst;
while(tst--){
solve();
}
}
/*
1
3 2
2 2 2
1 6
1 5
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |