# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
163037 | 2019-11-11T06:45:53 Z | fluffypotato | Bitaro the Brave (JOI19_ho_t1) | Java 11 | 0 ms | 0 KB |
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; } }