#include <bits/stdc++.h>
using namespace std;
#define int int64_t
void calc(vector<vector<int>> &aha, int h, int w, bool how){
if(how){
for(int i=h-1;i>=0;i--){
for(int j=w-2;j>=0;j--){
aha[i][j]+=aha[i][j+1];
}
}
return;
}
for(int i=w-1;i>=0;i--){
for(int j=h-2;j>=0;j--){
aha[j][i]+=aha[j+1][i];
}
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int h,w;
cin>>h>>w;
vector<string> grid(h);
vector<vector<int>> orbs(h,vector<int> (w,0));
vector<vector<int>> ingots(h,vector<int> (w,0));
for(int i=0;i<h;i++){
cin>>grid[i];
for(int j=0;j<w;j++){
if(grid[i][j]=='O'){
orbs[i][j]++;
}else if(grid[i][j]=='I'){
ingots[i][j]++;
}
}
}
calc(orbs,h,w,true);
calc(ingots,h,w,false);
int sum=0;
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(grid[i][j]=='J'){
sum+=orbs[i][j]*ingots[i][j];
}
}
}
cout<<sum<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
1 ms |
452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
1 ms |
452 KB |
Output is correct |
14 |
Correct |
6 ms |
3748 KB |
Output is correct |
15 |
Correct |
1 ms |
296 KB |
Output is correct |
16 |
Correct |
4 ms |
2508 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
9 ms |
4676 KB |
Output is correct |
19 |
Correct |
6 ms |
4612 KB |
Output is correct |
20 |
Correct |
6 ms |
4684 KB |
Output is correct |
21 |
Correct |
8 ms |
4688 KB |
Output is correct |
22 |
Correct |
6 ms |
4556 KB |
Output is correct |
23 |
Correct |
6 ms |
4684 KB |
Output is correct |
24 |
Correct |
8 ms |
4788 KB |
Output is correct |
25 |
Correct |
6 ms |
4556 KB |
Output is correct |
26 |
Correct |
6 ms |
4620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
1 ms |
452 KB |
Output is correct |
14 |
Correct |
6 ms |
3748 KB |
Output is correct |
15 |
Correct |
1 ms |
296 KB |
Output is correct |
16 |
Correct |
4 ms |
2508 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
9 ms |
4676 KB |
Output is correct |
19 |
Correct |
6 ms |
4612 KB |
Output is correct |
20 |
Correct |
6 ms |
4684 KB |
Output is correct |
21 |
Correct |
8 ms |
4688 KB |
Output is correct |
22 |
Correct |
6 ms |
4556 KB |
Output is correct |
23 |
Correct |
6 ms |
4684 KB |
Output is correct |
24 |
Correct |
8 ms |
4788 KB |
Output is correct |
25 |
Correct |
6 ms |
4556 KB |
Output is correct |
26 |
Correct |
6 ms |
4620 KB |
Output is correct |
27 |
Correct |
302 ms |
147488 KB |
Output is correct |
28 |
Correct |
1 ms |
844 KB |
Output is correct |
29 |
Correct |
13 ms |
11724 KB |
Output is correct |
30 |
Correct |
1 ms |
716 KB |
Output is correct |
31 |
Correct |
222 ms |
109936 KB |
Output is correct |
32 |
Correct |
242 ms |
154948 KB |
Output is correct |
33 |
Correct |
231 ms |
155580 KB |
Output is correct |
34 |
Correct |
256 ms |
126660 KB |
Output is correct |
35 |
Correct |
241 ms |
155072 KB |
Output is correct |
36 |
Correct |
234 ms |
155656 KB |
Output is correct |
37 |
Correct |
328 ms |
156108 KB |
Output is correct |
38 |
Correct |
169 ms |
109040 KB |
Output is correct |
39 |
Correct |
162 ms |
109392 KB |
Output is correct |