이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//Coded by Chirath Nirodha
#include<bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
const ll mod=1e9+7;
inline void io(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
void solve(){
ll h,w;cin>>h>>w;
char arr[h][w];
for(int i=0;i<h;i++)for(int j=0;j<w;j++)cin>>arr[i][j];
ll hor[h][w];
ll ver[h][w];
for(int i=0;i<h;i++){
if(arr[i][w-1]=='O')hor[i][w-1]=1;
else hor[i][w-1]=0;
for(int j=w-2;j>=0;j--){
hor[i][j]=hor[i][j+1];
if(arr[i][j]=='O')hor[i][j]++;
}
}
for(int j=0;j<w;j++){
if(arr[h-1][j]=='I')ver[h-1][j]=1;
else ver[h-1][j]=0;
for(int i=h-2;i>=0;i--){
ver[i][j]=ver[i+1][j];
if(arr[i][j]=='I')ver[i][j]++;
}
}
ll ans=0;
for(int i=0;i<h-1;i++){
for(int j=0;j<w-1;j++){
if(arr[i][j]!='J')continue;
ans+=hor[i][j+1]*ver[i+1][j];
}
}
cout<<ans<<endl;
}
int main(){
io();
solve();
//int t;cin>>t;for(int i=0;i<t;i++)solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |