#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define pii pair<ll,ll>
ll psi[3001][3001], pso[3001][3001];
int main(){
ll ans=0;
ll n, m;
cin >> n >> m;
char c[n+1][m+1];
vector <pii> pos;
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
cin >> c[i][j];
if(j>0) pso[i][j]=pso[i][j-1];
if(i>0) psi[i][j]=psi[i-1][j];
if(c[i][j] == 'J') pos.pb({i,j});
else if(c[i][j] == 'O'){
if(j>0) pso[i][j]++;
else pso[i][j]=1;
}
else{
if(i>0) psi[i][j]++;
else psi[i][j]=1;
}
}
}
// for(int i=0; i<n; i++){
// cout << psi[i][0] << " ";
// }
for(auto x:pos){
ll a=x.ff, b=x.ss;
ll I=psi[n-1][b]-psi[a][b], O=pso[a][m-1]-pso[a][b];
// cout << I*O << endl;
ans+=I*O;
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2396 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 |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
3164 KB |
Output is correct |
8 |
Correct |
1 ms |
5152 KB |
Output is correct |
9 |
Correct |
1 ms |
3164 KB |
Output is correct |
10 |
Correct |
1 ms |
3164 KB |
Output is correct |
11 |
Correct |
1 ms |
7004 KB |
Output is correct |
12 |
Correct |
1 ms |
6748 KB |
Output is correct |
13 |
Correct |
1 ms |
3164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2396 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 |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
3164 KB |
Output is correct |
8 |
Correct |
1 ms |
5152 KB |
Output is correct |
9 |
Correct |
1 ms |
3164 KB |
Output is correct |
10 |
Correct |
1 ms |
3164 KB |
Output is correct |
11 |
Correct |
1 ms |
7004 KB |
Output is correct |
12 |
Correct |
1 ms |
6748 KB |
Output is correct |
13 |
Correct |
1 ms |
3164 KB |
Output is correct |
14 |
Correct |
11 ms |
20432 KB |
Output is correct |
15 |
Correct |
2 ms |
12636 KB |
Output is correct |
16 |
Correct |
6 ms |
13008 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
14 ms |
19684 KB |
Output is correct |
19 |
Correct |
11 ms |
25600 KB |
Output is correct |
20 |
Correct |
11 ms |
17868 KB |
Output is correct |
21 |
Correct |
14 ms |
22472 KB |
Output is correct |
22 |
Correct |
13 ms |
18124 KB |
Output is correct |
23 |
Correct |
12 ms |
17864 KB |
Output is correct |
24 |
Correct |
14 ms |
24280 KB |
Output is correct |
25 |
Correct |
10 ms |
24276 KB |
Output is correct |
26 |
Correct |
11 ms |
17928 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2396 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 |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
3164 KB |
Output is correct |
8 |
Correct |
1 ms |
5152 KB |
Output is correct |
9 |
Correct |
1 ms |
3164 KB |
Output is correct |
10 |
Correct |
1 ms |
3164 KB |
Output is correct |
11 |
Correct |
1 ms |
7004 KB |
Output is correct |
12 |
Correct |
1 ms |
6748 KB |
Output is correct |
13 |
Correct |
1 ms |
3164 KB |
Output is correct |
14 |
Correct |
11 ms |
20432 KB |
Output is correct |
15 |
Correct |
2 ms |
12636 KB |
Output is correct |
16 |
Correct |
6 ms |
13008 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
14 ms |
19684 KB |
Output is correct |
19 |
Correct |
11 ms |
25600 KB |
Output is correct |
20 |
Correct |
11 ms |
17868 KB |
Output is correct |
21 |
Correct |
14 ms |
22472 KB |
Output is correct |
22 |
Correct |
13 ms |
18124 KB |
Output is correct |
23 |
Correct |
12 ms |
17864 KB |
Output is correct |
24 |
Correct |
14 ms |
24280 KB |
Output is correct |
25 |
Correct |
10 ms |
24276 KB |
Output is correct |
26 |
Correct |
11 ms |
17928 KB |
Output is correct |
27 |
Correct |
392 ms |
193668 KB |
Output is correct |
28 |
Correct |
10 ms |
63700 KB |
Output is correct |
29 |
Correct |
23 ms |
19164 KB |
Output is correct |
30 |
Correct |
2 ms |
2908 KB |
Output is correct |
31 |
Correct |
295 ms |
162992 KB |
Output is correct |
32 |
Correct |
361 ms |
172336 KB |
Output is correct |
33 |
Correct |
329 ms |
205464 KB |
Output is correct |
34 |
Correct |
347 ms |
199836 KB |
Output is correct |
35 |
Correct |
396 ms |
204440 KB |
Output is correct |
36 |
Correct |
318 ms |
205208 KB |
Output is correct |
37 |
Correct |
412 ms |
215268 KB |
Output is correct |
38 |
Correct |
204 ms |
142756 KB |
Output is correct |
39 |
Correct |
199 ms |
161944 KB |
Output is correct |