Submission #1359236

#TimeUsernameProblemLanguageResultExecution timeMemory
1359236vuhBitaro the Brave (JOI19_ho_t1)C++20
100 / 100
241 ms150112 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
const int sz = 3e3;
int r[sz][sz], c[sz][sz];
void solve(){
    int h, w;
    cin >> h >> w;
    char a[h][w];
    for(int i =0 ;  i <h;i ++){
        for(int j =0 ; j <w;j ++){
            cin>>a[i][j];
        }
    }
    for(int i =0 ;  i < h;i ++){
        for(int j = w - 2 ; j >= 0; j --){
            r[i][j]  = r[i][j + 1];
            if(a[i][j + 1] == 'O')
            r[i][j] ++;
        }
    }
    for(int j =0 ;  j < w; j ++){
        for(int i = h - 2 ; i >= 0;i --){
            c[i][j] = c[i + 1][j];
            if(a[i + 1][j] == 'I')
            c[i][j] ++;
        }
    }
    int ans = 0;
    for(int i =0 ; i < h;i ++){// k > i,    l > j
        for(int j =0 ; j < w;j ++){
            if(a[i][j] == 'J'){
                ans += r[i][j] * c[i][j];
            }
        }
    }
    cout<<ans<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1;
    //cin >> T;
    while(T--) solve();
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...