이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define endl '\n';
typedef long long ll;
int H,W;
ll ans = 0;
vector<pair<int,int>> J;
int dpI[3003][3003];
int dpO[3003][3003];
string S[3003];
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> H >> W;
for(int i = 1; i <= H; i++) {
string s; cin >> s;
S[i] = s;
}
for(int i = H; i >= 1; i--) {
for(int j = W-1; j >= 0; j--) {
dpI[j][i-1] += dpI[j][i];
dpO[i][j-1] += dpO[i][j];
if(S[i][j] == 'J') {
J.push_back({i,j});
}
else if(S[i][j] == 'I') {
dpI[j][i-1] += 1;
}
else if(S[i][j] == 'O') {
dpO[i][j-1] += 1;
}
}
}
for(auto e : J) {
int i = e.first;
int j = e.second;
//cout << endl;
//cout << "i = "<< i << " j = " << j << endl;
//cout << dpI[j][i] << " " << dpO[i][j] << endl;
ans += (dpI[j][i] * dpO[i][j]);
//cout << ans << endl
}
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... |