This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
import java.util.*;
import java.io.*;
class joi2019_ho_t1 {
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[][]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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |