Submission #1098499

#TimeUsernameProblemLanguageResultExecution timeMemory
1098499bvv23Bitaro the Brave (JOI19_ho_t1)C++14
100 / 100
142 ms159376 KiB
/*
=======-==========---=-----------------------=-==================-==-=-=-===------------------------------------------------------
---------=--==-------------------------------=----========-----==--=-----=--------------------------------------------------------
--------=====-======-----------=-------------------=---=----=======-------==--------------------:---------------------------------
-------=----===--------------------=-------------==-----------=--------------=---------:-::-:::::::::::::::::::::::::---:::::-:::-
----------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------:------:-------------------:::--------:-------------------:-:-
---------------:----------------------------------------:------------------------------------:::::::::::::::::----:::-::----------
--------:-::---:::-::::-----------::::::-:---:------:::::--------------:--------::--::::-:::::::::::::::::::::::::::::::-:::------
-------------------:::::::--------::-:::::::::---=+***++=++=----------:--::::::--:::::::-:::------:::--:::::---::::::::::---------
:::::::-::::--:::::::::::::::::::::::::::::--#%%@@@@@@@@@@@%+----------::------:::::::::::::::::-:-:-::::::::::::::-::-:---::-::--
::-:::::::---::::::::::----:--:-:-:::::---:=%@@@@@@@@@@@@@@@@*=--+------:::::::::::::::::::-::-:::--------:::::::::-::::::--------
::::::-:::::::::::::::::::::::::::::::::::-*%@@@@@@@@@@@@@@%*=*@@@@#+=-:::::::::::::::::::::::::::::::-::=*%%@@@@%#*=--::--::-----
::::::::::::::::::::::::::::::::::::::::::+#=%@@@@@@@@@@@@@@%@@@@@@@%#+=----:::::::::::::::::::::::::::=%@@@@@@@@@@@@%=::---------
::::::::::::::::::::::::::::--::::::::::::-@*+@@@@@@@@@@@@@@@@@@@%*+==========------::::::::::::::::::+@@@@@@@@@@@@@@@@+::-----:::
::::::::::::::::::::::::::::-------------::-+:=#%@%%%@@%@@@@@@@@*+=========+=========-::::::::::::::-*@@@@@%@%%%%%#%@@@@*-::::::::
:::::::::-:::::::::::::::::::::::::::::::::::-*#######%%@@@@@@@+=+++++++++***++*+**++*+:::::::::::==#@@@@@@@@@@@@@@%%#@@@+:::::::-
:::::::::::::::::::::::::::::::::::::::::::::-:--%%###%%@@@@@@%#**#****#%%%%%#%%####****-::::::::-+%@@@@@@@@@@@@@@@%@@@@@@=:------
:::::::::::::::.:::::::::::::::::::::::::::::::::++###%@@@@@%%%%%@%%###%%@@@@@@@@@@@%%###+::::::::%@@@@@@@@@@@@@@%**@@@@@@@=::::::
::::::::::::::..........::::::::::::::::::::::::::::-*%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%%%#:..::=%@@@@@@@@@@@@@@@@@@@@@@@@@@=:::::
:::::::::::::::::::.::::::::::::::::::::::::::::::::::---%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%:.=#@@%#%@@@@@@@@@@@@@@@@@@@@@@@@*:::.
:::::::::::::::::::::::::::::::::::::::.....:::.........@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#.:+%@@@@@@%#*+========++**###@@#*=...
:::::::::::::::::::::::::::::::::::::::::.:::.:.........%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#..:+*#%@@@@@@@@@@@@@@@@@@@@@@@#+:...
::::::::::::::::::...:...:::..::.:....:......:+-........+@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#......:=**#%%%%%%%%@%%##*+=::::....
::::::::::::::::.............................-=:..::...-%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#...........:-=:..............::::.
.....::::::::.............................:-:........:.*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%:........+*#+..............::..:-
......:..::..:..........................::--:........::#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%-...:=++#%@=====:...............
:::.:::::::::::........................::::---::...::.:@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@+*:-+=++#%#+++*++***+=::.......:
::.:::::::::::..:...................::::::--=-:......*@@@@@@@@@@@@@@@@@@@@@@@@@%@@@@@@@@@@@@@@@@@@@**-=+++#%*++**+=--=+++**+-:...=
::::::::.....:......::...........:::::::-::---::::::=@@@@@@@@@@@@@@@@@@@@@@@@@@%@@@@@@@@@@@@@@@@@@@@*#+=++*#+++****+==+===+++**=-.
:.:..:::::.:::.................:::::::-:::----:-:::-%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%*##++**++****###%%#*++***+===
:::::::::::::.::...............:--::--::::====-::=+@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%%@*#****+***##*#%%#***=+===
:::::::::::::.::.:..:..........:::::---:::--=---==%@@@@@@@@@@@@@@@@@%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%%%##%##**++*#******++++++
..........................:::::..::::--:---==--:%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%#***#%######**+
.......::...............:::.:.....:::----====-:.@@@@@@@@@@@@@%%@@@%#%@@%@@@@%%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%######*+:::---:
......::::::::::::::.::.::.:....::::....--+-*=::@@@@@@@@@@-....+%%%##%@@@%%%%%@@@@%%@@@@@@@@@@@@@@@@@@@@@@@@@@@=-==---=-:.........
...:::::::.:::::::.:::.:........::......::::-:..-=+*#%@@@@#+-::-%@@@%%%%%#%@@@@@@@**%@@@@@@@@@@@@@@@@@@@@@@@@@#:-:..............::
::::::::::::::::.:-=-::........:::............:::=....-=+*##%%%%@@@@@@@@@@@@@@@@@%+*+@@@@@@@@@@@@@@@@@@@@@@@@@:..-:.......:-:----:
:::::::::::::::.:-==:.........::..::-::....-=++*++*+++=+++*#@@@@@@@@@@@@@@@%%@@@@@#@#@@@@@@@@@@@@@@@@@@@@@@%%+.............:-=-:..
.::::::::::::..---=-:::.::.::----=**++=..:==***@%%%%%###*#%%%%%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*=::....................
..::::::::::::=====-:::::::--*++=*#**#*..=+**#%@@@%%@%%%#%%%%%@@@@@%@@@@@%%@@@@@@@@@%@@%%%@@@@@@@@@@@@@@@@*..........:::.::.......
:::::::::.::-=+====-:::..::=*####**#%%#..=#**%%%@@@@%%%%%%%%@%%%%%@@@@@%@%%@%%%%%%@%%%%%%%%@@@@@@@@@@@@@@@%-:...........--*#*++---
:::::::::::::-===--:::::::--=*%%%%@@@%#.:=+#%%%@@@@%***##%%@@@@@@@@%%@%@@@@@@%%%#%%%###%%%@@@@@@@@@@@@@@@@@%%#*#=-:..........:...-
::::::::::::::::==--::::-===*##%@@@@@%+.=######%%#+#*++++#%++#%%%%@%%@@@@@@@@@@@@@@@%@@@%@@@@@@@@@@@@@@@@@@%%@@@@@*=++==***=-:::-#
.:.::..:::::::::..::::::-+**#%@@@@@@@@=:+###%#%#*==#*****#%+.:*####*=#%%%%%@%%@%%#####**%%%@@@@@@@@@@@@@@@@*@@@@%#%*+*%@@@@@@%#**%
::::::::::::::.....:---==+###%@@@@@@@@=-##%%%###*==##%#####+.:+###*+=%%%%#%**%%#*****+*#%%@@@@@@@@@@@@@@@@@@%@@%%@##%#%%%%%@@@%##*
::::::...::---+:.....=+=*%#%@@@@%%@@@@=+##%%####*=#%@%%%#%%#..=*#*+-#@@@%#++*##*+*=::-*%@@@@@%%#@@@@@@@@@@@@@%#%@@@%%%%@@@%@@@@%#*
:--=-..:=----=-.......=##@@@@@@@@@@@@@**###%####**@@@@@@@@%%..-*#+:#@@@@*=+=:+-:..::=#%%@@%##**@%@@@@@@@@@@@@@@@@@%@@@@@@@@@@@@@@#
........-++*%=....::::..=%@@@@@@@@@@@@**#######*#@@@@@@@@@@#..:+*-+@@@@%+::.:...--:+%%@@@@@%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
----+*++**##%+=-..:.:+#*##@@@@@@@@@@@@+#######*#@@@@@@@@@@@+..-++:@@@@#-...::.-=::=%%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%%@
###%*++#@@%@%***%@@%###@@@@%%@@@@@@@@@+########@@@@@@%@@@@@:..-*=+@@@#-:.....:-+**#*#%@@@@@@@@@@@@@@@@@@@@@@@%@@@@@@@@@@@@@@@@@@%%
#===+#%@@@@@@%%@@@@%@@%*-.+:..:+@@@@@%*######*-.:=::..==---..:-*+:.:---...-:=*+=+*###%@@@@@@@@@@@@@@@@@@@@@@@%@@@@@@@@@@@@@@@@@@@@
.:-::..:-==:...-==-=...........:--::.:######*:..............:=*##*::-=-..-:.=++=*%%%%@@@@@@@@@@@@@@@@@@@@@@@@%%@@@@@@@@@@@@@@@@@@@
.:::--:::-=-.........................=*#####+..........:...-*%@@@+-+@-..:...:=#%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#++=--::-=+@@@@@@@@@@
:::==+****+-:.......................:*######+........+#%*%@@@@@@#-:-#=-#=:.:*%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@+=++=++=*##%+@@@@@@@@@
.....:=++**=:..:.:..................-*#%######:.......::+%@@@%#++=-=+%#=..**%%%%@%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%@@@@%+@@@@@@@@
.........-:...:-...................:+#%##%%%@@%:.........--::::##==.....:-=*##%%##%@@@@@@@@@@@@@@@@@@@@@@@@@@@%%%@%@@@@@@++@@@@@@@
::................................-+*#%%%@@@@@@+......:..:::-:-==.....:+=++*######@@@@@@@@@@@@@@@@@@@@@@@@@@@%%@@@@@@@@@@@*#@@@@@@
...........................:-=+=..=*%@@@@@@@@%=...:........---+*=:..:=+-*#@@@%%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@@@@@
........................-##=*%@@@@@@@@@%+-:+@@#-..:--::::...:=+::==**#*#%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
:......................:++===##%%%%%*=:..-#**%#**--**-::..=*##==*%%%%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
=-..................................::---==+=:::-+#%@%%##%%#@@@#%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+*-...............................................-#@@@@@%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#=-=*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
............................................:+#*==+--=----=*##@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%++=....:+@@@@@@@@@@@@@@@@@@@%%%*+-.:--
*/
// Ahmadov orz
/// successful failure
#include <bits/stdc++.h>
/// #include <ext/pb_ds/assoc_container.hpp>
using namespace std;
/// using namespace __gnu_pbds;
#define int long long
#define pb push_back
#define pii pair<int, int>
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define drop(x) cout<<x<<endl;return
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
// template <class T>
// using isTree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

/// sometimes you gotta think simple
struct custom_hash {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};
const int N = 3e3 + 7;
int suffI[N][N], suffO[N][N];
void failure()
{
    int n, m;
    cin >> n >> m;
    string arr[n + 1];
    for (int i = 1; i <= n; i++) {
        cin >> arr[i];
        arr[i] = "!" + arr[i];
    }
    // i,j -> J
    // i,l -> O
    // k,j -> I
    // i < k,  j < l!!!
    for (int i = n; i >= 1; i--) {
        for (int j = 1; j <= m; j++) {
            suffI[i][j] = suffI[i + 1][j] + (arr[i][j] == 'I');
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = m; j >= 1; j--) {
            suffO[i][j] = suffO[i][j + 1] + (arr[i][j] == 'O');
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if  (arr[i][j] == 'J') {
                ans += suffI[i][j] * suffO[i][j];   // her orb her ingot ile
            }
        }
    }
    cout << ans << endl;
}
signed main() { 
    cin.tie()->sync_with_stdio(0);
    int tt = 1;
    //cin >> tt;
    while (tt--)
    {
        failure();
    }
}
  
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...