제출 #1343639

#제출 시각아이디문제언어결과실행 시간메모리
1343639Born_To_LaughBitaro the Brave (JOI19_ho_t1)C++17
100 / 100
369 ms107888 KiB
// Born_To_Laugh - Hughie Do
#include <bits/stdc++.h>
#define alle(AC) AC.begin(), AC.end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
[[maybe_unused]] const int MOD = 998244353, INF = 1e9 + 7;

const int maxn = 3050;
int h, w;
int rowsuf[maxn][maxn], colsuf[maxn][maxn];
int state[maxn][maxn];

void solve(){
    cin >> h >> w;
    for(int i=1; i<=h; ++i){
        for(int j=1; j<=w; ++j){
            char c;cin >> c;
            if(c == 'J') state[i][j] = 1;
            if(c == 'O') state[i][j] = 2;
            if(c == 'I') state[i][j] = 3;
        }
    }

    for(int i=1; i<=h; ++i){
        for(int j=w; j>=1; --j){
            rowsuf[i][j] = rowsuf[i][j + 1] + (state[i][j] == 2);
        }
    }

    for(int i=1; i<=w; ++i){
        for(int j=h; j>=1; --j){
            colsuf[j][i] = colsuf[j + 1][i] + (state[j][i] == 3);
        }
    }

    ll ans = 0;
    for(int i=1; i<=h; ++i){
        for(int j=1; j<=w; ++j){
            if(state[i][j] == 1){
                ans += colsuf[i][j] * rowsuf[i][j];
            }
        }
    }
    cout << ans << '\n';
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...