Submission #641839

#TimeUsernameProblemLanguageResultExecution timeMemory
641839danikoynovBitaro the Brave (JOI19_ho_t1)C++14
100 / 100
747 ms159304 KiB
/**
 ____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|

**/

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const int maxn = 3010;
int n, m;
ll row[maxn][maxn], col[maxn][maxn];
char c[maxn][maxn];
void solve()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i ++)
        for (int j = 1; j <= m; j ++)
        {
            cin >> c[i][j];
            if (c[i][j] == 'O')
                row[i][j] ++;
            else if (c[i][j] == 'I')
                col[i][j] ++;
        }

    for (int i = 1; i <= n; i ++)
        for (int j = m; j > 0; j --)
            row[i][j] = row[i][j + 1] + row[i][j];

    for (int j = 1; j <= m; j ++)
        for (int i = n; i > 0; i --)
            col[i][j] = col[i + 1][j] + col[i][j];

    ll ans = 0;
    for (int i = 1; i <= n; i ++)
    {
        for (int j = 1; j <= m; j ++)
        {
            if (c[i][j] == 'J')
            {
                ans = ans + row[i][j] * col[i][j];
                ///cout << i << " " << j << " " << row[i][j] * col[i][j] << endl;
            }
        }
    }

    cout << ans << endl;

}

int main()
{
    solve();
    return 0;
}
/**
3 4
JOIJ
JIOO
IIII
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...