#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pl = pair<ll,ll>;
#define pb push_back
#define form(m,it) for(auto it=m.begin(); it!=m.end(); it++)
#define forp(i,a,b) for(ll i=a; i<=b; i++)
#define forn(i,a,b) for(ll i=a; i>=b; i--)
#define newl '\n'
#define ff first
#define ss second
const ll mod = 1000000007;
int cr[3][3005][3005];
int cc[3][3005][3005];
int a[3005][3005];
void solve(){
int h,w; cin>>h>>w;
char c;
forp(i,1,h){
forp(j,1,w){
cin>>c;
if(c=='J'){
a[i][j]=0;
}
if(c=='O'){
a[i][j]=1;
}
if(c=='I'){
a[i][j]=2;
}
}
}
forp(i,1,h){
forp(j,1,w){
forp(k,0,2){
cr[k][i][j]=cr[k][i][j-1]+(a[i][j]==k);
}
}
}
forp(i,1,h){
forp(j,1,w){
forp(k,0,2){
cc[k][i][j]=cc[k][i-1][j]+(a[i][j]==k);
}
}
}
ll ans=0;
forp(i,1,h){
forp(j,1,w){
if(a[i][j]==0){
ans+=(cr[1][i][w]-cr[1][i][j-1])*(cc[2][h][j]-cc[2][i-1][j]);
}
}
}
cout<<ans<<newl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1; //cin>>t;
while(t--)solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
2 ms |
3404 KB |
Output is correct |
6 |
Correct |
2 ms |
3276 KB |
Output is correct |
7 |
Correct |
2 ms |
3020 KB |
Output is correct |
8 |
Correct |
2 ms |
3404 KB |
Output is correct |
9 |
Correct |
2 ms |
3276 KB |
Output is correct |
10 |
Correct |
2 ms |
3020 KB |
Output is correct |
11 |
Correct |
2 ms |
3404 KB |
Output is correct |
12 |
Correct |
2 ms |
3276 KB |
Output is correct |
13 |
Correct |
2 ms |
3020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
2 ms |
3404 KB |
Output is correct |
6 |
Correct |
2 ms |
3276 KB |
Output is correct |
7 |
Correct |
2 ms |
3020 KB |
Output is correct |
8 |
Correct |
2 ms |
3404 KB |
Output is correct |
9 |
Correct |
2 ms |
3276 KB |
Output is correct |
10 |
Correct |
2 ms |
3020 KB |
Output is correct |
11 |
Correct |
2 ms |
3404 KB |
Output is correct |
12 |
Correct |
2 ms |
3276 KB |
Output is correct |
13 |
Correct |
2 ms |
3020 KB |
Output is correct |
14 |
Correct |
15 ms |
19660 KB |
Output is correct |
15 |
Correct |
5 ms |
12236 KB |
Output is correct |
16 |
Correct |
8 ms |
11084 KB |
Output is correct |
17 |
Correct |
1 ms |
588 KB |
Output is correct |
18 |
Correct |
19 ms |
21144 KB |
Output is correct |
19 |
Correct |
15 ms |
20960 KB |
Output is correct |
20 |
Correct |
14 ms |
20744 KB |
Output is correct |
21 |
Correct |
21 ms |
21460 KB |
Output is correct |
22 |
Correct |
16 ms |
21060 KB |
Output is correct |
23 |
Correct |
15 ms |
20892 KB |
Output is correct |
24 |
Correct |
19 ms |
21340 KB |
Output is correct |
25 |
Correct |
20 ms |
21060 KB |
Output is correct |
26 |
Correct |
16 ms |
20980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
2 ms |
3404 KB |
Output is correct |
6 |
Correct |
2 ms |
3276 KB |
Output is correct |
7 |
Correct |
2 ms |
3020 KB |
Output is correct |
8 |
Correct |
2 ms |
3404 KB |
Output is correct |
9 |
Correct |
2 ms |
3276 KB |
Output is correct |
10 |
Correct |
2 ms |
3020 KB |
Output is correct |
11 |
Correct |
2 ms |
3404 KB |
Output is correct |
12 |
Correct |
2 ms |
3276 KB |
Output is correct |
13 |
Correct |
2 ms |
3020 KB |
Output is correct |
14 |
Correct |
15 ms |
19660 KB |
Output is correct |
15 |
Correct |
5 ms |
12236 KB |
Output is correct |
16 |
Correct |
8 ms |
11084 KB |
Output is correct |
17 |
Correct |
1 ms |
588 KB |
Output is correct |
18 |
Correct |
19 ms |
21144 KB |
Output is correct |
19 |
Correct |
15 ms |
20960 KB |
Output is correct |
20 |
Correct |
14 ms |
20744 KB |
Output is correct |
21 |
Correct |
21 ms |
21460 KB |
Output is correct |
22 |
Correct |
16 ms |
21060 KB |
Output is correct |
23 |
Correct |
15 ms |
20892 KB |
Output is correct |
24 |
Correct |
19 ms |
21340 KB |
Output is correct |
25 |
Correct |
20 ms |
21060 KB |
Output is correct |
26 |
Correct |
16 ms |
20980 KB |
Output is correct |
27 |
Correct |
367 ms |
255708 KB |
Output is correct |
28 |
Correct |
33 ms |
66372 KB |
Output is correct |
29 |
Correct |
26 ms |
22212 KB |
Output is correct |
30 |
Correct |
2 ms |
1100 KB |
Output is correct |
31 |
Correct |
297 ms |
212432 KB |
Output is correct |
32 |
Correct |
289 ms |
255968 KB |
Output is correct |
33 |
Correct |
257 ms |
255196 KB |
Output is correct |
34 |
Correct |
325 ms |
246076 KB |
Output is correct |
35 |
Correct |
298 ms |
255944 KB |
Output is correct |
36 |
Correct |
259 ms |
255328 KB |
Output is correct |
37 |
Correct |
372 ms |
256068 KB |
Output is correct |
38 |
Correct |
201 ms |
212148 KB |
Output is correct |
39 |
Correct |
191 ms |
211384 KB |
Output is correct |