Submission #1359232

#TimeUsernameProblemLanguageResultExecution timeMemory
1359232itzmanuBitaro the Brave (JOI19_ho_t1)C++20
100 / 100
248 ms217056 KiB
#include <bits/stdc++.h>
using namespace std;
 
#define nitro ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define vi vector<int>
#define spc ' '
#define yes "YES"
#define no "NO"
#define endl "\n"
const int inf = 1e18;
const int maxn = 3e5 + 5;
const int mod = 1e9 + 7;
const int logn = 20;
 

void solve() {
    int n, m; cin >> n >> m;
    vector<pair<int, int>> js;
    vector<vi> rowo(n, vi(m, 0)), dI(n, vi(m, 0));
    vector<string> g(n);
    for(int i = 0; i < n; i++) cin >> g[i];

    for(int i = 0; i < n; i++)
        for(int j = m - 2; j >= 0; j--)
            rowo[i][j] = rowo[i][j+1] + (g[i][j + 1] == 'O');

    for(int j = 0; j < m; j++)
        for(int i = n - 2; i >= 0; i--)
            dI[i][j] = dI[i+1][j] + (g[i + 1][j] == 'I');

    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
            if(g[i][j] == 'J')
                js.push_back({i, j});

    int ans = 0;
    for(auto [i, j] : js)
        ans += rowo[i][j] * dI[i][j];

    cout << ans;
}
 
signed main() {
	// freopen("cbarn.in", "r", stdin);
	// freopen("cbarn.out", "w", stdout);
	nitro
	int t = 1;
	// cin >> t;
	for(int i = 1; i <= t; i++) {
		// cout << "Case #" << i << ": ";
		solve();
		cout << endl;
	}
	return 0;
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...