#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <algorithm>
#include <math.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
ifstream in("input.txt");
ofstream out("output.txt");
typedef long long ll;
int h,w;
char tab[5000][5000];
ll prefb[5000][5000];
ll fb[5000];
ll f[5000];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>h>>w;
ll sumf;
ll tot=0;
for(int i=0;i<h;i++){
ll sum=0;
for(int y=0;y<w;y++){
cin>>tab[i][y];
if(i!=0&&tab[i-1][y]=='J')fb[y]+=sumf-prefb[i-1][y];
if(tab[i][y]=='O')sum++;
else if(tab[i][y]=='I'){
f[y]++;
}
else{
tot+=f[y]*fb[y];
f[y]=0;
}
if(tab[i][y]!='J'&&i==h-1){
tot+=f[y]*fb[y];
}
prefb[i][y]=sum;
}
sumf=sum;
}
printf("%lld",tot);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
1276 KB |
Output is correct |
6 |
Correct |
2 ms |
1272 KB |
Output is correct |
7 |
Correct |
3 ms |
1144 KB |
Output is correct |
8 |
Correct |
3 ms |
1272 KB |
Output is correct |
9 |
Correct |
3 ms |
1272 KB |
Output is correct |
10 |
Correct |
3 ms |
1144 KB |
Output is correct |
11 |
Correct |
3 ms |
1272 KB |
Output is correct |
12 |
Correct |
3 ms |
1244 KB |
Output is correct |
13 |
Correct |
3 ms |
1144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
1276 KB |
Output is correct |
6 |
Correct |
2 ms |
1272 KB |
Output is correct |
7 |
Correct |
3 ms |
1144 KB |
Output is correct |
8 |
Correct |
3 ms |
1272 KB |
Output is correct |
9 |
Correct |
3 ms |
1272 KB |
Output is correct |
10 |
Correct |
3 ms |
1144 KB |
Output is correct |
11 |
Correct |
3 ms |
1272 KB |
Output is correct |
12 |
Correct |
3 ms |
1244 KB |
Output is correct |
13 |
Correct |
3 ms |
1144 KB |
Output is correct |
14 |
Correct |
12 ms |
6136 KB |
Output is correct |
15 |
Correct |
4 ms |
3836 KB |
Output is correct |
16 |
Correct |
6 ms |
3576 KB |
Output is correct |
17 |
Correct |
2 ms |
504 KB |
Output is correct |
18 |
Correct |
15 ms |
6520 KB |
Output is correct |
19 |
Correct |
11 ms |
6620 KB |
Output is correct |
20 |
Correct |
11 ms |
6392 KB |
Output is correct |
21 |
Correct |
15 ms |
6520 KB |
Output is correct |
22 |
Correct |
11 ms |
6620 KB |
Output is correct |
23 |
Correct |
10 ms |
6392 KB |
Output is correct |
24 |
Correct |
15 ms |
6520 KB |
Output is correct |
25 |
Correct |
11 ms |
6620 KB |
Output is correct |
26 |
Correct |
10 ms |
6480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
1276 KB |
Output is correct |
6 |
Correct |
2 ms |
1272 KB |
Output is correct |
7 |
Correct |
3 ms |
1144 KB |
Output is correct |
8 |
Correct |
3 ms |
1272 KB |
Output is correct |
9 |
Correct |
3 ms |
1272 KB |
Output is correct |
10 |
Correct |
3 ms |
1144 KB |
Output is correct |
11 |
Correct |
3 ms |
1272 KB |
Output is correct |
12 |
Correct |
3 ms |
1244 KB |
Output is correct |
13 |
Correct |
3 ms |
1144 KB |
Output is correct |
14 |
Correct |
12 ms |
6136 KB |
Output is correct |
15 |
Correct |
4 ms |
3836 KB |
Output is correct |
16 |
Correct |
6 ms |
3576 KB |
Output is correct |
17 |
Correct |
2 ms |
504 KB |
Output is correct |
18 |
Correct |
15 ms |
6520 KB |
Output is correct |
19 |
Correct |
11 ms |
6620 KB |
Output is correct |
20 |
Correct |
11 ms |
6392 KB |
Output is correct |
21 |
Correct |
15 ms |
6520 KB |
Output is correct |
22 |
Correct |
11 ms |
6620 KB |
Output is correct |
23 |
Correct |
10 ms |
6392 KB |
Output is correct |
24 |
Correct |
15 ms |
6520 KB |
Output is correct |
25 |
Correct |
11 ms |
6620 KB |
Output is correct |
26 |
Correct |
10 ms |
6480 KB |
Output is correct |
27 |
Correct |
349 ms |
93648 KB |
Output is correct |
28 |
Correct |
16 ms |
19292 KB |
Output is correct |
29 |
Correct |
20 ms |
7800 KB |
Output is correct |
30 |
Correct |
3 ms |
632 KB |
Output is correct |
31 |
Correct |
259 ms |
71640 KB |
Output is correct |
32 |
Correct |
253 ms |
97016 KB |
Output is correct |
33 |
Correct |
219 ms |
97372 KB |
Output is correct |
34 |
Correct |
304 ms |
90032 KB |
Output is correct |
35 |
Correct |
257 ms |
105824 KB |
Output is correct |
36 |
Correct |
224 ms |
106052 KB |
Output is correct |
37 |
Correct |
378 ms |
106460 KB |
Output is correct |
38 |
Correct |
168 ms |
77272 KB |
Output is correct |
39 |
Correct |
161 ms |
77304 KB |
Output is correct |