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>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int n,m;
char a[3002][3002];
int jewel[3002][3002];
int orb[3002][3002];
int ingot[3002][3002];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
cin >> n >> m;
for (int i=1; i<=n; i++) {
for (int j=1; j<=m; j++) {
cin >> a[i][j];
}
}
memset(jewel,0,sizeof(jewel));
memset(orb,0,sizeof(orb));
memset(ingot,0,sizeof(ingot));
//cout << "jewel: " << jewel[1][5] << endl;
for (int i=1; i<=n; i++) {
for (int j=m; j>=1; j--) {
if (a[i][j]=='J') {
//cout << i << " " << j << endl;
jewel[i][j]=jewel[i][j+1]+1;
} else {
jewel[i][j]=jewel[i][j+1];
}
}
}
for (int i=1; i<=n; i++) {
for (int j=m; j>=1; j--) {
if (a[i][j]=='O') {
orb[i][j]=orb[i][j+1]+1;
} else {
orb[i][j]=orb[i][j+1];
}
}
}
for (int j=1; j<=m; j++) {
for (int i=n; i>=1; i--) {
if (a[i][j]=='I') {
ingot[i][j]=ingot[i+1][j]+1;
} else {
ingot[i][j]=ingot[i+1][j];
}
}
}
// for (int i=1; i<=n; i++) {
// for (int j=1; j<=m; j++) {
// cout << jewel[i][j] << " ";
// }
// cout << endl;
// }
// cout << endl;
// for (int i=1; i<=n; i++) {
// for (int j=1; j<=m; j++) {
// cout << orb[i][j] << " ";
// }
// cout << endl;
// }
// cout << endl;
// for (int i=1; i<=n; i++) {
// for (int j=1; j<=m; j++) {
// cout << ingot[i][j] << " ";
// }
// cout << endl;
// }
// cout << endl;
// //cout << orb[2][2] << " " << ingot[3][1];
int ans=0;
for (int i=1; i<=n; i++) {
for (int j=1; j<=m; j++) {
if (a[i][j]=='J') {
// cout << i << " " << j << endl;
// cout << orb[i][j+1] << " " << ingot[i+1][j] << endl;
// cout << endl;
ans+=(orb[i][j+1]*ingot[i+1][j]);
}
}
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |