#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#include <cstring>
#include <numeric>
#include <functional>
#include <chrono>
#include <cassert>
#include <bitset>
//#include <bit>
//#include <ranges>
//#include <numbers>
#define itn int
#define sacnf scanf
#define sz(a) ((int)((a).size()))
// printf("%.10f\n", ans);
using ll = long long;
using namespace std;
const ll mod = 998244353;
const int N = 1e6 + 1, inf = 1e9;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
vector<string> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
vector<vector<int>> O(n, vector<int>(m));
for (int i = 0; i < n; i++)
{
if (v[i][m - 1] == 'O') O[i][m - 1] = 1;
for (int j = m - 2; j >= 0; j--)
{
O[i][j] = O[i][j + 1];
if (v[i][j] == 'O') O[i][j]++;
}
}
vector<vector<int>> I(m, vector<int>(n));
for (int j = 0; j < m; j++)
{
if (v[n - 1][j] == 'I') I[j][n - 1] = 1;
for (int i = n - 2; i >= 0; i--)
{
I[j][i] = I[j][i + 1];
if (v[i][j] == 'I') I[j][i]++;
}
}
ll ans = 0;
for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) if (v[i][j] == 'J' && i + 1 < n && j + 1 < m) ans += 1ll * O[i][j + 1] * I[j][i + 1];
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
5 ms |
2252 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
1620 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
5 ms |
2744 KB |
Output is correct |
19 |
Correct |
3 ms |
2732 KB |
Output is correct |
20 |
Correct |
3 ms |
2764 KB |
Output is correct |
21 |
Correct |
5 ms |
2764 KB |
Output is correct |
22 |
Correct |
4 ms |
2644 KB |
Output is correct |
23 |
Correct |
4 ms |
2756 KB |
Output is correct |
24 |
Correct |
5 ms |
2764 KB |
Output is correct |
25 |
Correct |
4 ms |
2644 KB |
Output is correct |
26 |
Correct |
3 ms |
2772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
5 ms |
2252 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
1620 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
5 ms |
2744 KB |
Output is correct |
19 |
Correct |
3 ms |
2732 KB |
Output is correct |
20 |
Correct |
3 ms |
2764 KB |
Output is correct |
21 |
Correct |
5 ms |
2764 KB |
Output is correct |
22 |
Correct |
4 ms |
2644 KB |
Output is correct |
23 |
Correct |
4 ms |
2756 KB |
Output is correct |
24 |
Correct |
5 ms |
2764 KB |
Output is correct |
25 |
Correct |
4 ms |
2644 KB |
Output is correct |
26 |
Correct |
3 ms |
2772 KB |
Output is correct |
27 |
Correct |
175 ms |
84592 KB |
Output is correct |
28 |
Correct |
1 ms |
724 KB |
Output is correct |
29 |
Correct |
8 ms |
6728 KB |
Output is correct |
30 |
Correct |
1 ms |
608 KB |
Output is correct |
31 |
Correct |
124 ms |
62268 KB |
Output is correct |
32 |
Correct |
131 ms |
88948 KB |
Output is correct |
33 |
Correct |
132 ms |
89164 KB |
Output is correct |
34 |
Correct |
140 ms |
72160 KB |
Output is correct |
35 |
Correct |
136 ms |
88908 KB |
Output is correct |
36 |
Correct |
130 ms |
89236 KB |
Output is correct |
37 |
Correct |
201 ms |
89512 KB |
Output is correct |
38 |
Correct |
85 ms |
61772 KB |
Output is correct |
39 |
Correct |
87 ms |
62028 KB |
Output is correct |