Submission #1355606

#TimeUsernameProblemLanguageResultExecution timeMemory
1355606anachkoidzeBitaro the Brave (JOI19_ho_t1)C++20
100 / 100
387 ms150208 KiB
#include <bits/stdc++.h>
using namespace std;
long long h, w, i, ans, j, k;
int main()
{
    cin >> h >> w;
    char s[h+1][w+1];
    long long dpo[h+1][w+1] = {}, dpi[h+1][w+1] = {};
    for(i = 1; i <= h; i++)
    {
        for(j = 1; j <= w; j++)
        {
            cin >> s[i][j];
        }
    }
    for(i = 1; i <= h; i++)
    {
        for(j = w; j >= 1; j--)
        {
            dpo[i][j] = dpo[i][j+1];
            if(s[i][j+1] == 'O') dpo[i][j]++;
        }
    }
    for(j = 1; j <= w; j++)
    {
        for(i = h-1; i >= 1; i--)
        {
            dpi[i][j] = dpi[i+1][j];
            if(s[i+1][j] == 'I') dpi[i][j]++;
        }
    }
    for(i = 1; i <= h; i++)
    {
        for(j = 1; j <= w; j++)
        {
            if(s[i][j] == 'J')
            {
                ans += dpo[i][j] * dpi[i][j];
            }
        }
    }
    cout << ans;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...