Submission #1296696

#TimeUsernameProblemLanguageResultExecution timeMemory
1296696florescentBitaro the Brave (JOI19_ho_t1)C++20
100 / 100
294 ms150684 KiB
//STRIKER!
#include <iostream> 
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <iomanip>

using namespace std;
#define int int64_t
#define pb push_back
#define speed cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false);
#define all(a) a.begin(), a.end()
#define sz(a) ((int)a.size())



void sol() {
    int n, m;
    cin >> n >> m;
    vector<vector<char>> a(n, vector<char>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }

    vector<vector<int>> sn(n + 2, vector<int>(m + 2, 0)), sm(n + 2, vector<int>(m + 2, 0));
    for (int j = 1; j <= m; j++) {
        for (int i = n; i >= 1; i--) {
            sn[i][j] = sn[i + 1][j] + (a[i - 1][j - 1] == 'I' ? 1 : 0);
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = m; j >= 1; j--) {
            sm[i][j] = sm[i][j + 1] + (a[i - 1][j - 1] == 'O' ? 1 : 0);
        }
    }

    int ans = 0;
    for (int i = 1; i < n; i++) {
        for (int j = 1; j < m; j++) {
            if (a[i - 1][j - 1] == 'J') {
                ans += sn[i + 1][j] * sm[i][j + 1];
            }
        }
    }

    cout << ans;
}

int32_t main() {
    speed;
    int t = 1;
    //cin >> t;

    while (t--) {
        sol();
    }

    return 0;
}

//freopen("name", "r", stdin);
//freopen("name", "w", stdout);
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...