#include <bits/stdc++.h>
using namespace std;
#define int long long int
int m, n;
using pii = pair<int,int>;
char a[3000][3000];
int32_t main(){
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin>>m>>n;
vector<pii>I;
for(int i = 0; i<m; ++i){
for(int j = 0; j<n; ++j){
cin>>a[i][j];
if(a[i][j] == 'I') I.push_back(make_pair(i, j));
}
}
int qsO[m][n];
memset(qsO, 0, sizeof(qsO));
for(int i = 0; i<m; ++i){
for(int j = n-1; j>=0; --j){
if(a[i][j] == 'O'){
qsO[i][j] = 1;
}
if(j<n-1) qsO[i][j] += qsO[i][j+1];
}
}
int qsJ[m][n];
memset(qsJ, 0, sizeof(qsJ));
//fix j
for(int j = 0; j<n; ++j){
for(int i = 0; i<m; ++i){
if(a[i][j] == 'J'){
qsJ[i][j] = qsO[i][j];
}
if(i>0) qsJ[i][j] += qsJ[i-1][j];
}
}
int ans = 0;
for(pii x: I){
ans += qsJ[x.first][x.second];
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
852 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
852 KB |
Output is correct |
10 |
Correct |
1 ms |
724 KB |
Output is correct |
11 |
Correct |
1 ms |
724 KB |
Output is correct |
12 |
Correct |
1 ms |
724 KB |
Output is correct |
13 |
Correct |
1 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
852 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
852 KB |
Output is correct |
10 |
Correct |
1 ms |
724 KB |
Output is correct |
11 |
Correct |
1 ms |
724 KB |
Output is correct |
12 |
Correct |
1 ms |
724 KB |
Output is correct |
13 |
Correct |
1 ms |
724 KB |
Output is correct |
14 |
Correct |
9 ms |
5840 KB |
Output is correct |
15 |
Correct |
1 ms |
1620 KB |
Output is correct |
16 |
Correct |
5 ms |
3920 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
11 ms |
7084 KB |
Output is correct |
19 |
Correct |
9 ms |
7172 KB |
Output is correct |
20 |
Correct |
12 ms |
6988 KB |
Output is correct |
21 |
Correct |
15 ms |
7132 KB |
Output is correct |
22 |
Correct |
11 ms |
6824 KB |
Output is correct |
23 |
Correct |
10 ms |
7020 KB |
Output is correct |
24 |
Correct |
13 ms |
6608 KB |
Output is correct |
25 |
Correct |
10 ms |
6348 KB |
Output is correct |
26 |
Correct |
11 ms |
7000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
852 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
852 KB |
Output is correct |
10 |
Correct |
1 ms |
724 KB |
Output is correct |
11 |
Correct |
1 ms |
724 KB |
Output is correct |
12 |
Correct |
1 ms |
724 KB |
Output is correct |
13 |
Correct |
1 ms |
724 KB |
Output is correct |
14 |
Correct |
9 ms |
5840 KB |
Output is correct |
15 |
Correct |
1 ms |
1620 KB |
Output is correct |
16 |
Correct |
5 ms |
3920 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
11 ms |
7084 KB |
Output is correct |
19 |
Correct |
9 ms |
7172 KB |
Output is correct |
20 |
Correct |
12 ms |
6988 KB |
Output is correct |
21 |
Correct |
15 ms |
7132 KB |
Output is correct |
22 |
Correct |
11 ms |
6824 KB |
Output is correct |
23 |
Correct |
10 ms |
7020 KB |
Output is correct |
24 |
Correct |
13 ms |
6608 KB |
Output is correct |
25 |
Correct |
10 ms |
6348 KB |
Output is correct |
26 |
Correct |
11 ms |
7000 KB |
Output is correct |
27 |
Correct |
448 ms |
187456 KB |
Output is correct |
28 |
Correct |
4 ms |
7768 KB |
Output is correct |
29 |
Correct |
20 ms |
14380 KB |
Output is correct |
30 |
Correct |
1 ms |
852 KB |
Output is correct |
31 |
Correct |
331 ms |
138900 KB |
Output is correct |
32 |
Correct |
394 ms |
205232 KB |
Output is correct |
33 |
Correct |
378 ms |
196452 KB |
Output is correct |
34 |
Correct |
395 ms |
160940 KB |
Output is correct |
35 |
Correct |
397 ms |
194712 KB |
Output is correct |
36 |
Correct |
373 ms |
196400 KB |
Output is correct |
37 |
Correct |
441 ms |
178360 KB |
Output is correct |
38 |
Correct |
248 ms |
123120 KB |
Output is correct |
39 |
Correct |
268 ms |
137704 KB |
Output is correct |