This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// In the name of the God
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define pii pair <int, int>
#define smin(x, y) (x) = min((x), (y))
#define smax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(), (x).end()
using namespace std;
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2")
const int inf = 1e9+7;
const int mod = 998244353;
const int maxn = 3e3+5;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int h, w, r[maxn][maxn], c[maxn][maxn];
string s[maxn];
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> h >> w;
for (int i = 0; i < h; i++) cin >> s[i];
for (int i = 0; i < h; i++) {
for (int j = w-2; j >= 0; j--) {
r[i][j] = r[i][j+1]+(s[i][j+1] == 'O');
// if (s[i][j+1] == 'o') cout << j << "FFF\n";
// cout << s[i] << '\n';
}
}
for (int i = h-2; i >= 0; i--) {
for (int j = 0; j < w; j++) {
c[i][j] = c[i+1][j]+(s[i+1][j] == 'I');
}
}
int ans = 0;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (s[i][j] == 'J') ans += r[i][j]*c[i][j];
}
}
cout << ans << '\n';
// cout << r[0][0] << '\n';
return 0;
}
/*
srand(time(0));
cout << (rand()%1900) + 1 << ' ' << (rand()%2)+5 << '\n';
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |