Submission #1205028

#TimeUsernameProblemLanguageResultExecution timeMemory
1205028andrejikusBitaro the Brave (JOI19_ho_t1)C++20
100 / 100
279 ms150508 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) { cerr << to_string(h); if(sizeof...(t)) cerr << ", "; DBG(t...); }
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)

const int N = 3003;
char a[N][N];
ll prefO[N][N], sufI[N][N];

void solve() {
    int n, m; cin >> n >> m;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            cin >> a[i][j], prefO[i][j] = prefO[i][j-1] + (a[i][j] == 'O');

    for (int j = 1; j <= m; j++) {
        for (int i = 1; i <= n; i++)
            sufI[i][j] = sufI[i-1][j] + (a[i][j] == 'I');
    }

    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (a[i][j] != 'J') continue;
            ans += (prefO[i][m]-prefO[i][j])*(sufI[n][j]-sufI[i][j]);
        }
    }

    cout << ans << "\n";
}

signed main() {
    ios::sync_with_stdio(false); cin.tie(0);
	int t=1; //cin >> t;
	while (t--) {
        solve();
	}
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...