#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
#define SZ(x) ((int) (x).size())
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define debug(x) cerr << "[" << #x << " = " << (x) << "]" << endl
#define left __left
#define right __right
#define prev __prev
#define fi first
#define se second
template <class X, class Y>
bool maximize(X &x, Y y) {
if (x < y) return x = y, true;
else return false;
}
template <class X, class Y>
bool minimize(X &x, Y y) {
if (x > y) return x = y, true;
else return false;
}
int numRow, numCol;
#define MAX_ROW 3'030
char a[MAX_ROW + 2][MAX_ROW + 2];
namespace subtask1 {
bool check() {
return (numRow <= 100 && numCol <= 100);
}
void solve() {
ll ans = 0;
FOR(i, 1, numRow) {
FOR(j, 1, numCol) {
if (a[i][j] == 'J') {
int cnt_ingot = 0, cnt_orb = 0;
FOR(k, i + 1, numRow) if (a[k][j] == 'I') ++cnt_ingot;
FOR(l, j + 1, numCol) if (a[i][l] == 'O') ++cnt_orb;
ans += 1LL * cnt_ingot * cnt_orb;
}
}
}
cout << ans;
}
};
namespace subtask3 {
int cnt_orb[MAX_ROW + 2];
void solve() {
ll ans = 0;
FORD(i, numRow, 1) {
int cnt_ingot = 0;
FORD(j, numCol, 1) {
if (a[i][j] == 'J') {
ans += 1LL * cnt_ingot * cnt_orb[j];
} else if (a[i][j] == 'O') {
++cnt_ingot;
} else if (a[i][j] == 'I') {
cnt_orb[j]++;
}
}
}
cout << ans;
}
}
int main() {
ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define task "test"
if (fopen(task".inp","r")) {
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
/*
(i, j, k, l)
(i, j) = 'J';
(i, l) = 'O';
(k, j) = 'I';
*/
cin >> numRow >> numCol;
FOR(i, 1, numRow) FOR(j, 1, numCol) cin >> a[i][j];
// if (subtask1 :: check()) return subtask1 :: solve(), 0;
subtask3 :: solve();
return 0;
}
/* Discipline - Calm */
Compilation message (stderr)
joi2019_ho_t1.cpp: In function 'int main()':
joi2019_ho_t1.cpp:86:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
86 | freopen(task".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
joi2019_ho_t1.cpp:87:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
87 | 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... |