import java.util.*;
import java.io.*;
class Main {
public static void main(String[] args) throws IOException{
BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new PrintStream(System.out));
StringTokenizer st=new StringTokenizer(f.readLine());
int n=Integer.parseInt(st.nextToken());
int m=Integer.parseInt(st.nextToken());
char[][]arr=new char[n][m];
int[][]arrJ=new int[n][m];
int[][]arrI=new int[n][m];
int[][]arrO=new int[n][m];
for(int i=0;i<n;i++){
String a=f.readLine();
for(int j=0;j<m;j++){
arr[i][j]=a.charAt(j);
arrO[i][j]=j==0?0:arrO[i][j-1];
arrI[i][j]=i==0?0:arrI[i-1][j];
if(arr[i][j]=='O'){
arrO[i][j]++;
}
else if(arr[i][j]=='I'){
arrI[i][j]++;
}
}
}
long ans=0;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(arr[i][j]!='J')continue;
int x=i==0?arrI[n-1][j]:arrI[n-1][j]-arrI[i-1][j];
int y=j==0?arrO[i][m-1]:arrO[i][m-1]-arrO[i][j-1];
ans+=x*y;
}
}
System.out.print(ans);
f.close();
out.close();
}
}
class pair implements Comparable <pair>{
int num;
int idx;
public int compareTo(pair other){
return num- other.num;
}
pair(int a, int b)
{
num=a;
idx=b;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
98 ms |
9724 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
98 ms |
9724 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
98 ms |
9724 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |