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>
#define pb push_back
#define f first
#define s second
#define rep(X, a,b) for(int X=a;X<b;++X)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) (int)(a).size()
#define NL "\n"
using namespace std;
typedef pair<long long,long long> pll;
typedef pair<int,int> pii;
typedef long long ll;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << "," << p.second << ')'; }
template<typename A> ostream& operator<<(ostream &os, const vector<A> &p){
for(const auto &a:p)
os << a << " ";
os << "\n";
return os;
}
int ocnt[3010][3010], icnt[3010][3010];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int h, w;
cin>>h>>w;
vector<string> grid(h);
rep(i,0,h){
cin>>grid[i];
for(int j=w-1;j>=0;--j) ocnt[i][j]=ocnt[i][j+1]+(grid[i][j]=='O');
}
rep(j,0,w){
for(int i=h-1;i>=0;--i) icnt[i][j]=icnt[i+1][j]+(grid[i][j]=='I');
}
ll ans=0;
rep(i,0,h){
rep(j,0,w) if(grid[i][j]=='J') ans+=ocnt[i][j+1]*icnt[i+1][j];
// rep(j,0,w) cout<<icnt[j]<<" ";
// cout<<NL;
}
cout<<ans<<NL;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |