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 <algorithm>
#include <fstream>
#include <vector>
#include <queue>
#include <stack>
#include <iostream>
#include <cmath>
#include <queue>
#include <set>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#define F first
#define S second
#define PB push_back
using namespace std;
const long long MOD=1e9+7, INF=1e18;
const int INFI=1e9;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<pair<int, ii>> viii;
typedef vector<vii> vvii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int h, w; cin>>h>>w;
vector<vector<char>> grid(h+1, vector<char>(w+1));
vvi prefRow(h+1, vi(w+1, 0)), prefCol(h+1, vi(w+1, 0));
for(int i=1;i<=h;i++)
for(int j=1;j<=w;j++)
cin>>grid[i][j];
for(int i=1;i<=h;i++)
for(int j=1;j<=w;j++){
prefRow[i][j]=prefRow[i][j-1];
prefCol[i][j]=prefCol[i-1][j];
if(grid[i][j]=='O') prefRow[i][j]++;
if(grid[i][j]=='I') prefCol[i][j]++;
}
ll ans=0;
for(int i=1;i<=h;i++)
for(int j=1;j<=w;j++)
if(grid[i][j]=='J')
ans+=(prefRow[i][w]-prefRow[i][j])*(prefCol[h][j]-prefCol[i][j]);
cout<<ans<<"\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |