#include <bits/stdc++.h>
using namespace std;
int main(){
int h, w;
cin >> h >> w;
vector <string> grid;
for(int i = 0; i < h; i++){
string s;
cin >> s;
grid.push_back(s);
}
int O[h][w], I[h][w];
for(int i = 0; i < h; i++){
O[i][w - 1] = (grid[i][w - 1] == 'O')?1:0;
}
for(int i = 0; i < w; i++){
I[h - 1][i] = (grid[h - 1][i] == 'I')?1:0;
}
int cnt = 0;
for(int i = h - 2; i >= 0; i--){
for(int j = w - 2; j >= 0; j--){
switch(grid[i][j]){
case 'J':
I[i][j] = I[i + 1][j];
O[i][j] = O[i][j + 1];
cnt += I[i][j] * O[i][j];
break;
case 'O':
I[i][j] = I[i + 1][j];
O[i][j] = O[i][j + 1] + 1;
break;
case 'I':
I[i][j] = I[i + 1][j] + 1;
O[i][j] = O[i][j + 1];
break;
}
}
}
cout << cnt;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
6 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
6 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
6 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
6 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
17 ms |
2168 KB |
Output is correct |
15 |
Correct |
6 ms |
376 KB |
Output is correct |
16 |
Correct |
12 ms |
1528 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
21 ms |
2680 KB |
Output is correct |
19 |
Correct |
18 ms |
2556 KB |
Output is correct |
20 |
Incorrect |
18 ms |
2552 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
6 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
6 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
17 ms |
2168 KB |
Output is correct |
15 |
Correct |
6 ms |
376 KB |
Output is correct |
16 |
Correct |
12 ms |
1528 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
21 ms |
2680 KB |
Output is correct |
19 |
Correct |
18 ms |
2556 KB |
Output is correct |
20 |
Incorrect |
18 ms |
2552 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |