Submission #1258694

#TimeUsernameProblemLanguageResultExecution timeMemory
1258694nguyentrungkienBitaro the Brave (JOI19_ho_t1)C++20
0 / 100
1 ms1604 KiB
#include<bits/stdc++.h>
#define int long long 
const int maxn = 3e3 + 5;
const int inf = 1e18;
const int base = 31;
const int mod = 1e9 + 7;
const int mod2 = 1212121;
using namespace std;
int n, m;
char a[maxn][maxn];
int fo[maxn][maxn];
int fi[maxn][maxn];
int res = 0;
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            cin >> a[i][j];
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int j = m; j >= 1; j--) {
            if(a[i][j] == 'O') fo[i][j] = fo[i][j + 1] + 1;
            else fo[i][j] = fo[i][j + 1];
        }
    }
    for(int j = 1; j <= m; j++) {
        for(int i = n; i >= 1; i--) {
            if(a[i][j] == 'I') fi[i][j] = fi[i + 1][j] + 1;
            else fi[i][j] = fi[i + 1][j];
        }
    }
    // for(int i = 1; i <= n; i++) {
    //     for(int j = 1; j <= n; j++) {
    //         cout << fi[i][j] << " ";
    //     }
    //     cout << "\n";
    // }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            if(a[i][j] == 'J') res += fi[i][j] * fo[i][j];
        }
    }
    cout << res << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...