#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <ll , ll> pll;
#define fi first
#define se second
//#define int ll
const int intf = 2e9 , maxn = 1e5 + 5;
const ll inf = 2e18 , mod = 1e9 + 7;
void solve(){
int h , w;
cin >> h >> w;
vector < vector <int> > a;
vector < vector <int> > pref[3];
a = pref[0] = pref[1] = pref[2] = vector < vector <int> > (h , vector <int> (w , 0));
for (int i = 0; i < h; i ++){
for (int j = 0; j < w; j ++){
char c; cin >> c;
if (c == 'J'){
a[i][j] = 0;
} else if (c == 'O'){
a[i][j] = 1;
pref[1][i][j] = 1;
} else {
a[i][j] = 2;
pref[2][i][j] = 1;
}
}
}
for (int i = h - 1; i >= 0; i --){
for (int j = w - 1; j >= 0; j --){
if (j + 1 < w)
pref[1][i][j] += pref[1][i][j + 1];
if (i + 1 < h)
pref[2][i][j] += pref[2][i + 1][j];
}
}
ll ans = 0;
for (int i = 0; i < h; i ++){
for (int j = 0; j < w; j ++){
if (a[i][j] != 0)
continue;
ans += pref[1][i][j] * pref[2][i][j];
}
}
cout << ans << '\n';
}
signed main() {
//freopen("input.txt" , "r" , stdin);
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.precision(20);
int t = 1; //cin >> t;
while(t-->0){
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
13 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
13 |
Correct |
1 ms |
512 KB |
Output is correct |
14 |
Correct |
10 ms |
3584 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
6 ms |
2560 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
12 ms |
4608 KB |
Output is correct |
19 |
Correct |
10 ms |
4480 KB |
Output is correct |
20 |
Correct |
10 ms |
4512 KB |
Output is correct |
21 |
Correct |
12 ms |
4608 KB |
Output is correct |
22 |
Correct |
10 ms |
4352 KB |
Output is correct |
23 |
Correct |
10 ms |
4480 KB |
Output is correct |
24 |
Correct |
13 ms |
4608 KB |
Output is correct |
25 |
Correct |
10 ms |
4352 KB |
Output is correct |
26 |
Correct |
9 ms |
4480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
13 |
Correct |
1 ms |
512 KB |
Output is correct |
14 |
Correct |
10 ms |
3584 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
6 ms |
2560 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
12 ms |
4608 KB |
Output is correct |
19 |
Correct |
10 ms |
4480 KB |
Output is correct |
20 |
Correct |
10 ms |
4512 KB |
Output is correct |
21 |
Correct |
12 ms |
4608 KB |
Output is correct |
22 |
Correct |
10 ms |
4352 KB |
Output is correct |
23 |
Correct |
10 ms |
4480 KB |
Output is correct |
24 |
Correct |
13 ms |
4608 KB |
Output is correct |
25 |
Correct |
10 ms |
4352 KB |
Output is correct |
26 |
Correct |
9 ms |
4480 KB |
Output is correct |
27 |
Correct |
401 ms |
142328 KB |
Output is correct |
28 |
Correct |
2 ms |
1152 KB |
Output is correct |
29 |
Correct |
24 ms |
11136 KB |
Output is correct |
30 |
Correct |
2 ms |
768 KB |
Output is correct |
31 |
Correct |
294 ms |
104696 KB |
Output is correct |
32 |
Correct |
356 ms |
149752 KB |
Output is correct |
33 |
Correct |
323 ms |
150012 KB |
Output is correct |
34 |
Correct |
339 ms |
121336 KB |
Output is correct |
35 |
Correct |
364 ms |
149752 KB |
Output is correct |
36 |
Correct |
326 ms |
150008 KB |
Output is correct |
37 |
Correct |
426 ms |
150520 KB |
Output is correct |
38 |
Correct |
239 ms |
103928 KB |
Output is correct |
39 |
Correct |
224 ms |
104440 KB |
Output is correct |