Submission #548247

#TimeUsernameProblemLanguageResultExecution timeMemory
548247beaconmcBitaro the Brave (JOI19_ho_t1)C++17
100 / 100
192 ms158936 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

typedef long long ll;
using namespace std;
using namespace __gnu_pbds;

#define FOR(i, x, y) for(ll i=x; i<y; i++)
#define FORNEG(i, x, y) for(ll i=x; i>y; i--)
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)

ll prefx[3001][3001], prefy[3001][3001];
char grid[3001][3001];

int main(){
    fast();
    ll h,w;
    cin >> h >> w;

    FOR(i,0,h){
        string temp;
        cin >> temp;
        FOR(j,0,w){
            grid[i][j] = temp[j];
        }
    }
    FOR(i,0,h){
        FOR(j,0,w){
            if (j==0){
                if (grid[i][j]=='O') prefx[i][j] = 1;
            }else{
                prefx[i][j] = prefx[i][j-1] + (grid[i][j] == 'O');
            }
        }
    }

    FOR(i,0,h){
        FOR(j,0,w){
            if (i==0){
                if (grid[i][j] == 'I') prefy[i][j] = 1;
            }else{
                prefy[i][j] = prefy[i-1][j] + (grid[i][j]=='I');
            }
        }
    }
    ll ans = 0;
    FOR(i,0,h){
        FOR(j,0,w){
            if (grid[i][j] == 'J'){
                ans += (prefx[i][w-1] - prefx[i][j])*(prefy[h-1][j] - prefy[i][j]);
            }
        }
    }
    cout << ans;

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