#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define imie(x...) cerr << "[" #x "]: ", [](auto... $) {((cerr << $ << "; "), ...); }(x), cerr << '\n'
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
const int mod=1e9+7;
const int N=3005;
char v[N][N];
int ile_O[N][N], ile_I[N][N];
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int h,w;
cin >> h >> w;
for(int i = 0; i < h; i++) {
for(int j = 0; j < w; j++) {
cin >> v[i][j];
}
}
ll ans = 0;
for(int i = 0; i < h; i++) {
for(int j = w - 2; j >= 0; j--) {
ile_O[i][j] = ile_O[i][j + 1];
if(v[i][j + 1] == 'O') {
ile_O[i][j]++;
}
}
}
for(int j = 0; j < w; j++) {
for(int i = h - 2; i >= 0; i--) {
ile_I[i][j] = ile_I[i + 1][j];
if(v[i + 1][j] == 'I') {
ile_I[i][j]++;
}
}
}
for(int i = 0; i < h; i++) {
for(int j = 0; j < w; j++) {
if(v[i][j] == 'J') {
ans += (ile_I[i][j] * ile_O[i][j]);
}
}
}
cout << ans;
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... |