#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define INF 1e9+7
#define all(x) x.begin(),x.end()
using namespace std;
using namespace __gnu_pbds;
using ll=long long;
using pii=pair<int,int>;
using ppi=pair<int,pii>;
using oset=tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>;
template<typename T>
void _print(vector<T> x) {for(auto e:x) cerr<<e<<",";}
template<typename T>
void _print(T x) {cerr<<x;}
void dbg() {cerr<<endl;}
template<typename Head,typename... Tail>
void dbg(Head H,Tail... T) {
_print(H);
if(sizeof...(T)) cerr<<",";
else cerr<<"\"]";
dbg(T...);
}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:[\"",dbg(__VA_ARGS__)
int m,n;
char a[3002][3002];
int dp[3002][3002][2];
int dm[4]={-1,0,1,0}; int dn[4]={0,1,0,-1};
map<char,int> hsh;
int main () {
ios::sync_with_stdio(false); cin.tie(0);
hsh['O']=0; hsh['I']=1; hsh['J']=2;
cin>>m>>n;
for(int i=1;i<=m;i++) {
for(int j=1;j<=n;j++) {
cin>>a[i][j];
}
}
for(int i=1;i<=m;i++) {
for(int j=n;j>=1;j--) {
dp[i][j][0]=dp[i][j+1][0]+(a[i][j]=='O');
}
}
for(int j=1;j<=n;j++) {
for(int i=m;i>=1;i--) {
dp[i][j][1]=dp[i+1][j][1]+(a[i][j]=='I');
}
}
ll ans=0;
for(int i=1;i<=m;i++) {
for(int j=1;j<=n;j++) {
if(a[i][j]=='J') {
ans+=dp[i][j+1][hsh['O']]*dp[i+1][j][hsh['I']];
}
}
}
cout<<ans<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
1132 KB |
Output is correct |
6 |
Correct |
1 ms |
1132 KB |
Output is correct |
7 |
Correct |
1 ms |
1004 KB |
Output is correct |
8 |
Correct |
1 ms |
1132 KB |
Output is correct |
9 |
Correct |
1 ms |
1132 KB |
Output is correct |
10 |
Correct |
1 ms |
1004 KB |
Output is correct |
11 |
Correct |
1 ms |
1132 KB |
Output is correct |
12 |
Correct |
1 ms |
1132 KB |
Output is correct |
13 |
Correct |
2 ms |
1004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
1132 KB |
Output is correct |
6 |
Correct |
1 ms |
1132 KB |
Output is correct |
7 |
Correct |
1 ms |
1004 KB |
Output is correct |
8 |
Correct |
1 ms |
1132 KB |
Output is correct |
9 |
Correct |
1 ms |
1132 KB |
Output is correct |
10 |
Correct |
1 ms |
1004 KB |
Output is correct |
11 |
Correct |
1 ms |
1132 KB |
Output is correct |
12 |
Correct |
1 ms |
1132 KB |
Output is correct |
13 |
Correct |
2 ms |
1004 KB |
Output is correct |
14 |
Correct |
9 ms |
5484 KB |
Output is correct |
15 |
Correct |
2 ms |
3308 KB |
Output is correct |
16 |
Correct |
5 ms |
3308 KB |
Output is correct |
17 |
Correct |
1 ms |
492 KB |
Output is correct |
18 |
Correct |
11 ms |
5996 KB |
Output is correct |
19 |
Correct |
10 ms |
5996 KB |
Output is correct |
20 |
Correct |
10 ms |
5868 KB |
Output is correct |
21 |
Correct |
11 ms |
5996 KB |
Output is correct |
22 |
Correct |
10 ms |
5996 KB |
Output is correct |
23 |
Correct |
10 ms |
5868 KB |
Output is correct |
24 |
Correct |
13 ms |
5996 KB |
Output is correct |
25 |
Correct |
10 ms |
5996 KB |
Output is correct |
26 |
Correct |
10 ms |
5868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
1132 KB |
Output is correct |
6 |
Correct |
1 ms |
1132 KB |
Output is correct |
7 |
Correct |
1 ms |
1004 KB |
Output is correct |
8 |
Correct |
1 ms |
1132 KB |
Output is correct |
9 |
Correct |
1 ms |
1132 KB |
Output is correct |
10 |
Correct |
1 ms |
1004 KB |
Output is correct |
11 |
Correct |
1 ms |
1132 KB |
Output is correct |
12 |
Correct |
1 ms |
1132 KB |
Output is correct |
13 |
Correct |
2 ms |
1004 KB |
Output is correct |
14 |
Correct |
9 ms |
5484 KB |
Output is correct |
15 |
Correct |
2 ms |
3308 KB |
Output is correct |
16 |
Correct |
5 ms |
3308 KB |
Output is correct |
17 |
Correct |
1 ms |
492 KB |
Output is correct |
18 |
Correct |
11 ms |
5996 KB |
Output is correct |
19 |
Correct |
10 ms |
5996 KB |
Output is correct |
20 |
Correct |
10 ms |
5868 KB |
Output is correct |
21 |
Correct |
11 ms |
5996 KB |
Output is correct |
22 |
Correct |
10 ms |
5996 KB |
Output is correct |
23 |
Correct |
10 ms |
5868 KB |
Output is correct |
24 |
Correct |
13 ms |
5996 KB |
Output is correct |
25 |
Correct |
10 ms |
5996 KB |
Output is correct |
26 |
Correct |
10 ms |
5868 KB |
Output is correct |
27 |
Correct |
438 ms |
88068 KB |
Output is correct |
28 |
Correct |
12 ms |
16748 KB |
Output is correct |
29 |
Correct |
22 ms |
7780 KB |
Output is correct |
30 |
Correct |
2 ms |
620 KB |
Output is correct |
31 |
Correct |
323 ms |
72676 KB |
Output is correct |
32 |
Correct |
418 ms |
88636 KB |
Output is correct |
33 |
Correct |
429 ms |
88292 KB |
Output is correct |
34 |
Correct |
378 ms |
84216 KB |
Output is correct |
35 |
Correct |
435 ms |
88548 KB |
Output is correct |
36 |
Correct |
427 ms |
88164 KB |
Output is correct |
37 |
Correct |
468 ms |
88440 KB |
Output is correct |
38 |
Correct |
297 ms |
72292 KB |
Output is correct |
39 |
Correct |
296 ms |
72292 KB |
Output is correct |