This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |