이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 3005;
int main(){
	int h, w;
	ll sum = 0;
	ll zerocount, onecount;
	vector<string> grid;
	string input;
	ll pref0[N][N], pref1[N][N];
	cin >> h >> w;
	for(int i = 0; i < h; i++){
		cin >> input;
		grid.push_back(input);
	}
	for(int i = 0; i < N-2; i++){
		for(int j = 0; j < N-2; j++){
			pref1[i][j] = 0;
			pref0[i][j] = 0;
		}
	}
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(grid[i][j] == 'O'){
				pref0[i][j]++;
			}
			else if(grid[i][j] == 'I'){
				pref1[i][j]++;
			}
		}
	}
	
	for(int i = 0; i < h; i++){
		for(int j = 1; j < w; j++){
			pref0[i][j] += pref0[i][j-1];
		}
	}
	for(int i = 1; i < h; i++){
		for(int j = 0; j < w; j++){
			pref1[i][j] += pref1[i-1][j];
		}
	}
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(grid[i][j] == 'J'){
				// cout << i << " " << j << endl;
				zerocount = pref0[i][w-1] - pref0[i][j];
				onecount = pref1[h-1][j] - pref1[i][j];
				sum += zerocount*onecount;
			}
		}
	}
	cout << sum << endl;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |