Submission #1359237

#TimeUsernameProblemLanguageResultExecution timeMemory
1359237darkdevilvaqifBitaro the Brave (JOI19_ho_t1)C++20
100 / 100
88 ms80040 KiB
/*
  _      __        __         __        ____                    ___    _                   __
 | | /| / / ___ _ / /_ ____  / /       / __ \  ___  ___        / _ \  (_) ___  ____ ___   / /
 | |/ |/ / / _ `// __// __/ / _ \     / /_/ / / _ \/ -_)      / ___/ / / / -_)/ __// -_) /_/ 
 |__/|__/  \_,_/ \__/ \__/ /_//_/     \____/ /_//_/\__/      /_/    /_/  \__/ \__/ \__/ (_)  
                                                                                             
*/

#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
// #pragma GCC target("avx2")
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define ld long double
#define all(v) v.begin(), v.end()
#define allr(v, l, r) v.begin() + l, v.begin() + r + 1
#define rall(v) v.rbegin(), v.rend()
#define rallr(v, l, r) v.rbegin() + ((int)v.size() - 1 - r), v.rbegin() + ((int)v.size() - l)
#define endl "\n"
#define newline cout << endl;
using namespace std;
 
// constants
const int INF = 1e9;

// functions

// structs

// globals

// notes
/*
 -stuff you should look for-
* int overflow, array bounds
* special cases (n=1?)
* do something instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH

continue - skip the rest in the loop
*/
 
void solve()
{
    int n, m;
    cin >> n >> m;
    vector <string> g(n + 1);
    for (int i = 1; i <= n; i++)
    {
        cin >> g[i];

        g[i] = '-' + g[i];
    }

    vector <vector <ll> > cnt(n + 1, vector <ll>(m + 1, 0LL));
    for (int i = 1; i <= n; i++)
    {
        cnt[i] = cnt[i - 1];
        int cur = 0;
        for (int j = m; j >= 1; j--)
        {
            cur += (g[i][j] == 'O');
            if (g[i][j] == 'J')
            {
                cnt[i][j] += 1LL * cur;
            }
        }
    }

    ll res = 0LL;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            if (g[i][j] == 'I')
            {
                res += cnt[i][j];
            }
        }
    }

    cout << res;
}
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int testcount = 1;
    // cin >> testcount;
    while (testcount--)
    {
        solve();
        newline
    }
}

/*
$$$$$$$$\ $$$$$$$$\ 
$$  _____|\____$$  |
$$ |          $$  / 
$$$$$\       $$  /  
$$  __|     $$  /   
$$ |       $$  /    
$$$$$$$$\ $$$$$$$$\ 
\________|\________|
*/
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...