Submission #1237173

#TimeUsernameProblemLanguageResultExecution timeMemory
1237173nasjesBitaro the Brave (JOI19_ho_t1)C++20
100 / 100
487 ms247756 KiB
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <string>
#include <cstring>
#include <iterator>
#include <random>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
const ll dim = 5*1e3+7;
//const ll mod = 1e9 + 7;
const ll inf = 1e18 + 77;
#define endl "\n"
#define fi first
#define pb push_back
#define se second
#define vll vector<ll>

ll n, m;
ll a[dim][dim];
ll o[dim][dim];
ll b[dim][dim];
int main() {
    ll k, s, t, u0, v0;
    cin>>n>>m;
    for(int i=1; i<=n; i++){
        string s;
        cin>>s;
        for(int j=1; j<=m; j++){
            if(s[j-1]=='J')a[i][j]=1;
            else if(s[j-1]=='I')a[i][j]=2;
            else a[i][j]=3;
        }
    }
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            o[i][j]=o[i][j-1];
            if(a[i][j]==3)o[i][j]++;
        }
    }

    for(int j=1; j<=m; j++){
        for(int i=1; i<=n; i++){
            b[i][j]=b[i-1][j];
            if(a[i][j]==2)b[i][j]++;
        }
    }
    ll ans=0;
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            if(a[i][j]==1){
                ll c1=b[n][j]-b[i][j];
                ll c2=o[i][m]-o[i][j];
                ans+=c1*c2;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...