#pragma GCC optimize("Ofast,O2,O3,unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << "[" << H << "]";
debug_out(T...);
}
#ifdef dddxxz
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define SZ(s) ((int)s.size())
#define all(x) (x).begin(), (x).end()
#define lla(x) (x).rbegin(), (x).rend()
clock_t startTime;
double getCurrentTime() {
return (double) (clock() - startTime) / CLOCKS_PER_SEC;
}
#define MP make_pair
typedef long long ll;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const double eps = 0.000001;
const int MOD = 1e9 + 7;
const int INF = 1000000101;
const long long LLINF = 1223372000000000555;
const int N = 1e6 + 3e2;
const int M = 3222;
char a[M][M];
int O[M][M], I[M][M];
void solve(int TC) {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
}
}
ll ans = 0;
for (int i = n; i >= 1; i--) {
for (int j = m; j >= 1; j--){
O[i][j] = O[i][j + 1] + (a[i][j] == 'O');
I[i][j] = I[i + 1][j] + (a[i][j] == 'I');
if (a[i][j] == 'J') ans += 1ll * I[i + 1][j] * O[i][j + 1];
}
}
cout << ans;
}
int main() {
startTime = clock();
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
#ifdef dddxxz
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int TC = 1;
// cin >> TC;
for (int test = 1; test <= TC; test++) {
//debug(test);
//cout << "Case #" << test << ": ";
solve(test);
}
cerr << endl << "Time: " << int(getCurrentTime() * 1000) << " ms" << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
1484 KB |
Output is correct |
6 |
Correct |
1 ms |
1484 KB |
Output is correct |
7 |
Correct |
1 ms |
1356 KB |
Output is correct |
8 |
Correct |
1 ms |
1492 KB |
Output is correct |
9 |
Correct |
1 ms |
1484 KB |
Output is correct |
10 |
Correct |
1 ms |
1356 KB |
Output is correct |
11 |
Correct |
1 ms |
1484 KB |
Output is correct |
12 |
Correct |
1 ms |
1484 KB |
Output is correct |
13 |
Correct |
1 ms |
1356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
1484 KB |
Output is correct |
6 |
Correct |
1 ms |
1484 KB |
Output is correct |
7 |
Correct |
1 ms |
1356 KB |
Output is correct |
8 |
Correct |
1 ms |
1492 KB |
Output is correct |
9 |
Correct |
1 ms |
1484 KB |
Output is correct |
10 |
Correct |
1 ms |
1356 KB |
Output is correct |
11 |
Correct |
1 ms |
1484 KB |
Output is correct |
12 |
Correct |
1 ms |
1484 KB |
Output is correct |
13 |
Correct |
1 ms |
1356 KB |
Output is correct |
14 |
Correct |
7 ms |
7592 KB |
Output is correct |
15 |
Correct |
3 ms |
5068 KB |
Output is correct |
16 |
Correct |
4 ms |
4300 KB |
Output is correct |
17 |
Correct |
1 ms |
400 KB |
Output is correct |
18 |
Correct |
7 ms |
8088 KB |
Output is correct |
19 |
Correct |
7 ms |
8012 KB |
Output is correct |
20 |
Correct |
8 ms |
7896 KB |
Output is correct |
21 |
Correct |
8 ms |
8144 KB |
Output is correct |
22 |
Correct |
7 ms |
8012 KB |
Output is correct |
23 |
Correct |
7 ms |
7892 KB |
Output is correct |
24 |
Correct |
9 ms |
8068 KB |
Output is correct |
25 |
Correct |
9 ms |
8012 KB |
Output is correct |
26 |
Correct |
7 ms |
7884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
1484 KB |
Output is correct |
6 |
Correct |
1 ms |
1484 KB |
Output is correct |
7 |
Correct |
1 ms |
1356 KB |
Output is correct |
8 |
Correct |
1 ms |
1492 KB |
Output is correct |
9 |
Correct |
1 ms |
1484 KB |
Output is correct |
10 |
Correct |
1 ms |
1356 KB |
Output is correct |
11 |
Correct |
1 ms |
1484 KB |
Output is correct |
12 |
Correct |
1 ms |
1484 KB |
Output is correct |
13 |
Correct |
1 ms |
1356 KB |
Output is correct |
14 |
Correct |
7 ms |
7592 KB |
Output is correct |
15 |
Correct |
3 ms |
5068 KB |
Output is correct |
16 |
Correct |
4 ms |
4300 KB |
Output is correct |
17 |
Correct |
1 ms |
400 KB |
Output is correct |
18 |
Correct |
7 ms |
8088 KB |
Output is correct |
19 |
Correct |
7 ms |
8012 KB |
Output is correct |
20 |
Correct |
8 ms |
7896 KB |
Output is correct |
21 |
Correct |
8 ms |
8144 KB |
Output is correct |
22 |
Correct |
7 ms |
8012 KB |
Output is correct |
23 |
Correct |
7 ms |
7892 KB |
Output is correct |
24 |
Correct |
9 ms |
8068 KB |
Output is correct |
25 |
Correct |
9 ms |
8012 KB |
Output is correct |
26 |
Correct |
7 ms |
7884 KB |
Output is correct |
27 |
Correct |
161 ms |
92396 KB |
Output is correct |
28 |
Correct |
13 ms |
26440 KB |
Output is correct |
29 |
Correct |
12 ms |
8324 KB |
Output is correct |
30 |
Correct |
1 ms |
588 KB |
Output is correct |
31 |
Correct |
125 ms |
77308 KB |
Output is correct |
32 |
Correct |
189 ms |
92368 KB |
Output is correct |
33 |
Correct |
154 ms |
92100 KB |
Output is correct |
34 |
Correct |
138 ms |
89488 KB |
Output is correct |
35 |
Correct |
160 ms |
92480 KB |
Output is correct |
36 |
Correct |
151 ms |
92096 KB |
Output is correct |
37 |
Correct |
171 ms |
92400 KB |
Output is correct |
38 |
Correct |
119 ms |
77224 KB |
Output is correct |
39 |
Correct |
127 ms |
77056 KB |
Output is correct |