#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fi first
#define sc second
#define pb push_back
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
template<typename type>
using ordered_set = tree<type, null_type, less<type>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 3005, mod = 1e9 + 7, inf = 2e9;
const int dl[] = {-1, 0, 1, 0}, dc[] = {0, 1, 0, -1};
const int ddl[] = {-1, -1, -1, 0, 1, 1, 1, 0}, ddc[] = {-1, 0, 1, 1, 1, 0, -1, -1};
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
int rng(int lo = 1, int hi = INT_MAX) {
uniform_int_distribution<int> rnd(lo, hi);
return rnd(gen);
}
struct mint {
int val;
mint(int32_t x = 0) {
val = x % mod;
}
mint(long long x) {
val = x % mod;
}
mint operator+(mint x) {
return val + x.val;
}
mint operator-(mint x) {
return val - x.val + mod;
}
mint operator*(mint x) {
return 1LL * val * x.val;
}
void operator+=(mint x) {
val = (*this + x).val;
}
void operator-=(mint x) {
val = (*this - x).val;
}
void operator*=(mint x) {
val = (*this * x).val;
}
friend auto operator>>(istream& in, mint &x) -> istream& {
in >> x.val;
x.val %= mod;
return in;
}
friend auto operator<<(ostream& out, mint const &x) -> ostream& {
out << x.val;
return out;
}
};
int n, m, ln[N][N], col[N][N];
char a[N][N];
int32_t main()
{
cin.tie(nullptr)->sync_with_stdio(0);
cin >> n >> m;
for(int i=1; i<=n; i++)
for(int j=1; j<=m; j++)
cin >> a[i][j];
for(int i=1; i<=n; i++)
for(int j=1; j<=m; j++)
ln[i][j] = ln[i][j-1] + (a[i][j] == 'O');
for(int j=1; j<=m; j++)
for(int i=1; i<=n; i++)
col[i][j] = col[i-1][j] + (a[i][j] == 'I');
ll ans = 0;
for(int i=1; i<=n; i++)
for(int j=1; j<=m; j++)
if(a[i][j] == 'J')
ans += 1LL * (ln[i][m] - ln[i][j]) * (col[n][j] - col[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... |