제출 #925467

#제출 시각아이디문제언어결과실행 시간메모리
925467XiaoyangBitaro the Brave (JOI19_ho_t1)C++17
100 / 100
219 ms180108 KiB
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 1ll<<60
#define rep(i,a,b) for (ll i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
#define endl "\n"
void inc(ll &a,ll b) {a=(a+b)%mod;}
void dec(ll &a,ll b) {a=(a-b+mod)%mod;}
int prod(ll a,ll b) {return ll(a)*ll(b)%mod;}
int lowbit(ll x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}
 
const ll maxn=3333;

char grid[maxn][maxn];
ll row[maxn][maxn],col[maxn][maxn];


signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll r,c;cin>>r>>c;
	rep(i,1,r+1)rep(j,1,c+1)cin>>grid[i][j];
	
	rep(i,1,r+1){
		rep(j,1,c+1){
			row[i][j]=row[i][j-1];
			row[i][j]+=grid[i][j]=='O';
		}
	}
	
	rep(j,1,c+1){
		rep(i,1,r+1){
			col[i][j]=col[i-1][j];
			col[i][j]+=grid[i][j]=='I';
		}
	}
	/*
	rep(i,1,r+1){
		rep(j,1,c+1){
			cout<<col[i][j]<<" ";
		}
		cout<<endl;
	}
	*/
	ll cnt=0;
	rep(i,1,r+1){
		rep(j,1,c+1){
			if(grid[i][j]!='J')continue;
			//cerr<<i<<" "<<j<<endl;
			ll a=row[i][c]-row[i][j-1];
			ll b=col[r][j]-col[i-1][j];
			//debug(a);
			//debug(b);
			if(a>0 and b>0){
				cnt+=a*b;
			}
		}
	}
	cout<<cnt<<endl;
	return 0;
}
/*
4 4
JJOO
JJOO
IIJO
IIIJ

3 4
JOIJ
JIOO
IIII
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...