#include<bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> pii;
constexpr int maxh = 3e3;
ll typ[maxh][maxh] = { 0 },
orbs[maxh][maxh] = { 0 },
ingots[maxh][maxh] = { 0 };
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int h, w;
cin >> h >> w;
string s;
for (int y = 0; y < h; y++)
{
cin >> s;
for (int x = 0; x < w; x++) typ[x][y] = (s[x] == 'J' ? 1 : (s[x] == 'O' ? 2 : 3));
}
// Calculate orbs
for (int y = 0; y < h; y++)
{
orbs[w - 1][y] = (typ[w - 1][y] == 2);
for (int x = w - 2; x >= 0; x--) orbs[x][y] = orbs[x + 1][y] + (typ[x][y] == 2);
}
// Calculate ingots
for (int x = 0; x < w; x++)
{
ingots[x][h - 1] = (typ[x][h - 1] == 3);
for (int y = h - 2; y >= 0; y--) ingots[x][y] = ingots[x][y + 1] + (typ[x][y] == 3);
}
ll output = 0;
for (int x = 0; x < w; x++)
{
for (int y = 0; y < h; y++)
{
if (typ[x][y] == 1) output += ingots[x][y] * orbs[x][y];
}
}
cout << output << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
1748 KB |
Output is correct |
6 |
Correct |
1 ms |
1364 KB |
Output is correct |
7 |
Correct |
1 ms |
1748 KB |
Output is correct |
8 |
Correct |
1 ms |
1748 KB |
Output is correct |
9 |
Correct |
1 ms |
1364 KB |
Output is correct |
10 |
Correct |
1 ms |
1748 KB |
Output is correct |
11 |
Correct |
1 ms |
1748 KB |
Output is correct |
12 |
Correct |
1 ms |
1492 KB |
Output is correct |
13 |
Correct |
1 ms |
1748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
1748 KB |
Output is correct |
6 |
Correct |
1 ms |
1364 KB |
Output is correct |
7 |
Correct |
1 ms |
1748 KB |
Output is correct |
8 |
Correct |
1 ms |
1748 KB |
Output is correct |
9 |
Correct |
1 ms |
1364 KB |
Output is correct |
10 |
Correct |
1 ms |
1748 KB |
Output is correct |
11 |
Correct |
1 ms |
1748 KB |
Output is correct |
12 |
Correct |
1 ms |
1492 KB |
Output is correct |
13 |
Correct |
1 ms |
1748 KB |
Output is correct |
14 |
Correct |
7 ms |
9556 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
6 ms |
9420 KB |
Output is correct |
17 |
Correct |
2 ms |
3884 KB |
Output is correct |
18 |
Correct |
9 ms |
12340 KB |
Output is correct |
19 |
Correct |
8 ms |
11860 KB |
Output is correct |
20 |
Correct |
7 ms |
12256 KB |
Output is correct |
21 |
Correct |
9 ms |
12356 KB |
Output is correct |
22 |
Correct |
8 ms |
11920 KB |
Output is correct |
23 |
Correct |
7 ms |
12252 KB |
Output is correct |
24 |
Correct |
8 ms |
12408 KB |
Output is correct |
25 |
Correct |
6 ms |
11860 KB |
Output is correct |
26 |
Correct |
8 ms |
12244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
1748 KB |
Output is correct |
6 |
Correct |
1 ms |
1364 KB |
Output is correct |
7 |
Correct |
1 ms |
1748 KB |
Output is correct |
8 |
Correct |
1 ms |
1748 KB |
Output is correct |
9 |
Correct |
1 ms |
1364 KB |
Output is correct |
10 |
Correct |
1 ms |
1748 KB |
Output is correct |
11 |
Correct |
1 ms |
1748 KB |
Output is correct |
12 |
Correct |
1 ms |
1492 KB |
Output is correct |
13 |
Correct |
1 ms |
1748 KB |
Output is correct |
14 |
Correct |
7 ms |
9556 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
6 ms |
9420 KB |
Output is correct |
17 |
Correct |
2 ms |
3884 KB |
Output is correct |
18 |
Correct |
9 ms |
12340 KB |
Output is correct |
19 |
Correct |
8 ms |
11860 KB |
Output is correct |
20 |
Correct |
7 ms |
12256 KB |
Output is correct |
21 |
Correct |
9 ms |
12356 KB |
Output is correct |
22 |
Correct |
8 ms |
11920 KB |
Output is correct |
23 |
Correct |
7 ms |
12252 KB |
Output is correct |
24 |
Correct |
8 ms |
12408 KB |
Output is correct |
25 |
Correct |
6 ms |
11860 KB |
Output is correct |
26 |
Correct |
8 ms |
12244 KB |
Output is correct |
27 |
Correct |
339 ms |
208228 KB |
Output is correct |
28 |
Correct |
1 ms |
980 KB |
Output is correct |
29 |
Correct |
37 ms |
46176 KB |
Output is correct |
30 |
Correct |
12 ms |
28500 KB |
Output is correct |
31 |
Correct |
253 ms |
182540 KB |
Output is correct |
32 |
Correct |
334 ms |
218960 KB |
Output is correct |
33 |
Correct |
331 ms |
220384 KB |
Output is correct |
34 |
Correct |
286 ms |
183500 KB |
Output is correct |
35 |
Correct |
329 ms |
219004 KB |
Output is correct |
36 |
Correct |
353 ms |
220328 KB |
Output is correct |
37 |
Correct |
365 ms |
220364 KB |
Output is correct |
38 |
Correct |
260 ms |
181092 KB |
Output is correct |
39 |
Correct |
232 ms |
182492 KB |
Output is correct |