Submission #465065

#TimeUsernameProblemLanguageResultExecution timeMemory
465065ohasanovBitaro the Brave (JOI19_ho_t1)C++17
100 / 100
382 ms85684 KiB
#include "bits/stdc++.h"
using namespace std;
int ans[3005][3005];
char arr[3005][3005];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,m;
    cin >> n >> m;
    vector<pair<int,int>> list;
    for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			cin >> arr[i][j];
		}
	}
	for(int j = m-1; j >= 0; j--){
		int o = 0;
		for(int i = n-1; i >= 0; i--){
			if(arr[i][j] == 'I') o++;
			if(arr[i][j] == 'J') {
				ans[i][j] = o;
			}
		}
	}
	for(int i = n-1; i >= 0; i--){
		int o = 0;
		for(int j = m-1; j >= 0; j--){
			if(arr[i][j] == 'O') o++;
			if(arr[i][j] == 'J') {
				list.push_back(make_pair(i,j));
				ans[i][j] *= o;
			}
		}
	}
	
	long long int ansss = 0;
	for(int i = 0; i < (int)list.size(); i++) ansss += ans[list[i].first][list[i].second];
	cout << ansss << endl;
	
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...