// 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';
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
2972 KB |
Output is correct |
6 |
Correct |
1 ms |
2908 KB |
Output is correct |
7 |
Correct |
1 ms |
1372 KB |
Output is correct |
8 |
Correct |
1 ms |
3164 KB |
Output is correct |
9 |
Correct |
1 ms |
3160 KB |
Output is correct |
10 |
Correct |
1 ms |
1372 KB |
Output is correct |
11 |
Correct |
1 ms |
3164 KB |
Output is correct |
12 |
Correct |
1 ms |
2908 KB |
Output is correct |
13 |
Correct |
1 ms |
1368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
2972 KB |
Output is correct |
6 |
Correct |
1 ms |
2908 KB |
Output is correct |
7 |
Correct |
1 ms |
1372 KB |
Output is correct |
8 |
Correct |
1 ms |
3164 KB |
Output is correct |
9 |
Correct |
1 ms |
3160 KB |
Output is correct |
10 |
Correct |
1 ms |
1372 KB |
Output is correct |
11 |
Correct |
1 ms |
3164 KB |
Output is correct |
12 |
Correct |
1 ms |
2908 KB |
Output is correct |
13 |
Correct |
1 ms |
1368 KB |
Output is correct |
14 |
Correct |
5 ms |
14948 KB |
Output is correct |
15 |
Correct |
2 ms |
10588 KB |
Output is correct |
16 |
Correct |
3 ms |
7516 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
5 ms |
15680 KB |
Output is correct |
19 |
Correct |
5 ms |
15452 KB |
Output is correct |
20 |
Correct |
5 ms |
15452 KB |
Output is correct |
21 |
Correct |
5 ms |
15708 KB |
Output is correct |
22 |
Correct |
5 ms |
15452 KB |
Output is correct |
23 |
Correct |
5 ms |
15452 KB |
Output is correct |
24 |
Correct |
5 ms |
15788 KB |
Output is correct |
25 |
Correct |
5 ms |
15452 KB |
Output is correct |
26 |
Correct |
5 ms |
15452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
2972 KB |
Output is correct |
6 |
Correct |
1 ms |
2908 KB |
Output is correct |
7 |
Correct |
1 ms |
1372 KB |
Output is correct |
8 |
Correct |
1 ms |
3164 KB |
Output is correct |
9 |
Correct |
1 ms |
3160 KB |
Output is correct |
10 |
Correct |
1 ms |
1372 KB |
Output is correct |
11 |
Correct |
1 ms |
3164 KB |
Output is correct |
12 |
Correct |
1 ms |
2908 KB |
Output is correct |
13 |
Correct |
1 ms |
1368 KB |
Output is correct |
14 |
Correct |
5 ms |
14948 KB |
Output is correct |
15 |
Correct |
2 ms |
10588 KB |
Output is correct |
16 |
Correct |
3 ms |
7516 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
5 ms |
15680 KB |
Output is correct |
19 |
Correct |
5 ms |
15452 KB |
Output is correct |
20 |
Correct |
5 ms |
15452 KB |
Output is correct |
21 |
Correct |
5 ms |
15708 KB |
Output is correct |
22 |
Correct |
5 ms |
15452 KB |
Output is correct |
23 |
Correct |
5 ms |
15452 KB |
Output is correct |
24 |
Correct |
5 ms |
15788 KB |
Output is correct |
25 |
Correct |
5 ms |
15452 KB |
Output is correct |
26 |
Correct |
5 ms |
15452 KB |
Output is correct |
27 |
Correct |
95 ms |
158864 KB |
Output is correct |
28 |
Correct |
10 ms |
63580 KB |
Output is correct |
29 |
Correct |
7 ms |
13916 KB |
Output is correct |
30 |
Correct |
1 ms |
860 KB |
Output is correct |
31 |
Correct |
72 ms |
130744 KB |
Output is correct |
32 |
Correct |
86 ms |
159828 KB |
Output is correct |
33 |
Correct |
76 ms |
159708 KB |
Output is correct |
34 |
Correct |
84 ms |
151740 KB |
Output is correct |
35 |
Correct |
75 ms |
159844 KB |
Output is correct |
36 |
Correct |
73 ms |
159568 KB |
Output is correct |
37 |
Correct |
101 ms |
160080 KB |
Output is correct |
38 |
Correct |
58 ms |
130304 KB |
Output is correct |
39 |
Correct |
56 ms |
130116 KB |
Output is correct |