This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int n, m, dp[3002][3002][3], nr[3002][3];
char ch[] = "JOI";
char v[3002][3002];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
cin >> v[i][j];
for (int i = n; i >= 1; i--)
for (int j = 1; j <= m; j++)
for (int k = 0; k < 3; k++)
dp[i][j][k] = dp[i + 1][j][k] + (v[i][j] == ch[k]);
long long ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = m; j >= 1; j--) {
for (int k = 0; k < 3; k++)
nr[j][k] = nr[j + 1][k] + (v[i][j] == ch[k]);
if (v[i][j] == 'J')
ans += 1ll * dp[i + 1][j][2] * nr[j + 1][1];
//if (v[i][j] == 'O')
//ans += 1ll * dp[i + 1][j][0] * nr[j + 1][2] + 1ll * dp[i + 1][j][2] * nr[j + 1][0];
//if (v[i][j] == 'I')
//ans += 1ll * dp[i + 1][j][1] * nr[j + 1][0] + 1ll * dp[i + 1][j][0] * nr[j + 1][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... |