제출 #321121

#제출 시각아이디문제언어결과실행 시간메모리
321121teehandsomeBitaro the Brave (JOI19_ho_t1)C++11
100 / 100
468 ms88636 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define INF 1e9+7
#define all(x) x.begin(),x.end()
using namespace std;
using namespace __gnu_pbds;
using ll=long long;
using pii=pair<int,int>;
using ppi=pair<int,pii>;
using oset=tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>;

template<typename T>
void _print(vector<T> x) {for(auto e:x) cerr<<e<<",";}
template<typename T>
void _print(T x) {cerr<<x;}

void dbg() {cerr<<endl;}
template<typename Head,typename... Tail>
void dbg(Head H,Tail... T) {
    _print(H);
    if(sizeof...(T)) cerr<<",";
    else cerr<<"\"]";
    dbg(T...);
}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:[\"",dbg(__VA_ARGS__)

int m,n;
char a[3002][3002];
int dp[3002][3002][2];
int dm[4]={-1,0,1,0}; int dn[4]={0,1,0,-1};
map<char,int> hsh;

int main () {
    ios::sync_with_stdio(false); cin.tie(0);
    hsh['O']=0; hsh['I']=1; hsh['J']=2;
    cin>>m>>n;
    for(int i=1;i<=m;i++) {
        for(int j=1;j<=n;j++) {
            cin>>a[i][j];
        }
    }
    for(int i=1;i<=m;i++) {
        for(int j=n;j>=1;j--) {
            dp[i][j][0]=dp[i][j+1][0]+(a[i][j]=='O');
        }
    }
    for(int j=1;j<=n;j++) {
        for(int i=m;i>=1;i--) {
            dp[i][j][1]=dp[i+1][j][1]+(a[i][j]=='I');
        }
    }
    ll ans=0;
    for(int i=1;i<=m;i++) {
        for(int j=1;j<=n;j++) {
            if(a[i][j]=='J') {
                ans+=dp[i][j+1][hsh['O']]*dp[i+1][j][hsh['I']];
            }
        }
    }
    cout<<ans<<endl;
}

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