Submission #1086609

#TimeUsernameProblemLanguageResultExecution timeMemory
1086609Dennis_JasonBitaro the Brave (JOI19_ho_t1)C++14
100 / 100
336 ms220752 KiB
#include <bitset>
#include <cmath>
#include <functional>
#include <algorithm>
#include <numeric>
#include <system_error>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#define pb push_back
#define MOD 1000000007
#define NMAX 200001
#define nl '\n'
#define pii1 pair<int, pair<int,int>>  (1,(1,2));
#define pii pair<int,int>
#define tpl tuple<int,int,int>
#define int long long
using namespace std;
ifstream fin("data.in");
ofstream fout("data.out");
const int INF=1e12;
/*
    ====================DEMONSTRATION======================


    =========================END===========================

 */
int n,m;
int mat[3001][3001];
int ans;
int O[3002][3002];
int I[3002][3002];
signed main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n>>m;
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=m;++j)
        {
            char x;
            cin>>x;
            if(x=='J')
            {
                mat[i][j]=1;
            }
            else if(x=='O')
            {
                mat[i][j]=2;
            }
            else
            {
                mat[i][j]=3;
            }
        }
    }

    for(int i=n;i>=1;--i)
    {
        for(int j=m;j>=1;--j)
        {
            O[i][j]+=O[i][j+1];
            I[i][j]+=I[i+1][j];
            if(mat[i][j]==2)
            {
                O[i][j]++;
            }
            if(mat[i][j]==3)
            {
                I[i][j]++;
            }
        }
    }

    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=m;++j)
        {
            if(I[i][j] && O[i][j] && mat[i][j]==1)
            {
                ans+=(I[i][j]*O[i][j]);
            }
        }

    }
    cout<<ans;



    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...