#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
#define endl "\n"
#define int ll
using ull=unsigned long long;
using ll=long long;
using pii=pair<int,int>;
const int mod=1e9+7;
#define OVL(x,s) for(auto y:x) cout<<y<<s; cout<<"\n";
template <typename T> istream& operator>>(istream& is, vector<T> &a) {
copy_n(istream_iterator<T>(is), a.size(), a.begin()); return is;}
#ifdef IOI
void dbg_out() { cout << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__);
#else
#define dbg(...) 1337;
#endif
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
const int mxn=2e5+100;
signed main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int n,m;
cin>>n>>m;
vector<string> v(n);
cin>>v;
map<char,int> mp;
mp['U']=0;
mp['J']=1;
mp['I']=2;
int ans=0;
int dp1[n][m][3];
memset(dp1,0,sizeof(dp1));
int dp2[n][m][3];
memset(dp2,0,sizeof(dp2));
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
dp1[i][j][mp[v[i][j]]]++;
for(int k=0;k<3;k++)
if(j)
dp1[i][j][k]+=dp1[i][j-1][k];
}
for(int j=0;j<m;j++){
dp2[i][j][mp[v[i][j]]]++;
if(i){
for(int k=0;k<3;k++){
dp2[i][j][k]+=dp2[i-1][j][k];
}
}
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(v[i][j]!='J') continue;
int a=dp1[i][m-1][mp['O']]-(j?dp1[i][j-1][mp['O']]:0LL);
int b=dp2[n-1][j][mp['I']]-(i?dp2[i-1][j][mp['I']]:0LL);
ans+=a*b;
// dbg(a,b,dp1[i][n-1][mp['O']])
}
}
cout<<ans<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
860 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
860 KB |
Output is correct |
8 |
Correct |
1 ms |
860 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Correct |
1 ms |
856 KB |
Output is correct |
11 |
Correct |
1 ms |
860 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
860 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
860 KB |
Output is correct |
8 |
Correct |
1 ms |
860 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Correct |
1 ms |
856 KB |
Output is correct |
11 |
Correct |
1 ms |
860 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
860 KB |
Output is correct |
14 |
Correct |
11 ms |
9820 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
6 ms |
6748 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
15 ms |
12636 KB |
Output is correct |
19 |
Correct |
10 ms |
12124 KB |
Output is correct |
20 |
Correct |
10 ms |
12460 KB |
Output is correct |
21 |
Correct |
15 ms |
12636 KB |
Output is correct |
22 |
Correct |
15 ms |
12124 KB |
Output is correct |
23 |
Correct |
10 ms |
12380 KB |
Output is correct |
24 |
Correct |
15 ms |
12608 KB |
Output is correct |
25 |
Correct |
10 ms |
12124 KB |
Output is correct |
26 |
Correct |
10 ms |
12632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
860 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
860 KB |
Output is correct |
8 |
Correct |
1 ms |
860 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Correct |
1 ms |
856 KB |
Output is correct |
11 |
Correct |
1 ms |
860 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
860 KB |
Output is correct |
14 |
Correct |
11 ms |
9820 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
6 ms |
6748 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
15 ms |
12636 KB |
Output is correct |
19 |
Correct |
10 ms |
12124 KB |
Output is correct |
20 |
Correct |
10 ms |
12460 KB |
Output is correct |
21 |
Correct |
15 ms |
12636 KB |
Output is correct |
22 |
Correct |
15 ms |
12124 KB |
Output is correct |
23 |
Correct |
10 ms |
12380 KB |
Output is correct |
24 |
Correct |
15 ms |
12608 KB |
Output is correct |
25 |
Correct |
10 ms |
12124 KB |
Output is correct |
26 |
Correct |
10 ms |
12632 KB |
Output is correct |
27 |
Runtime error |
184 ms |
274432 KB |
Execution killed with signal 9 |
28 |
Halted |
0 ms |
0 KB |
- |