Submission #209208

#TimeUsernameProblemLanguageResultExecution timeMemory
209208origami100Bitaro the Brave (JOI19_ho_t1)C++11
100 / 100
572 ms150396 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll h, w;
	cin >> h >> w;
	vector <string> grid;
	for(ll i = 0; i < h; i++){
		string s;
		cin >> s;
		grid.push_back(s);
	}
	ll O[h][w], I[h][w];
	for(ll i = 0; i < h; i++){
		O[i][w - 1] = (grid[i][w - 1] == 'O')?1:0;
	}
	for(ll i = 0; i < w; i++){
		I[h - 1][i] = (grid[h - 1][i] == 'I')?1:0;
	}
	ll cnt = 0;
	for(ll i = h - 2; i >= 0; i--){
		for(ll j = w - 2; j >= 0; j--){
			switch(grid[i][j]){
				case 'J':
					I[i][j] = I[i + 1][j];
					O[i][j] = O[i][j + 1];
					cnt += I[i][j] * O[i][j];
					break;
				case 'O':
					I[i][j] = I[i + 1][j];
					O[i][j] = O[i][j + 1] + 1;
					break;
				case 'I':
					I[i][j] = I[i + 1][j] + 1;
					O[i][j] = O[i][j + 1];
					break;
			}
		}
	}
	cout << cnt;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...