제출 #689297

#제출 시각아이디문제언어결과실행 시간메모리
689297zeroesandonesBitaro the Brave (JOI19_ho_t1)C++17
100 / 100
280 ms159816 KiB
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;

#define FOR(i, j, k) for (ll i = j; i < (ll) k; ++i)
#define FORD(i, j, k) for (ll i = j; i >= (ll) k; --i)
#define nl "\n"
#define sp " "

#define all(x) (x).begin(), (x).end()
#define sc second
#define fr first
#define pb emplace_back

void solve()
{
    ll n, m;
    cin >> n >> m;

    string a[n];
    FOR(i, 0, n) {
        cin >> a[i];
    }

    ll ans = 0;

    ll row[n][m] = {};
    ll col[n][m] = {};
    FOR(i, 0, n) {
        FOR(j, 0, m) {
            row[i][j] = (a[i][j] == 'O');
            if(j) row[i][j] += row[i][j - 1];
        }
    }

    FOR(j, 0, m) {
        FOR(i, 0, n) {
            col[i][j] = (a[i][j] == 'I');
            if(i) col[i][j] += col[i - 1][j];
        }
    }

    FOR(i, 0, n) {
        FOR(j, 0, m) {
            if(a[i][j] != 'J')
                continue;
            ll O = row[i][m - 1] - row[i][j];
            ll I = col[n - 1][j] - col[i][j];
            ans += (O * I);
        }
    }

    cout << ans << nl;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll 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...