#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
#define pb push_back
#define f first
#define s second
int main() {
int H, W;
cin >> H >> W;
int grid[H][W];
for (int i = 0; i < H; i++) {
string line;
cin >> line;
for (int j = 0; j < W; j++) {
grid[i][j] = line[j];
}
}
vi vCnts(W, 0);
ll ans = 0;
for (int i = H - 1; i >= 0; i--) {
int hCnt = 0;
for (int j = W - 1; j >= 0; j--) {
if (grid[i][j] == 'J') {
ans += (ll) hCnt * vCnts[j];
}
if (grid[i][j] == 'O') {
hCnt++;
}
if (grid[i][j] == 'I') {
vCnts[j]++;
}
}
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
380 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
380 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
16 ms |
1272 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
10 ms |
888 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
19 ms |
1528 KB |
Output is correct |
19 |
Correct |
17 ms |
1528 KB |
Output is correct |
20 |
Correct |
18 ms |
1528 KB |
Output is correct |
21 |
Correct |
19 ms |
1500 KB |
Output is correct |
22 |
Correct |
17 ms |
1528 KB |
Output is correct |
23 |
Correct |
17 ms |
1528 KB |
Output is correct |
24 |
Correct |
19 ms |
1524 KB |
Output is correct |
25 |
Correct |
17 ms |
1632 KB |
Output is correct |
26 |
Correct |
17 ms |
1528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
380 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
16 ms |
1272 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
10 ms |
888 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
19 ms |
1528 KB |
Output is correct |
19 |
Correct |
17 ms |
1528 KB |
Output is correct |
20 |
Correct |
18 ms |
1528 KB |
Output is correct |
21 |
Correct |
19 ms |
1500 KB |
Output is correct |
22 |
Correct |
17 ms |
1528 KB |
Output is correct |
23 |
Correct |
17 ms |
1528 KB |
Output is correct |
24 |
Correct |
19 ms |
1524 KB |
Output is correct |
25 |
Correct |
17 ms |
1632 KB |
Output is correct |
26 |
Correct |
17 ms |
1528 KB |
Output is correct |
27 |
Correct |
572 ms |
41924 KB |
Output is correct |
28 |
Correct |
4 ms |
376 KB |
Output is correct |
29 |
Correct |
43 ms |
3448 KB |
Output is correct |
30 |
Correct |
4 ms |
376 KB |
Output is correct |
31 |
Correct |
438 ms |
30860 KB |
Output is correct |
32 |
Correct |
549 ms |
44280 KB |
Output is correct |
33 |
Correct |
547 ms |
44408 KB |
Output is correct |
34 |
Correct |
489 ms |
35740 KB |
Output is correct |
35 |
Correct |
547 ms |
44152 KB |
Output is correct |
36 |
Correct |
549 ms |
44256 KB |
Output is correct |
37 |
Correct |
600 ms |
44448 KB |
Output is correct |
38 |
Correct |
379 ms |
30672 KB |
Output is correct |
39 |
Correct |
380 ms |
30840 KB |
Output is correct |