Submission #382582

#TimeUsernameProblemLanguageResultExecution timeMemory
382582aryan12Bitaro the Brave (JOI19_ho_t1)C++17
100 / 100
268 ms16776 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long

void Solve() {
	int h, w;
	cin >> h >> w;
	char a[h][w];
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			cin >> a[i][j];
		}
	}
	int orbRow[h], ingotCol[w];
	for(int i = 0; i < h; i++) {
		orbRow[i] = 0;
	}
	for(int i = 0; i < w; i++) {
		ingotCol[i] = 0;
	}
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			if(a[i][j] == 'O') {
				orbRow[i]++;
			}
			if(a[i][j] == 'I') {
				ingotCol[j]++;
			}
		}
	}
	int ans = 0;
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			if(a[i][j] == 'J') {
				ans += orbRow[i] * ingotCol[j];
			}
			else if(a[i][j] == 'O') {
				orbRow[i]--;
			}
			else {
				ingotCol[j]--;
			}
		}
	}
	cout << ans << "\n";
}

int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	Solve();
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...