This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("-Ofast")
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <limits>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
using namespace std;
using ll = long long;
void solve(){
ll h, w;
cin >> h >> w;
vector<string> grid(h);
for(ll i = 0; i < h; i++){
cin >> grid[i];
}
ll total = 0;
vector<vector<pair<ll, ll>>> grid_val(h + 1, vector<pair<ll, ll>>(w + 1, pair<ll,ll>{0, 0})); // Orbs, Ignots
for(ll i = h - 1; i >= 0; i--){
for(ll j = w - 1; j >= 0; j--){
grid_val[i][j].first = grid_val[i][j + 1].first;
grid_val[i][j].second = grid_val[i + 1][j].second;
if(grid[i][j] == 'O'){
grid_val[i][j].first += 1;
}else if(grid[i][j] == 'I'){
grid_val[i][j].second += 1;
}else{
total += grid_val[i][j].first * grid_val[i][j].second;
}
}
}
cout << total << endl;
}
int main(){
ios_base::sync_with_stdio(false);
cout.tie(0);
cin.tie(0);
ll t = 1;
while(t--){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |