#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pld pair<long double, int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define ff first
#define ss second
#define SZ(x) ((int)(x).size())
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MAXN = 3e3+100;
int H, W, a[MAXN][MAXN], cnt[2+1][MAXN][MAXN];
void read(){
cin >> H >> W;
for(int i = 0; i < H; i++){
string s; cin >> s;
for(int j = 0; j < W; j++){
if(s[j] == 'J')
a[i][j] = 0;
else if(s[j] == 'O')
a[i][j] = 1;
else if(s[j] == 'I')
a[i][j] = 2;
}
}
for(int i = 0; i < H; i++){
for(int j = W-1; j >= 0; j--){
cnt[1][i][j] += cnt[1][i][j+1];
if(a[i][j] == 1)
cnt[1][i][j]++;
}
}
for(int j = 0; j < W; j++){
for(int i = H-1; i >= 0; i--){
cnt[2][i][j] += cnt[2][i+1][j];
if(a[i][j] == 2)
cnt[2][i][j]++;
}
}
}
void solve(){
read();
ll ans = 0;
for(int i = 0; i < H; i++){
for(int j = 0; j < W; j++){
if(a[i][j] == 0){
ans += cnt[1][i][j] * cnt[2][i][j];
}
}
}
cout << ans;
}
int main(){
ios_base::sync_with_stdio(false);
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
1664 KB |
Output is correct |
6 |
Correct |
2 ms |
1664 KB |
Output is correct |
7 |
Correct |
1 ms |
1536 KB |
Output is correct |
8 |
Correct |
2 ms |
1664 KB |
Output is correct |
9 |
Correct |
1 ms |
1664 KB |
Output is correct |
10 |
Correct |
1 ms |
1536 KB |
Output is correct |
11 |
Correct |
2 ms |
1688 KB |
Output is correct |
12 |
Correct |
2 ms |
1664 KB |
Output is correct |
13 |
Correct |
1 ms |
1536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
1664 KB |
Output is correct |
6 |
Correct |
2 ms |
1664 KB |
Output is correct |
7 |
Correct |
1 ms |
1536 KB |
Output is correct |
8 |
Correct |
2 ms |
1664 KB |
Output is correct |
9 |
Correct |
1 ms |
1664 KB |
Output is correct |
10 |
Correct |
1 ms |
1536 KB |
Output is correct |
11 |
Correct |
2 ms |
1688 KB |
Output is correct |
12 |
Correct |
2 ms |
1664 KB |
Output is correct |
13 |
Correct |
1 ms |
1536 KB |
Output is correct |
14 |
Correct |
11 ms |
8832 KB |
Output is correct |
15 |
Correct |
4 ms |
5504 KB |
Output is correct |
16 |
Correct |
5 ms |
5120 KB |
Output is correct |
17 |
Correct |
1 ms |
512 KB |
Output is correct |
18 |
Correct |
13 ms |
9600 KB |
Output is correct |
19 |
Correct |
10 ms |
9472 KB |
Output is correct |
20 |
Correct |
10 ms |
9344 KB |
Output is correct |
21 |
Correct |
14 ms |
9600 KB |
Output is correct |
22 |
Correct |
11 ms |
9472 KB |
Output is correct |
23 |
Correct |
9 ms |
9344 KB |
Output is correct |
24 |
Correct |
13 ms |
9600 KB |
Output is correct |
25 |
Correct |
10 ms |
9472 KB |
Output is correct |
26 |
Correct |
10 ms |
9344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
1664 KB |
Output is correct |
6 |
Correct |
2 ms |
1664 KB |
Output is correct |
7 |
Correct |
1 ms |
1536 KB |
Output is correct |
8 |
Correct |
2 ms |
1664 KB |
Output is correct |
9 |
Correct |
1 ms |
1664 KB |
Output is correct |
10 |
Correct |
1 ms |
1536 KB |
Output is correct |
11 |
Correct |
2 ms |
1688 KB |
Output is correct |
12 |
Correct |
2 ms |
1664 KB |
Output is correct |
13 |
Correct |
1 ms |
1536 KB |
Output is correct |
14 |
Correct |
11 ms |
8832 KB |
Output is correct |
15 |
Correct |
4 ms |
5504 KB |
Output is correct |
16 |
Correct |
5 ms |
5120 KB |
Output is correct |
17 |
Correct |
1 ms |
512 KB |
Output is correct |
18 |
Correct |
13 ms |
9600 KB |
Output is correct |
19 |
Correct |
10 ms |
9472 KB |
Output is correct |
20 |
Correct |
10 ms |
9344 KB |
Output is correct |
21 |
Correct |
14 ms |
9600 KB |
Output is correct |
22 |
Correct |
11 ms |
9472 KB |
Output is correct |
23 |
Correct |
9 ms |
9344 KB |
Output is correct |
24 |
Correct |
13 ms |
9600 KB |
Output is correct |
25 |
Correct |
10 ms |
9472 KB |
Output is correct |
26 |
Correct |
10 ms |
9344 KB |
Output is correct |
27 |
Correct |
449 ms |
118008 KB |
Output is correct |
28 |
Correct |
20 ms |
28672 KB |
Output is correct |
29 |
Correct |
13 ms |
10368 KB |
Output is correct |
30 |
Correct |
1 ms |
768 KB |
Output is correct |
31 |
Correct |
332 ms |
97528 KB |
Output is correct |
32 |
Correct |
359 ms |
118264 KB |
Output is correct |
33 |
Correct |
348 ms |
117916 KB |
Output is correct |
34 |
Correct |
371 ms |
113028 KB |
Output is correct |
35 |
Correct |
360 ms |
118392 KB |
Output is correct |
36 |
Correct |
359 ms |
118008 KB |
Output is correct |
37 |
Correct |
483 ms |
118292 KB |
Output is correct |
38 |
Correct |
275 ms |
97452 KB |
Output is correct |
39 |
Correct |
252 ms |
97124 KB |
Output is correct |