Submission #1359205

#TimeUsernameProblemLanguageResultExecution timeMemory
1359205greatrevanBitaro the Brave (JOI19_ho_t1)C++20
0 / 100
1 ms344 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

#define GreatRevan()            ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define int                     long long
#define ld                      long double
#define pp                      pair<int, int>
#define pb                      push_back
#define ff                      first
#define ss                      second
#define all(v)                  v.begin(), v.end()
#define rall(v)                 v.rbegin(), v.rend()
#define endl                    "\n"
#define YES                     cout<<"YES\n"
#define Yes                     cout<<"Yes\n"
#define NO                      cout<<"NO\n"
#define No                      cout<<"No\n"

template <class T>
using ordered_set =             tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const double Pi =               3.141592653589793;
const long long MaX =           1e10;
const long long mod =           1e9 + 7;

void code(){
    int n,m;
    cin>>n>>m;
    char a[n][m];
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            cin>>a[i][j];
        }
    }
    int orb[n][m];
    int ing[n][m];
    for (int i = 0; i < m; i++){
        orb[i][m-1] = 0;
        if (a[i][m-1] == 'O') orb[i][m-1]++;
        ing[n-1][i] = 0;
        if (a[n-1][i] == 'I') ing[n-1][i]++;
    }
    for (int i = n-1; i >= 0; i--){
        for (int j = m-1; j >= 0; j--){
            if (i < n-1){
                ing[i][j] = ing[i+1][j] + (a[i][j] == 'I');
            }
            if (j < m-1){
                orb[i][j] = orb[i][j+1] + (a[i][j] == 'O');
            }
        }
    }
    int res = 0;
    for (int i = n-1; i >= 0; i--){
        for (int j = m-1; j >= 0; j--){
            if (a[i][j] == 'J'){
                res += ing[i][j]*orb[i][j];
            }
        }
    }
    cout<<res<<endl;
}

signed main(){
    GreatRevan();
    int tcs = 1;
    //cin>>tcs;
    for (int i = 1; i <= tcs; i++){
        //cout<<"Case #"<<i<<": ";
        code();
    }
    cerr<<"By GreatRevan"<<endl<<endl;
}
/*
 ██████╗ ███████╗███╗  ██╗ █████╗ ███████╗
██╔════╝ ██╔════╝████╗ ██║██╔══██╗██╔════╝
██║  ██╗ █████╗  ██╔██╗██║██║  ╚═╝█████╗
██║  ╚██╗██╔══╝  ██║╚████║██║  ██╗██╔══╝
╚██████╔╝███████╗██║ ╚███║╚█████╔╝███████╗
 ╚═════╝ ╚══════╝╚═╝  ╚══╝ ╚════╝ ╚══════╝
   ███████╗██████╗ ██╗████████╗██╗
   ██╔════╝██╔══██╗██║╚══██╔══╝██║
   █████╗  ██████╔╝██║   ██║   ██║
   ██╔══╝  ██╔══██╗██║   ██║   ██║
   ██║     ██║  ██║██║   ██║   ███████╗
   ╚═╝     ╚═╝  ╚═╝╚═╝   ╚═╝   ╚══════╝
*/
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...