#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define x first
#define y second
const int MOD = 1e9 + 7;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};
const char dir[] = {'R', 'L', 'D', 'U'};
int add(int a, int b){
a += b;
if(a >= MOD){
a -= MOD;
}
return a;
}
int sub(int a, int b){
a -= b;
if(a < 0) a += MOD;
return a;
}
int mult(int a, int b){
return ((ll) a * b) % MOD;
}
void setIO() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen((s+".in").c_str(),"r",stdin);
// freopen((s+".text").c_str(),"w",stdout);
}
//ctrl q is comment
//ctrl b is run
//ctrl s is compile
//alt r is search & replace
//alt d is delete a line
int main(){
setIO();
int h, w; cin >> h >> w;
int grid[h][w];
for(int i = 0; i < h; ++i){
string s; cin >> s;
for(int j = 0; j < w; ++j){
grid[i][j] = s[j] == 'J' ? 0 : s[j] == 'O' ? 1 : 2;
}
}
int suffo[h][w], suffi[h][w];
for(int i = 0; i < h; ++i){
for(int j = 0; j < w; ++j){
suffo[i][j] = 0;
suffi[i][j] = 0;
}
}
for(int i = 0; i < h; ++i){
for(int j = w - 1; j >= 0; --j){
suffo[i][j] = grid[i][j] == 1 ? 1 : 0;
if(j < w - 1) suffo[i][j] += suffo[i][j + 1];
}
}
for(int i = 0; i < w; ++i){
for(int j = h - 1; j >= 0; --j){
suffi[j][i] = grid[j][i] == 2 ? 1 : 0;
if(j < h - 1) suffi[j][i] += suffi[j + 1][i];
}
}
ll ans = 0;
for(int i = 0; i < h; ++i){
for(int j = 0; j < w; ++j){
if(!grid[i][j]) {
ans += (ll) suffo[i][j] * suffi[i][j];
}
}
}
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
0 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 |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
0 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 |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
6 ms |
2816 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
1920 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
7 ms |
3564 KB |
Output is correct |
19 |
Correct |
5 ms |
3328 KB |
Output is correct |
20 |
Correct |
5 ms |
3456 KB |
Output is correct |
21 |
Correct |
7 ms |
3456 KB |
Output is correct |
22 |
Correct |
5 ms |
3328 KB |
Output is correct |
23 |
Correct |
5 ms |
3456 KB |
Output is correct |
24 |
Correct |
8 ms |
3456 KB |
Output is correct |
25 |
Correct |
5 ms |
3328 KB |
Output is correct |
26 |
Correct |
5 ms |
3448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
0 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 |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
6 ms |
2816 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
1920 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
7 ms |
3564 KB |
Output is correct |
19 |
Correct |
5 ms |
3328 KB |
Output is correct |
20 |
Correct |
5 ms |
3456 KB |
Output is correct |
21 |
Correct |
7 ms |
3456 KB |
Output is correct |
22 |
Correct |
5 ms |
3328 KB |
Output is correct |
23 |
Correct |
5 ms |
3456 KB |
Output is correct |
24 |
Correct |
8 ms |
3456 KB |
Output is correct |
25 |
Correct |
5 ms |
3328 KB |
Output is correct |
26 |
Correct |
5 ms |
3448 KB |
Output is correct |
27 |
Correct |
387 ms |
108536 KB |
Output is correct |
28 |
Correct |
1 ms |
548 KB |
Output is correct |
29 |
Correct |
12 ms |
8576 KB |
Output is correct |
30 |
Correct |
1 ms |
640 KB |
Output is correct |
31 |
Correct |
284 ms |
79864 KB |
Output is correct |
32 |
Correct |
340 ms |
114040 KB |
Output is correct |
33 |
Correct |
334 ms |
114424 KB |
Output is correct |
34 |
Correct |
333 ms |
92556 KB |
Output is correct |
35 |
Correct |
351 ms |
114040 KB |
Output is correct |
36 |
Correct |
334 ms |
114424 KB |
Output is correct |
37 |
Correct |
418 ms |
114824 KB |
Output is correct |
38 |
Correct |
235 ms |
79264 KB |
Output is correct |
39 |
Correct |
253 ms |
79480 KB |
Output is correct |