Submission #165981

#TimeUsernameProblemLanguageResultExecution timeMemory
165981sochoBitaro the Brave (JOI19_ho_t1)C++14
100 / 100
741 ms161656 KiB
#include "bits/stdc++.h"
using namespace std;

int main() {
    
    int h, w;
    cin >> h >> w;
    
    string arr[h];
    for (int i=0; i<h; i++) cin >> arr[i];
    
    long long iron[h+1][w+1], orbs[h+1][w+1];
    for (int i=0; i<h+1; i++) iron[i][0] = 0, orbs[i][0] = 0;
    for (int i=0; i<w+1; i++) iron[0][i] = 0, orbs[0][i] = 0;
    
    for (int i=0; i<h; i++) {
		for (int j=0; j<w; j++) {
			if (arr[i][j] == 'I') iron[i+1][j+1] = iron[i][j+1] + 1;
			else iron[i+1][j+1] = iron[i][j+1];
			if (arr[i][j] == 'O') orbs[i+1][j+1] = orbs[i+1][j] + 1;
			else orbs[i+1][j+1] = orbs[i+1][j];
		}
	}
	
	long long score = 0;
	long long ik, jk;
	
	for (int i=0; i<h; i++) {
		for (int j=0; j<w; j++) {
			if (arr[i][j] == 'J') {
				// cout << "POS: " << i << ' ' << j << endl;
				ik = i + 1;
				jk = j + 1;
				long long ot = iron[h][jk] - iron[ik][jk];
				long long at = orbs[ik][w] - orbs[ik][jk];
				score += (ot * at);
			}
		}
	}
	
	cout << score << endl;
    
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...