This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |