Submission #542091

#TimeUsernameProblemLanguageResultExecution timeMemory
542091AJ00Bitaro the Brave (JOI19_ho_t1)C++14
100 / 100
604 ms216644 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
int sufr[3000][3000],sufc[3000][3000],val[3000][3000];
char ch;
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1,n,m; 
   // cin >> t; 
    while (t--){
        cin >> n >> m;
        for (int i = 0; i < n; i++){
            for (int j = 0; j < m; j++){
                cin >> ch;
                if (ch == 'J'){
                    val[i][j] = 0;
                }
                if (ch == 'O'){
                    val[i][j] = 1;
                }
                if (ch == 'I'){
                    val[i][j] = 2;
                }
            }
        }
        // sufr[i][j] orbs in row i, after j
        // sufc[i][j] ingots in column j, after i
        for (int i = 0; i < n; i++){
            sufr[i][m-1] = (val[i][m-1] == 1);
            for (int j = m-2; j >= 0; j--){
                sufr[i][j] = sufr[i][j+1] + (val[i][j] == 1);
            }
        }
        for (int j = 0; j < m; j++){
            sufc[n-1][j] = (val[n-1][j] == 2);
            for (int i = n-2; i >= 0; i--){
                sufc[i][j] = sufc[i+1][j] + (val[i][j] == 2);
            }
        }
        int ans = 0;
        for (int i = 0; i < n; i++){
            for (int j = 0; j < m; j++){
                if (!val[i][j]){
                    ans += (sufr[i][j]*sufc[i][j]);
                }
            }
        }
        cout << ans << "\n";
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...