답안 #276981

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
276981 2020-08-20T22:44:56 Z Gilgamesh Bitaro the Brave (JOI19_ho_t1) Java 11
0 / 100
78 ms 10388 KB
import java.util.*;
import java.io.*;

public class joi2019_ho_t1 {
	final static int MOD = 1000000007;
	final static int intMax = 1000000000;
	final static int intMin = -1000000000;
	final static int[] dx = { 0, 0, -1, 1 };
	final static int[] dy = { -1, 1, 0, 0 };

	static int add(int a, int b) {
		return (a + b) % MOD;
	}
	
	static int sub(int a, int b) {
		return (a - b + MOD) % MOD;
	}
	
	static int mult(int a, int b) {
		return (int)((((long)(a)) * b) % MOD);
	}
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//		BufferedReader br = new BufferedReader(new FileReader(".in"));
		PrintWriter out = new PrintWriter(new File(".out"));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int h = Integer.parseInt(st.nextToken());
		int w = Integer.parseInt(st.nextToken());
	    int grid[][] = new int[h][w];
	    for(int i = 0; i < h; ++i){
	        String s = br.readLine();
	        for(int j = 0; j < w; ++j){
	            grid[i][j] = s.charAt(j) == 'J' ? 0 : s.charAt(j) == 'O' ? 1 : 2;
	        }
	    }
	    int[][] suffo = new int[h][w];
	    int[][] suffi = new int[h][w];
	    for(int i = 0; i < h; ++i){
	        for(int j = w - 1; j >= 0; --j){
	            suffo[i][j] = grid[i][j] == 1 ? 1 : 0;
	            if(j < w - 1) suffo[i][j] += suffo[i][j + 1];
	        }
	    }
	    for(int i = 0; i < w; ++i){
	        for(int j = h - 1; j >= 0; --j){
	            suffi[j][i] = grid[j][i] == 2 ? 1 : 0;
	            if(j < h - 1) suffi[j][i] += suffi[j + 1][i];
	        }
	    }
	    long ans = 0;
	    for(int i = 0; i < w; ++i){
	        for(int j = 0; j < h; ++j){
	            if(grid[i][j] == 0) {
	                ans += (long) suffo[i][j] * suffi[i][j];
	            }
	        }
	    }
	    System.out.println(ans);
		br.close();
		out.close();
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 10388 KB Output is correct
2 Correct 77 ms 10376 KB Output is correct
3 Runtime error 75 ms 10380 KB Execution failed because the return code was nonzero
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 10388 KB Output is correct
2 Correct 77 ms 10376 KB Output is correct
3 Runtime error 75 ms 10380 KB Execution failed because the return code was nonzero
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 10388 KB Output is correct
2 Correct 77 ms 10376 KB Output is correct
3 Runtime error 75 ms 10380 KB Execution failed because the return code was nonzero
4 Halted 0 ms 0 KB -