#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
using ll= long long;
#define fast_io ios::sync_with_stdio(0); cin.tie(0)
#define inpint(x) int x; cin>>x
#define inpll(x) long long x; cin>>x
#define fl(i, n) for(int i=0; i<n; i++)
#define flo(i, n) for(int i=1; i<=n; i++)
#define int long long
#define pi pair<int, int>
#define mp make_pair
#define ld long double
const int MOD = 7 + (int)1e9;
const int INF = (int)1e18;
//
void solve()
{
int h, w;
cin>>h>>w;
// jewel on the square (i, j), an orb on the
//square (i, ℓ) and an ingot on
//the square (k, j)
vector<vector<int>> grid(h+2, vector<int>(w+2));
vector<vector<int>> jp(h+2, vector<int>(w+2, 0));
vector<vector<int>> op(h+2, vector<int>(w+2, 0));
int ans = 0;
for(int i=1; i<=h; i++)
{
string s;
cin>>s;
for(int j=1; j<=w; j++)
{
if(s[j-1]=='J') grid[i][j] = 0;
else if(s[j-1]=='O') grid[i][j] = 1;
else grid[i][j] = 2;
}
}
for(int i=1; i<=h; i++)
{
for(int j=w; j>0; j--)
{
jp[i][j] = jp[i][j+1];
op[i][j] = op[i-1][j];
if(grid[i][j]==1) jp[i][j]++;
else if(grid[i][j]==0) op[i][j] += jp[i][j];
else ans += op[i][j];
}
}
cout<<ans;
}
signed main()
{
fast_io;
int t=1;
//cin>>t;
while(t--)
{
solve();
}
cout<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
452 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
456 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
452 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
456 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
6 ms |
5096 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
4 ms |
3532 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
8 ms |
6564 KB |
Output is correct |
19 |
Correct |
5 ms |
6220 KB |
Output is correct |
20 |
Correct |
5 ms |
6348 KB |
Output is correct |
21 |
Correct |
7 ms |
6476 KB |
Output is correct |
22 |
Correct |
5 ms |
6228 KB |
Output is correct |
23 |
Correct |
5 ms |
6356 KB |
Output is correct |
24 |
Correct |
7 ms |
6472 KB |
Output is correct |
25 |
Correct |
5 ms |
6228 KB |
Output is correct |
26 |
Correct |
7 ms |
6436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
452 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
456 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
6 ms |
5096 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
4 ms |
3532 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
8 ms |
6564 KB |
Output is correct |
19 |
Correct |
5 ms |
6220 KB |
Output is correct |
20 |
Correct |
5 ms |
6348 KB |
Output is correct |
21 |
Correct |
7 ms |
6476 KB |
Output is correct |
22 |
Correct |
5 ms |
6228 KB |
Output is correct |
23 |
Correct |
5 ms |
6356 KB |
Output is correct |
24 |
Correct |
7 ms |
6472 KB |
Output is correct |
25 |
Correct |
5 ms |
6228 KB |
Output is correct |
26 |
Correct |
7 ms |
6436 KB |
Output is correct |
27 |
Correct |
212 ms |
208780 KB |
Output is correct |
28 |
Correct |
2 ms |
1236 KB |
Output is correct |
29 |
Correct |
12 ms |
16328 KB |
Output is correct |
30 |
Correct |
1 ms |
976 KB |
Output is correct |
31 |
Correct |
145 ms |
153620 KB |
Output is correct |
32 |
Correct |
144 ms |
219656 KB |
Output is correct |
33 |
Correct |
162 ms |
220296 KB |
Output is correct |
34 |
Correct |
165 ms |
178208 KB |
Output is correct |
35 |
Correct |
154 ms |
219656 KB |
Output is correct |
36 |
Correct |
155 ms |
220308 KB |
Output is correct |
37 |
Correct |
216 ms |
221004 KB |
Output is correct |
38 |
Correct |
107 ms |
152560 KB |
Output is correct |
39 |
Correct |
105 ms |
153028 KB |
Output is correct |