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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
using namespace std;
using namespace __gnu_pbds;
#define FOR(i, x, y) for(ll i=x; i<y; i++)
#define FORNEG(i, x, y) for(ll i=x; i>y; i--)
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
ll prefx[3001][3001], prefy[3001][3001];
char grid[3001][3001];
int main(){
fast();
ll h,w;
cin >> h >> w;
FOR(i,0,h){
string temp;
cin >> temp;
FOR(j,0,w){
grid[i][j] = temp[j];
}
}
FOR(i,0,h){
FOR(j,0,w){
if (j==0){
if (grid[i][j]=='O') prefx[i][j] = 1;
}else{
prefx[i][j] = prefx[i][j-1] + (grid[i][j] == 'O');
}
}
}
FOR(i,0,h){
FOR(j,0,w){
if (i==0){
if (grid[i][j] == 'I') prefy[i][j] = 1;
}else{
prefy[i][j] = prefy[i-1][j] + (grid[i][j]=='I');
}
}
}
ll ans = 0;
FOR(i,0,h){
FOR(j,0,w){
if (grid[i][j] == 'J'){
ans += (prefx[i][w-1] - prefx[i][j])*(prefy[h-1][j] - prefy[i][j]);
}
}
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |