이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |