#include <iostream>
#include <climits>
#include <numeric>
#include <cassert>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <vector>
#include <array>
#include <memory>
#define IN(a,b) (a.find(b) != a.end())
#define p(a,b) make_pair(a,b)
#define readVec(a) for (int64_t __i = 0; __i<(int64_t)a.size();__i++){cin>>a[__i];}
// jimjam
template<typename T>
void pMin(T &a, T b) {if (b<a){a=b;}}
template<typename T>
void pMax(T &a, T b) {if (b>a){a=b;}}
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& c);
template<typename A, typename B>
std::ostream& operator<<(std::ostream& os, const std::pair<A,B>& c) {std::cout << "(" << c.first << ", " << c.second << ")";return os;}
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& c) {
if (c.size() == 0) {os << "{}"; return os;}
os << "{" << c[0];
for (int64_t i = 1; i < (int64_t)c.size(); i++) {os <<", "<<c[i];}
os << "}";
return os;
}
using namespace std;
#define MAXN 3001
char grid[MAXN][MAXN];
int64_t ingotsBelow[MAXN][MAXN];
int64_t orbsRight[MAXN][MAXN];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int64_t rows, cols; cin >> rows >> cols;
for (int64_t r = 0; r < rows; r++) {
for (int64_t c = 0; c < cols; c++) {
cin >> grid[r][c];
}
}
for (int64_t c = 0; c < cols; c++) {
for (int64_t r = rows-1; r >= 0; r--) {
ingotsBelow[r][c] += ingotsBelow[r+1][c];
ingotsBelow[r][c] += (grid[r][c]=='I');
}
}
for (int64_t r = 0; r < rows; r++) {
for (int64_t c = cols-1; c >= 0; c--) {
orbsRight[r][c] += orbsRight[r][c+1];
orbsRight[r][c] += (grid[r][c]=='O');
}
}
int64_t ans=0;
for (int64_t r = 0; r < rows; r++) {
for (int64_t c = 0 ; c < cols ;c++) {
if (grid[r][c]=='J') {
ans += ingotsBelow[r][c]*orbsRight[r][c];
}
}
}
cout << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
1536 KB |
Output is correct |
6 |
Correct |
1 ms |
1536 KB |
Output is correct |
7 |
Correct |
1 ms |
1408 KB |
Output is correct |
8 |
Correct |
2 ms |
1536 KB |
Output is correct |
9 |
Correct |
2 ms |
1536 KB |
Output is correct |
10 |
Correct |
1 ms |
1536 KB |
Output is correct |
11 |
Correct |
2 ms |
1536 KB |
Output is correct |
12 |
Correct |
1 ms |
1536 KB |
Output is correct |
13 |
Correct |
1 ms |
1408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
1536 KB |
Output is correct |
6 |
Correct |
1 ms |
1536 KB |
Output is correct |
7 |
Correct |
1 ms |
1408 KB |
Output is correct |
8 |
Correct |
2 ms |
1536 KB |
Output is correct |
9 |
Correct |
2 ms |
1536 KB |
Output is correct |
10 |
Correct |
1 ms |
1536 KB |
Output is correct |
11 |
Correct |
2 ms |
1536 KB |
Output is correct |
12 |
Correct |
1 ms |
1536 KB |
Output is correct |
13 |
Correct |
1 ms |
1408 KB |
Output is correct |
14 |
Correct |
12 ms |
8832 KB |
Output is correct |
15 |
Correct |
4 ms |
5120 KB |
Output is correct |
16 |
Correct |
7 ms |
5248 KB |
Output is correct |
17 |
Correct |
1 ms |
512 KB |
Output is correct |
18 |
Correct |
14 ms |
9728 KB |
Output is correct |
19 |
Correct |
13 ms |
9600 KB |
Output is correct |
20 |
Correct |
13 ms |
9600 KB |
Output is correct |
21 |
Correct |
14 ms |
9984 KB |
Output is correct |
22 |
Correct |
13 ms |
9856 KB |
Output is correct |
23 |
Correct |
12 ms |
9856 KB |
Output is correct |
24 |
Correct |
14 ms |
9984 KB |
Output is correct |
25 |
Correct |
13 ms |
9856 KB |
Output is correct |
26 |
Correct |
13 ms |
9856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
1536 KB |
Output is correct |
6 |
Correct |
1 ms |
1536 KB |
Output is correct |
7 |
Correct |
1 ms |
1408 KB |
Output is correct |
8 |
Correct |
2 ms |
1536 KB |
Output is correct |
9 |
Correct |
2 ms |
1536 KB |
Output is correct |
10 |
Correct |
1 ms |
1536 KB |
Output is correct |
11 |
Correct |
2 ms |
1536 KB |
Output is correct |
12 |
Correct |
1 ms |
1536 KB |
Output is correct |
13 |
Correct |
1 ms |
1408 KB |
Output is correct |
14 |
Correct |
12 ms |
8832 KB |
Output is correct |
15 |
Correct |
4 ms |
5120 KB |
Output is correct |
16 |
Correct |
7 ms |
5248 KB |
Output is correct |
17 |
Correct |
1 ms |
512 KB |
Output is correct |
18 |
Correct |
14 ms |
9728 KB |
Output is correct |
19 |
Correct |
13 ms |
9600 KB |
Output is correct |
20 |
Correct |
13 ms |
9600 KB |
Output is correct |
21 |
Correct |
14 ms |
9984 KB |
Output is correct |
22 |
Correct |
13 ms |
9856 KB |
Output is correct |
23 |
Correct |
12 ms |
9856 KB |
Output is correct |
24 |
Correct |
14 ms |
9984 KB |
Output is correct |
25 |
Correct |
13 ms |
9856 KB |
Output is correct |
26 |
Correct |
13 ms |
9856 KB |
Output is correct |
27 |
Correct |
493 ms |
158440 KB |
Output is correct |
28 |
Correct |
19 ms |
26360 KB |
Output is correct |
29 |
Correct |
24 ms |
13952 KB |
Output is correct |
30 |
Correct |
2 ms |
896 KB |
Output is correct |
31 |
Correct |
369 ms |
131236 KB |
Output is correct |
32 |
Correct |
489 ms |
158900 KB |
Output is correct |
33 |
Correct |
485 ms |
158456 KB |
Output is correct |
34 |
Correct |
427 ms |
152312 KB |
Output is correct |
35 |
Correct |
485 ms |
158840 KB |
Output is correct |
36 |
Correct |
486 ms |
158328 KB |
Output is correct |
37 |
Correct |
521 ms |
159072 KB |
Output is correct |
38 |
Correct |
350 ms |
130808 KB |
Output is correct |
39 |
Correct |
347 ms |
130680 KB |
Output is correct |