# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
163037 | fluffypotato | Bitaro the Brave (JOI19_ho_t1) | Java | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
import java.util.*;
import java.io.*;
public 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;
}
}