이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define eb emplace_back
#define vl vector<ll>
#define fi first
#define se second
#define in insert
#define mpr make_pair
#define lg(x) __lg(x)
#define bpc(x) __builtin_popcount(x)
#define all(v) v.begin(), v.end()
#define endl "\n"
using namespace std;
const int sz = 2e5+5;
const int mod = 998244353;
const ll inf = 1000000000000000;
void solve()
{
ll n, m, i, j;
cin>>n>>m;
char a[n+1][m+1];
ll sc[n+2][m+2], sr[n+2][m+2];
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
cin>>a[i][j];
}
}
for(i=1;i<=n;i++){sr[i][m+1] = 0;}
for(i=1;i<=m;i++){sc[n+1][i] = 0;}
ll ans = 0;
for(i=n;i>0;i--){
for(j=m;j>0;j--){
sr[i][j] = sr[i][j+1];
sc[i][j] = sc[i+1][j];
if(a[i][j] == 'O'){sr[i][j]++;}
else if(a[i][j] == 'I'){sc[i][j]++;}
else{
ans += (sr[i][j] * sc[i][j]);
}
}
}
/*for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
cout << sr[i][j] << ' ';
}
cout << endl;
}*/
cout << ans << endl;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//precomp();
ll tst=1;
//cin>>tst;
while(tst--){
solve();
}
}
/*
1
3 2
2 2 2
1 6
1 5
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |