이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
#define INF 1000000000000000
#define lchild(i) (i*2 + 1)
#define rchild(i) (i*2 + 2)
#define mid(l, u) ((l+u)/2)
#define x(p) p.first
#define y(p) p.second
#define MOD 998244353
using namespace std;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int h, w;
cin>>h>>w;
char mat[h+1][w+1];
int preo[h+1][w+1];
int prer[h+1][w+1];
for(int i = 1;i<=h;i++) for(int j = 1;j<=w;j++) preo[i][j] = prer[i][j] = 0;
for(int i = 1;i<=h;i++){
string s;
cin>>s;
for(int j = 1;j<=w;j++){
mat[i][j] = s[j-1];
}
}
int cnt = 0;
for(int i = 1;i<=h;i++){
preo[i][w] = (mat[i][w]=='O');
for(int j = w-1;j>=1;j--){
preo[i][j] = preo[i][j+1] + (mat[i][j]=='O');
}
}
for(int j = 1;j<=w;j++){
prer[h][j] = (mat[h][j] == 'I');
for(int i = h-1;i>=1;i--){
prer[i][j] = prer[i+1][j] + (mat[i][j]=='I');
}
}
for(int i = 1;i<h;i++){
for(int j = 1;j<w;j++){
if(mat[i][j] == 'J') cnt += (preo[i][j+1] * prer[i+1][j]);
}
}
cout<<cnt<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |