#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define se second
#define fi first
#define pii pair<int,int>
#define pll pair<long long, long long>
ll h,w,power=0;
vector<vector<char>> thingy;
pll os[3000][3000];
void solve(){
memset(os,0,sizeof(os));
cin >> h >> w;
for(int i=0; i<h; i++){
vector<char> bruh;
for(int j=0; j<w; j++){
char temp;
cin >> temp;
bruh.push_back(temp);
}
thingy.push_back(bruh);
}
for(int i=h-1; i>=0; i--){
for(int j=w-1; j>=0; j--){
if(thingy[i][j]=='I'){
if(i==h-1){
os[i][j].fi=1;
os[i][j].se=0;
}else{
os[i][j].fi=os[i+1][j].fi+1;
os[i][j].se=os[i][j+1].se;
}
}else if(thingy[i][j]=='O'){
if(j==w-1){
os[i][j].se=1;
os[i][j].fi=0;
}else{
os[i][j].se=os[i][j+1].se+1;
os[i][j].fi=os[i+1][j].fi;
}
}else{
if(j==w-1){
os[i][j].se=0;
}else{
os[i][j].se=os[i][j+1].se;
}
if(i==h-1){
os[i][j].fi=0;
}else{
os[i][j].fi=os[i+1][j].fi;
}
}
}
}
for(int i=0; i<h; i++){
for(int j=0; j<w; j++){
if(thingy[i][j]=='J'){
power+= os[i][j].fi*os[i][j].se;
}
}
}
cout << power << endl;
return;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
141156 KB |
Output is correct |
2 |
Correct |
47 ms |
141136 KB |
Output is correct |
3 |
Correct |
47 ms |
141104 KB |
Output is correct |
4 |
Correct |
48 ms |
141080 KB |
Output is correct |
5 |
Correct |
47 ms |
141124 KB |
Output is correct |
6 |
Correct |
49 ms |
141120 KB |
Output is correct |
7 |
Correct |
49 ms |
141216 KB |
Output is correct |
8 |
Correct |
49 ms |
141188 KB |
Output is correct |
9 |
Correct |
49 ms |
141172 KB |
Output is correct |
10 |
Correct |
52 ms |
141144 KB |
Output is correct |
11 |
Correct |
49 ms |
141216 KB |
Output is correct |
12 |
Correct |
49 ms |
141132 KB |
Output is correct |
13 |
Correct |
50 ms |
141112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
141156 KB |
Output is correct |
2 |
Correct |
47 ms |
141136 KB |
Output is correct |
3 |
Correct |
47 ms |
141104 KB |
Output is correct |
4 |
Correct |
48 ms |
141080 KB |
Output is correct |
5 |
Correct |
47 ms |
141124 KB |
Output is correct |
6 |
Correct |
49 ms |
141120 KB |
Output is correct |
7 |
Correct |
49 ms |
141216 KB |
Output is correct |
8 |
Correct |
49 ms |
141188 KB |
Output is correct |
9 |
Correct |
49 ms |
141172 KB |
Output is correct |
10 |
Correct |
52 ms |
141144 KB |
Output is correct |
11 |
Correct |
49 ms |
141216 KB |
Output is correct |
12 |
Correct |
49 ms |
141132 KB |
Output is correct |
13 |
Correct |
50 ms |
141112 KB |
Output is correct |
14 |
Correct |
53 ms |
141388 KB |
Output is correct |
15 |
Correct |
49 ms |
141184 KB |
Output is correct |
16 |
Correct |
54 ms |
141256 KB |
Output is correct |
17 |
Correct |
57 ms |
141172 KB |
Output is correct |
18 |
Correct |
54 ms |
141396 KB |
Output is correct |
19 |
Correct |
52 ms |
141376 KB |
Output is correct |
20 |
Correct |
52 ms |
141444 KB |
Output is correct |
21 |
Correct |
55 ms |
141408 KB |
Output is correct |
22 |
Correct |
53 ms |
141352 KB |
Output is correct |
23 |
Correct |
52 ms |
141388 KB |
Output is correct |
24 |
Correct |
53 ms |
141420 KB |
Output is correct |
25 |
Correct |
52 ms |
141400 KB |
Output is correct |
26 |
Correct |
53 ms |
141448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
141156 KB |
Output is correct |
2 |
Correct |
47 ms |
141136 KB |
Output is correct |
3 |
Correct |
47 ms |
141104 KB |
Output is correct |
4 |
Correct |
48 ms |
141080 KB |
Output is correct |
5 |
Correct |
47 ms |
141124 KB |
Output is correct |
6 |
Correct |
49 ms |
141120 KB |
Output is correct |
7 |
Correct |
49 ms |
141216 KB |
Output is correct |
8 |
Correct |
49 ms |
141188 KB |
Output is correct |
9 |
Correct |
49 ms |
141172 KB |
Output is correct |
10 |
Correct |
52 ms |
141144 KB |
Output is correct |
11 |
Correct |
49 ms |
141216 KB |
Output is correct |
12 |
Correct |
49 ms |
141132 KB |
Output is correct |
13 |
Correct |
50 ms |
141112 KB |
Output is correct |
14 |
Correct |
53 ms |
141388 KB |
Output is correct |
15 |
Correct |
49 ms |
141184 KB |
Output is correct |
16 |
Correct |
54 ms |
141256 KB |
Output is correct |
17 |
Correct |
57 ms |
141172 KB |
Output is correct |
18 |
Correct |
54 ms |
141396 KB |
Output is correct |
19 |
Correct |
52 ms |
141376 KB |
Output is correct |
20 |
Correct |
52 ms |
141444 KB |
Output is correct |
21 |
Correct |
55 ms |
141408 KB |
Output is correct |
22 |
Correct |
53 ms |
141352 KB |
Output is correct |
23 |
Correct |
52 ms |
141388 KB |
Output is correct |
24 |
Correct |
53 ms |
141420 KB |
Output is correct |
25 |
Correct |
52 ms |
141400 KB |
Output is correct |
26 |
Correct |
53 ms |
141448 KB |
Output is correct |
27 |
Runtime error |
264 ms |
274432 KB |
Execution killed with signal 11 |
28 |
Halted |
0 ms |
0 KB |
- |