#include "bits/stdc++.h"
// @JASPER'S BOILERPLATE
using namespace std;
using ll = long long;
#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 REP(i, b) for(int i = 0; i < b; i++)
#define PER(i, b) for(int i = b - 1; i >= 0; i--)
#define fi first
#define se second
#ifdef JASPER
#include "debug.h"
#else
#define debug(...) 166
#endif
using pii = pair < int, int >;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int N = 3e3 + 5;
int n, m;
char a[N][N];
int dpO[N][N], dpI[N][N];
void run_case() {
cin >> n >> m;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
cin >> a[i][j];
for (int j = m; j >= 1; --j) {
for (int i = 1; i <= n; ++i) {
dpO[i][j] = (a[i][j] == 'O');
dpO[i][j] += dpO[i][j + 1];
}
}
for (int i = n; i >= 1; --i) {
for (int j = 1; j <= m; ++j) {
dpI[i][j] = (a[i][j] == 'I');
dpI[i][j] += dpI[i + 1][j];
}
}
ll ans = 0;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
if (a[i][j] == 'J')
ans += 1ll * dpO[i][j] * dpI[i][j];
cout << ans << "\n";
}
signed main() {
cin.tie(0) -> sync_with_stdio(0);
int Test = 1;
//cin >> Test;
for (int test = 1; test <= Test; test++){
run_case();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
5 ms |
18780 KB |
Output is correct |
15 |
Correct |
2 ms |
14684 KB |
Output is correct |
16 |
Correct |
3 ms |
10840 KB |
Output is correct |
17 |
Correct |
1 ms |
4440 KB |
Output is correct |
18 |
Correct |
6 ms |
19036 KB |
Output is correct |
19 |
Correct |
6 ms |
19036 KB |
Output is correct |
20 |
Correct |
5 ms |
17240 KB |
Output is correct |
21 |
Correct |
6 ms |
19036 KB |
Output is correct |
22 |
Correct |
5 ms |
19016 KB |
Output is correct |
23 |
Correct |
5 ms |
16988 KB |
Output is correct |
24 |
Correct |
6 ms |
19048 KB |
Output is correct |
25 |
Correct |
5 ms |
19032 KB |
Output is correct |
26 |
Correct |
5 ms |
16988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
5 ms |
18780 KB |
Output is correct |
15 |
Correct |
2 ms |
14684 KB |
Output is correct |
16 |
Correct |
3 ms |
10840 KB |
Output is correct |
17 |
Correct |
1 ms |
4440 KB |
Output is correct |
18 |
Correct |
6 ms |
19036 KB |
Output is correct |
19 |
Correct |
6 ms |
19036 KB |
Output is correct |
20 |
Correct |
5 ms |
17240 KB |
Output is correct |
21 |
Correct |
6 ms |
19036 KB |
Output is correct |
22 |
Correct |
5 ms |
19016 KB |
Output is correct |
23 |
Correct |
5 ms |
16988 KB |
Output is correct |
24 |
Correct |
6 ms |
19048 KB |
Output is correct |
25 |
Correct |
5 ms |
19032 KB |
Output is correct |
26 |
Correct |
5 ms |
16988 KB |
Output is correct |
27 |
Correct |
177 ms |
88228 KB |
Output is correct |
28 |
Correct |
9 ms |
66136 KB |
Output is correct |
29 |
Correct |
10 ms |
11352 KB |
Output is correct |
30 |
Correct |
1 ms |
4696 KB |
Output is correct |
31 |
Correct |
121 ms |
76280 KB |
Output is correct |
32 |
Correct |
161 ms |
88520 KB |
Output is correct |
33 |
Correct |
168 ms |
88460 KB |
Output is correct |
34 |
Correct |
143 ms |
86612 KB |
Output is correct |
35 |
Correct |
155 ms |
88524 KB |
Output is correct |
36 |
Correct |
154 ms |
88896 KB |
Output is correct |
37 |
Correct |
177 ms |
88776 KB |
Output is correct |
38 |
Correct |
102 ms |
76372 KB |
Output is correct |
39 |
Correct |
100 ms |
76260 KB |
Output is correct |