#include <bits/stdc++.h>
#define task "BriantheCrab"
#define int long long
#define pii pair <int, int>
#define fi first
#define se second
#define szf sizeof
#define sz(s) (int)((s).size())
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;
template <class T> void minimize (T &t, T f) {if (t > f) t = f;}
template <class T> void maximize (T &t, T f) {if (t < f) t = f;}
const int maxN = 3e3 + 5;
const int inf = 1e18 + 7;
const int mod = 1e9 + 7;
// khong tu code thi khong kha len duoc dau
int n, m;
char a[maxN][maxN];
int pfs[maxN][maxN][2]; // o, i
vector <pii> posJ;
inline int get (int xU, int yU, int xD, int yD, int t) {
return pfs[xD][yD][t] - pfs[xD][yU - 1][t] - pfs[xU - 1][yD][t] + pfs[xU - 1][yU - 1][t];
}
void solve () {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i ++) {
for (int j = 1; j <= m; j ++) {
cin >> a[i][j];
if (a[i][j] == 'J') {
posJ.push_back ({i, j});
}
}
}
for (int i = 1; i <= n; i ++) {
for (int j = 1; j <= m; j ++) {
pfs[i][j][0] = pfs[i - 1][j][0] + pfs[i][j - 1][0] - pfs[i - 1][j - 1][0] + (a[i][j] == 'O');
pfs[i][j][1] = pfs[i - 1][j][1] + pfs[i][j - 1][1] - pfs[i - 1][j - 1][1] + (a[i][j] == 'I');
}
}
int res = 0;
for (auto [x, y] : posJ) {
res += get (x, y + 1, x, m, 0) * get (x + 1, y, n, y, 1);
//cout << x << ' ' << y << ' ' << get (x, y + 1, x, m, 0) <<' ' << get (x + 1, y, n, y, 1) << '\n';
}
cout << res;
return;
}
signed main () {
cin.tie (nullptr) -> sync_with_stdio (false);
if (fopen (task".inp", "r")) {
freopen (task".inp", "r", stdin);
freopen (task".out", "w", stdout);
}
int t = 1;
//cin >> t;
while (t --) {
solve ();
}
return 0;
}
// thfv
컴파일 시 표준 에러 (stderr) 메시지
joi2019_ho_t1.cpp: In function 'int main()':
joi2019_ho_t1.cpp:66:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
66 | freopen (task".inp", "r", stdin);
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
joi2019_ho_t1.cpp:67:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
67 | freopen (task".out", "w", stdout);
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |