#include <bits/stdc++.h>
using namespace std;
#define int long long
int sufr[3000][3000],sufc[3000][3000],val[3000][3000];
char ch;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int t=1,n,m;
// cin >> t;
while (t--){
cin >> n >> m;
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
cin >> ch;
if (ch == 'J'){
val[i][j] = 0;
}
if (ch == 'O'){
val[i][j] = 1;
}
if (ch == 'I'){
val[i][j] = 2;
}
}
}
// sufr[i][j] orbs in row i, after j
// sufc[i][j] ingots in column j, after i
for (int i = 0; i < n; i++){
sufr[i][m-1] = (val[i][m-1] == 1);
for (int j = m-2; j >= 0; j--){
sufr[i][j] = sufr[i][j+1] + (val[i][j] == 1);
}
}
for (int j = 0; j < m; j++){
sufc[n-1][j] = (val[n-1][j] == 2);
for (int i = n-2; i >= 0; i--){
sufc[i][j] = sufc[i+1][j] + (val[i][j] == 2);
}
}
int ans = 0;
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
if (!val[i][j]){
ans += (sufr[i][j]*sufc[i][j]);
}
}
}
cout << ans << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
1748 KB |
Output is correct |
6 |
Correct |
1 ms |
1620 KB |
Output is correct |
7 |
Correct |
1 ms |
1524 KB |
Output is correct |
8 |
Correct |
2 ms |
1748 KB |
Output is correct |
9 |
Correct |
1 ms |
1620 KB |
Output is correct |
10 |
Correct |
1 ms |
1620 KB |
Output is correct |
11 |
Correct |
1 ms |
1748 KB |
Output is correct |
12 |
Correct |
1 ms |
1620 KB |
Output is correct |
13 |
Correct |
1 ms |
1620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
1748 KB |
Output is correct |
6 |
Correct |
1 ms |
1620 KB |
Output is correct |
7 |
Correct |
1 ms |
1524 KB |
Output is correct |
8 |
Correct |
2 ms |
1748 KB |
Output is correct |
9 |
Correct |
1 ms |
1620 KB |
Output is correct |
10 |
Correct |
1 ms |
1620 KB |
Output is correct |
11 |
Correct |
1 ms |
1748 KB |
Output is correct |
12 |
Correct |
1 ms |
1620 KB |
Output is correct |
13 |
Correct |
1 ms |
1620 KB |
Output is correct |
14 |
Correct |
11 ms |
10884 KB |
Output is correct |
15 |
Correct |
2 ms |
5460 KB |
Output is correct |
16 |
Correct |
5 ms |
6484 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
14 ms |
12116 KB |
Output is correct |
19 |
Correct |
11 ms |
11988 KB |
Output is correct |
20 |
Correct |
10 ms |
11960 KB |
Output is correct |
21 |
Correct |
16 ms |
12380 KB |
Output is correct |
22 |
Correct |
12 ms |
12148 KB |
Output is correct |
23 |
Correct |
12 ms |
12116 KB |
Output is correct |
24 |
Correct |
14 ms |
12408 KB |
Output is correct |
25 |
Correct |
10 ms |
12252 KB |
Output is correct |
26 |
Correct |
9 ms |
12124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
1748 KB |
Output is correct |
6 |
Correct |
1 ms |
1620 KB |
Output is correct |
7 |
Correct |
1 ms |
1524 KB |
Output is correct |
8 |
Correct |
2 ms |
1748 KB |
Output is correct |
9 |
Correct |
1 ms |
1620 KB |
Output is correct |
10 |
Correct |
1 ms |
1620 KB |
Output is correct |
11 |
Correct |
1 ms |
1748 KB |
Output is correct |
12 |
Correct |
1 ms |
1620 KB |
Output is correct |
13 |
Correct |
1 ms |
1620 KB |
Output is correct |
14 |
Correct |
11 ms |
10884 KB |
Output is correct |
15 |
Correct |
2 ms |
5460 KB |
Output is correct |
16 |
Correct |
5 ms |
6484 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
14 ms |
12116 KB |
Output is correct |
19 |
Correct |
11 ms |
11988 KB |
Output is correct |
20 |
Correct |
10 ms |
11960 KB |
Output is correct |
21 |
Correct |
16 ms |
12380 KB |
Output is correct |
22 |
Correct |
12 ms |
12148 KB |
Output is correct |
23 |
Correct |
12 ms |
12116 KB |
Output is correct |
24 |
Correct |
14 ms |
12408 KB |
Output is correct |
25 |
Correct |
10 ms |
12252 KB |
Output is correct |
26 |
Correct |
9 ms |
12124 KB |
Output is correct |
27 |
Correct |
566 ms |
216316 KB |
Output is correct |
28 |
Correct |
13 ms |
28884 KB |
Output is correct |
29 |
Correct |
20 ms |
19148 KB |
Output is correct |
30 |
Correct |
2 ms |
984 KB |
Output is correct |
31 |
Correct |
358 ms |
181164 KB |
Output is correct |
32 |
Correct |
455 ms |
216452 KB |
Output is correct |
33 |
Correct |
388 ms |
215644 KB |
Output is correct |
34 |
Correct |
478 ms |
209516 KB |
Output is correct |
35 |
Correct |
509 ms |
216336 KB |
Output is correct |
36 |
Correct |
407 ms |
215876 KB |
Output is correct |
37 |
Correct |
604 ms |
216644 KB |
Output is correct |
38 |
Correct |
333 ms |
181052 KB |
Output is correct |
39 |
Correct |
330 ms |
180872 KB |
Output is correct |