Submission #887981

#TimeUsernameProblemLanguageResultExecution timeMemory
887981TahirAliyevBitaro the Brave (JOI19_ho_t1)C++17
100 / 100
262 ms88528 KiB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pii pair<int, int>
#define oo 1e9
#define pb push_back

const int MAX = 3003;

int n, m;

char arr[MAX][MAX];

int sufOrb[MAX][MAX];
int sufIng[MAX][MAX];

int main(){
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        string a; cin >> a;
        for(int j = 0; j < m; j++){
            arr[i][j + 1] = a[j];
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = m; j >= 1; j--){
            sufOrb[i][j] = sufOrb[i][j + 1] + (arr[i][j] == 'O');
        }
    }
    for(int j = 1; j <= m; j++){
        for(int i = n; i >= 1; i--){
            sufIng[i][j] = sufIng[i + 1][j] + (arr[i][j] == 'I');
        }
    }

    ll ans = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(arr[i][j] == 'J'){
                ans += 1ll * sufOrb[i][j] * sufIng[i][j];
            }
        }
    }
    cout << ans << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...