Submission #1125239

#TimeUsernameProblemLanguageResultExecution timeMemory
1125239omar1312Bitaro the Brave (JOI19_ho_t1)C++20
100 / 100
289 ms151304 KiB
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
#define ll long long
#define pb push_back
#define all(x) x.begin(), x.end()
const int mod = 1000000007;
const int N = 3001;
string a[N+2];
ll pref[N+2][N+2][2];
void solve(){
    int n, m;
    cin>>n>>m;
    for(int i = 0; i < n; i++){
        cin>>a[i];
    }
    for(int i = 0; i < n; i++){
        if(a[i][0] == 'O')pref[i][0][0] = 1;
        for(int j = 1; j < m; j++){
            pref[i][j][0] = pref[i][j - 1][0] + (a[i][j] == 'O');
        }
    }
    for(int j = 0; j < m; j++){
        if(a[0][j] == 'I')pref[0][j][1] = 1;
        for(int i = 1; i < n; i++){
            pref[i][j][1] = pref[i - 1][j][1] + (a[i][j] == 'I');
        }
    }
    ll ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if(a[i][j] == 'J'){
                ans += (pref[i][m - 1][0] - pref[i][j][0]) * (pref[n - 1][j][1] - pref[i][j][1]);
            }
        }
    }
    cout<<ans;
}
int main(){
cin.tie(0)->sync_with_stdio(0);
    int tt = 1;
    //cin>>tt;
    while(tt--){
        solve();
        cout<<'\n';
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...