#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 1ll<<60
#define rep(i,a,b) for (ll i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
#define endl "\n"
void inc(ll &a,ll b) {a=(a+b)%mod;}
void dec(ll &a,ll b) {a=(a-b+mod)%mod;}
int prod(ll a,ll b) {return ll(a)*ll(b)%mod;}
int lowbit(ll x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}
const ll maxn=3333;
char grid[maxn][maxn];
ll row[maxn][maxn],col[maxn][maxn];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
ll r,c;cin>>r>>c;
rep(i,1,r+1)rep(j,1,c+1)cin>>grid[i][j];
rep(i,1,r+1){
rep(j,1,c+1){
row[i][j]=row[i][j-1];
row[i][j]+=grid[i][j]=='O';
}
}
rep(j,1,c+1){
rep(i,1,r+1){
col[i][j]=col[i-1][j];
col[i][j]+=grid[i][j]=='I';
}
}
/*
rep(i,1,r+1){
rep(j,1,c+1){
cout<<col[i][j]<<" ";
}
cout<<endl;
}
*/
ll cnt=0;
rep(i,1,r+1){
rep(j,1,c+1){
if(grid[i][j]!='J')continue;
//cerr<<i<<" "<<j<<endl;
ll a=row[i][c]-row[i][j-1];
ll b=col[r][j]-col[i-1][j];
//debug(a);
//debug(b);
if(a>0 and b>0){
cnt+=a*b;
}
}
}
cout<<cnt<<endl;
return 0;
}
/*
4 4
JJOO
JJOO
IIJO
IIIJ
3 4
JOIJ
JIOO
IIII
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
8796 KB |
Output is correct |
6 |
Correct |
1 ms |
8796 KB |
Output is correct |
7 |
Correct |
1 ms |
8792 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
2 ms |
8792 KB |
Output is correct |
10 |
Correct |
1 ms |
8792 KB |
Output is correct |
11 |
Correct |
2 ms |
8796 KB |
Output is correct |
12 |
Correct |
1 ms |
8916 KB |
Output is correct |
13 |
Correct |
2 ms |
8792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
8796 KB |
Output is correct |
6 |
Correct |
1 ms |
8796 KB |
Output is correct |
7 |
Correct |
1 ms |
8792 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
2 ms |
8792 KB |
Output is correct |
10 |
Correct |
1 ms |
8792 KB |
Output is correct |
11 |
Correct |
2 ms |
8796 KB |
Output is correct |
12 |
Correct |
1 ms |
8916 KB |
Output is correct |
13 |
Correct |
2 ms |
8792 KB |
Output is correct |
14 |
Correct |
7 ms |
24156 KB |
Output is correct |
15 |
Correct |
3 ms |
18780 KB |
Output is correct |
16 |
Correct |
4 ms |
16220 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
8 ms |
24412 KB |
Output is correct |
19 |
Correct |
7 ms |
24412 KB |
Output is correct |
20 |
Correct |
8 ms |
24412 KB |
Output is correct |
21 |
Correct |
8 ms |
24412 KB |
Output is correct |
22 |
Correct |
7 ms |
24412 KB |
Output is correct |
23 |
Correct |
7 ms |
24412 KB |
Output is correct |
24 |
Correct |
8 ms |
24412 KB |
Output is correct |
25 |
Correct |
8 ms |
24412 KB |
Output is correct |
26 |
Correct |
7 ms |
24416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
8796 KB |
Output is correct |
6 |
Correct |
1 ms |
8796 KB |
Output is correct |
7 |
Correct |
1 ms |
8792 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
2 ms |
8792 KB |
Output is correct |
10 |
Correct |
1 ms |
8792 KB |
Output is correct |
11 |
Correct |
2 ms |
8796 KB |
Output is correct |
12 |
Correct |
1 ms |
8916 KB |
Output is correct |
13 |
Correct |
2 ms |
8792 KB |
Output is correct |
14 |
Correct |
7 ms |
24156 KB |
Output is correct |
15 |
Correct |
3 ms |
18780 KB |
Output is correct |
16 |
Correct |
4 ms |
16220 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
8 ms |
24412 KB |
Output is correct |
19 |
Correct |
7 ms |
24412 KB |
Output is correct |
20 |
Correct |
8 ms |
24412 KB |
Output is correct |
21 |
Correct |
8 ms |
24412 KB |
Output is correct |
22 |
Correct |
7 ms |
24412 KB |
Output is correct |
23 |
Correct |
7 ms |
24412 KB |
Output is correct |
24 |
Correct |
8 ms |
24412 KB |
Output is correct |
25 |
Correct |
8 ms |
24412 KB |
Output is correct |
26 |
Correct |
7 ms |
24416 KB |
Output is correct |
27 |
Correct |
219 ms |
179380 KB |
Output is correct |
28 |
Correct |
13 ms |
81752 KB |
Output is correct |
29 |
Correct |
12 ms |
20800 KB |
Output is correct |
30 |
Correct |
1 ms |
4700 KB |
Output is correct |
31 |
Correct |
140 ms |
148028 KB |
Output is correct |
32 |
Correct |
188 ms |
180108 KB |
Output is correct |
33 |
Correct |
187 ms |
177744 KB |
Output is correct |
34 |
Correct |
165 ms |
169664 KB |
Output is correct |
35 |
Correct |
191 ms |
179980 KB |
Output is correct |
36 |
Correct |
183 ms |
177756 KB |
Output is correct |
37 |
Correct |
206 ms |
179792 KB |
Output is correct |
38 |
Correct |
123 ms |
147932 KB |
Output is correct |
39 |
Correct |
123 ms |
145852 KB |
Output is correct |