// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx")
// #pragma comment(linker, "/stack:200000000"]
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <stack>
#include <random>
#include <fstream>
#include <sstream>
#include <chrono>
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
#define hm unordered_map
#define pii pair<int, int>
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define cinv(v) for (auto& x: v) cin >> x
#define fr(i, n) for (int i = 0; i < n; ++i)
#define fl(i, l, n) for (int i = l; i < n; ++i)
#define int ll
template <typename T1, typename T2> inline bool chkmin(T1 &x, const T2 &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T1, typename T2> inline bool chkmax(T1 &x, const T2 &y) {if (x < y) {x = y; return 1;} return 0;}
using namespace std;
#ifdef LOCAL
#define dbg(x) cerr << #x << " : " << x << '\n'
const int maxn = 20;
#else
#define dbg(x)
const int maxn = 3000 + 20;
#endif
//tg: @galebickosikasa
ostream& operator << (ostream& out, const pii& v) {
out << v.fi << ", " << v.se;
return out;
}
template<typename T> ostream& operator << (ostream& out, const vector<T>& v) {
for (auto& x: v) out << x << " ";
return out;
}
istream& operator >> (istream& in, pii& a) {
in >> a.fi >> a.se;
return in;
}
const ll inf = (ll) 2e9;
const ld pi = asin (1) * 2;
const ld eps = 1e-8;
const ll mod = (ll)1e9 + 7;
const ll ns = 97;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int dp1[maxn][maxn], dp2[maxn][maxn];
char goo[maxn][maxn];
signed main () {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, m;
cin >> n >> m;
fr (i, n) fr (j, m) cin >> goo[i][j];
for (int i = 0; i < n; ++i) {
for (int j = m - 1; j >= 0; --j) {
dp1[i][j] = dp1[i][j + 1] + (goo[i][j] == 'O');
}
}
for (int j = 0; j < m; ++j) {
for (int i = n - 1; i >= 0; --i) {
dp2[i][j] = dp2[i + 1][j] + (goo[i][j] == 'I');
}
}
int ans = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
ans += dp1[i][j] * dp2[i][j] * (goo[i][j] == 'J');
if (goo[i][j] == 'J') {
dbg (i);
dbg (j);
dbg (dp1[i][j]);
dbg (dp2[i][j]);
}
}
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
1644 KB |
Output is correct |
6 |
Correct |
1 ms |
1516 KB |
Output is correct |
7 |
Correct |
1 ms |
1516 KB |
Output is correct |
8 |
Correct |
2 ms |
1644 KB |
Output is correct |
9 |
Correct |
2 ms |
1516 KB |
Output is correct |
10 |
Correct |
1 ms |
1516 KB |
Output is correct |
11 |
Correct |
1 ms |
1644 KB |
Output is correct |
12 |
Correct |
1 ms |
1516 KB |
Output is correct |
13 |
Correct |
1 ms |
1516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
1644 KB |
Output is correct |
6 |
Correct |
1 ms |
1516 KB |
Output is correct |
7 |
Correct |
1 ms |
1516 KB |
Output is correct |
8 |
Correct |
2 ms |
1644 KB |
Output is correct |
9 |
Correct |
2 ms |
1516 KB |
Output is correct |
10 |
Correct |
1 ms |
1516 KB |
Output is correct |
11 |
Correct |
1 ms |
1644 KB |
Output is correct |
12 |
Correct |
1 ms |
1516 KB |
Output is correct |
13 |
Correct |
1 ms |
1516 KB |
Output is correct |
14 |
Correct |
10 ms |
9068 KB |
Output is correct |
15 |
Correct |
3 ms |
5100 KB |
Output is correct |
16 |
Correct |
6 ms |
5356 KB |
Output is correct |
17 |
Correct |
1 ms |
492 KB |
Output is correct |
18 |
Correct |
11 ms |
9964 KB |
Output is correct |
19 |
Correct |
11 ms |
9836 KB |
Output is correct |
20 |
Correct |
11 ms |
9836 KB |
Output is correct |
21 |
Correct |
12 ms |
9964 KB |
Output is correct |
22 |
Correct |
11 ms |
9836 KB |
Output is correct |
23 |
Correct |
12 ms |
9836 KB |
Output is correct |
24 |
Correct |
12 ms |
9964 KB |
Output is correct |
25 |
Correct |
15 ms |
9836 KB |
Output is correct |
26 |
Correct |
14 ms |
9836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
1644 KB |
Output is correct |
6 |
Correct |
1 ms |
1516 KB |
Output is correct |
7 |
Correct |
1 ms |
1516 KB |
Output is correct |
8 |
Correct |
2 ms |
1644 KB |
Output is correct |
9 |
Correct |
2 ms |
1516 KB |
Output is correct |
10 |
Correct |
1 ms |
1516 KB |
Output is correct |
11 |
Correct |
1 ms |
1644 KB |
Output is correct |
12 |
Correct |
1 ms |
1516 KB |
Output is correct |
13 |
Correct |
1 ms |
1516 KB |
Output is correct |
14 |
Correct |
10 ms |
9068 KB |
Output is correct |
15 |
Correct |
3 ms |
5100 KB |
Output is correct |
16 |
Correct |
6 ms |
5356 KB |
Output is correct |
17 |
Correct |
1 ms |
492 KB |
Output is correct |
18 |
Correct |
11 ms |
9964 KB |
Output is correct |
19 |
Correct |
11 ms |
9836 KB |
Output is correct |
20 |
Correct |
11 ms |
9836 KB |
Output is correct |
21 |
Correct |
12 ms |
9964 KB |
Output is correct |
22 |
Correct |
11 ms |
9836 KB |
Output is correct |
23 |
Correct |
12 ms |
9836 KB |
Output is correct |
24 |
Correct |
12 ms |
9964 KB |
Output is correct |
25 |
Correct |
15 ms |
9836 KB |
Output is correct |
26 |
Correct |
14 ms |
9836 KB |
Output is correct |
27 |
Correct |
418 ms |
159724 KB |
Output is correct |
28 |
Correct |
18 ms |
26348 KB |
Output is correct |
29 |
Correct |
24 ms |
13932 KB |
Output is correct |
30 |
Correct |
1 ms |
876 KB |
Output is correct |
31 |
Correct |
312 ms |
131692 KB |
Output is correct |
32 |
Correct |
434 ms |
159852 KB |
Output is correct |
33 |
Correct |
431 ms |
159340 KB |
Output is correct |
34 |
Correct |
357 ms |
152556 KB |
Output is correct |
35 |
Correct |
434 ms |
159980 KB |
Output is correct |
36 |
Correct |
433 ms |
159340 KB |
Output is correct |
37 |
Correct |
431 ms |
159980 KB |
Output is correct |
38 |
Correct |
311 ms |
130796 KB |
Output is correct |
39 |
Correct |
306 ms |
131180 KB |
Output is correct |