This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using ll = long long;
#define pb push_back
// overflow check strat : a * b / b == a
using std::cin;
using std::cout;
template <typename T>
std::ostream& operator<<( std::ostream& os, const std::vector<T>& v );
using namespace std;
const ll inf = 1e9 + 37;
void solve(){
ll n, m;
cin >> n >> m;
vector<string> g(n);
for(auto& s : g)
cin >> s;
vector<vector<ll> > osuf(n + 1, vector<ll>(m + 1)), isuf(n + 1, vector<ll>(m + 1));
for(ll row = 0; row < n; ++row) {
for(ll col = m - 1; col >= 0; --col) {
osuf[row][col] = osuf[row][col + 1] + (g[row][col] == 'O');
}
}
for(ll col = 0; col < m; ++col) {
for(ll row = n - 1; row >= 0; --row) {
isuf[row][col] = isuf[row + 1][col] + (g[row][col] == 'I');
}
}
ll ans = 0;
for(ll i = 0; i < n; ++i) {
for(ll j = 0; j < m; ++j) {
if(g[i][j] != 'J')
continue;
ans += osuf[i][j] * isuf[i][j];
}
}
cout << ans << endl;
}
signed main() {
#ifdef LOCAL
freopen("test.in", "r", stdin);
freopen("test.out", "w", stdout);
#endif
std::ios_base::sync_with_stdio(0);
cin.tie(NULL);
// signed t = 0; cin >> t; while(t--)
solve();
}
template <typename T>
std::ostream& operator<<( std::ostream& os, const std::vector<T>& v ) {
os << "[";
for (auto x : v)
os << x << ", ";
os << "]\n";
return os;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |