#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
#define __TIME (1.0 * clock() / CLOCKS_PER_SEC)
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
const int N = 3e3 + 5;
const int oo = 1e9, mod = 1e9 + 7;
int n, m, preO[N][N], preI[N][N], res=0;
char s[N][N];
void process() {
cin >> n >> m;
foru(i, 1, n) {
foru(j, 1, m) {
cin >> s[i][j];
}
}
foru(i, 1, n) {
ford(j, m, 1) {
preO[i][j] = preO[i][j + 1] + (s[i][j] == 'O');
}
}
ford(i, n, 1) {
foru(j, 1, m) {
preI[i][j] = preI[i + 1][j] + (s[i][j] == 'I');
}
}
foru(i,1,n-1) {
foru(j,1,m-1) {
if (s[i][j]=='J') res+=(preO[i][j] * preI[i][j]);
}
}
cout << res;
return;
}
signed main() {
cin.tie(0)->sync_with_stdio(false);
//freopen(".inp", "r", stdin);
//freopen(".out", "w", stdout);
process();
cerr << "Time elapsed: " << __TIME << " s.\n";
return 0;
}
/*
Xét các trường hợp đặc biệt
Kiểm tra lại input/output
Cố gắng trâu
Lật ngược bài toán
Keep calm and get VOI
Flow:
*/
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
5212 KB |
Output is correct |
6 |
Correct |
1 ms |
5212 KB |
Output is correct |
7 |
Correct |
1 ms |
5212 KB |
Output is correct |
8 |
Correct |
1 ms |
5212 KB |
Output is correct |
9 |
Correct |
1 ms |
5460 KB |
Output is correct |
10 |
Correct |
1 ms |
5212 KB |
Output is correct |
11 |
Correct |
1 ms |
5328 KB |
Output is correct |
12 |
Correct |
1 ms |
5212 KB |
Output is correct |
13 |
Correct |
1 ms |
5212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
5212 KB |
Output is correct |
6 |
Correct |
1 ms |
5212 KB |
Output is correct |
7 |
Correct |
1 ms |
5212 KB |
Output is correct |
8 |
Correct |
1 ms |
5212 KB |
Output is correct |
9 |
Correct |
1 ms |
5460 KB |
Output is correct |
10 |
Correct |
1 ms |
5212 KB |
Output is correct |
11 |
Correct |
1 ms |
5328 KB |
Output is correct |
12 |
Correct |
1 ms |
5212 KB |
Output is correct |
13 |
Correct |
1 ms |
5212 KB |
Output is correct |
14 |
Correct |
6 ms |
17244 KB |
Output is correct |
15 |
Correct |
3 ms |
14680 KB |
Output is correct |
16 |
Correct |
4 ms |
11096 KB |
Output is correct |
17 |
Correct |
0 ms |
604 KB |
Output is correct |
18 |
Correct |
7 ms |
17756 KB |
Output is correct |
19 |
Correct |
6 ms |
17496 KB |
Output is correct |
20 |
Correct |
6 ms |
17668 KB |
Output is correct |
21 |
Correct |
7 ms |
17756 KB |
Output is correct |
22 |
Correct |
6 ms |
17500 KB |
Output is correct |
23 |
Correct |
6 ms |
17500 KB |
Output is correct |
24 |
Correct |
7 ms |
17824 KB |
Output is correct |
25 |
Correct |
7 ms |
17524 KB |
Output is correct |
26 |
Correct |
7 ms |
17500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
5212 KB |
Output is correct |
6 |
Correct |
1 ms |
5212 KB |
Output is correct |
7 |
Correct |
1 ms |
5212 KB |
Output is correct |
8 |
Correct |
1 ms |
5212 KB |
Output is correct |
9 |
Correct |
1 ms |
5460 KB |
Output is correct |
10 |
Correct |
1 ms |
5212 KB |
Output is correct |
11 |
Correct |
1 ms |
5328 KB |
Output is correct |
12 |
Correct |
1 ms |
5212 KB |
Output is correct |
13 |
Correct |
1 ms |
5212 KB |
Output is correct |
14 |
Correct |
6 ms |
17244 KB |
Output is correct |
15 |
Correct |
3 ms |
14680 KB |
Output is correct |
16 |
Correct |
4 ms |
11096 KB |
Output is correct |
17 |
Correct |
0 ms |
604 KB |
Output is correct |
18 |
Correct |
7 ms |
17756 KB |
Output is correct |
19 |
Correct |
6 ms |
17496 KB |
Output is correct |
20 |
Correct |
6 ms |
17668 KB |
Output is correct |
21 |
Correct |
7 ms |
17756 KB |
Output is correct |
22 |
Correct |
6 ms |
17500 KB |
Output is correct |
23 |
Correct |
6 ms |
17500 KB |
Output is correct |
24 |
Correct |
7 ms |
17824 KB |
Output is correct |
25 |
Correct |
7 ms |
17524 KB |
Output is correct |
26 |
Correct |
7 ms |
17500 KB |
Output is correct |
27 |
Correct |
168 ms |
158792 KB |
Output is correct |
28 |
Correct |
11 ms |
72028 KB |
Output is correct |
29 |
Correct |
11 ms |
16212 KB |
Output is correct |
30 |
Correct |
1 ms |
860 KB |
Output is correct |
31 |
Correct |
121 ms |
132840 KB |
Output is correct |
32 |
Correct |
149 ms |
159340 KB |
Output is correct |
33 |
Correct |
141 ms |
158704 KB |
Output is correct |
34 |
Correct |
145 ms |
152808 KB |
Output is correct |
35 |
Correct |
146 ms |
159060 KB |
Output is correct |
36 |
Correct |
150 ms |
158692 KB |
Output is correct |
37 |
Correct |
171 ms |
159060 KB |
Output is correct |
38 |
Correct |
108 ms |
132452 KB |
Output is correct |
39 |
Correct |
106 ms |
132952 KB |
Output is correct |