제출 #654271

#제출 시각아이디문제언어결과실행 시간메모리
654271hailBitaro the Brave (JOI19_ho_t1)C++17
100 / 100
216 ms221004 KiB
#include <bits/stdc++.h>
 
using namespace std;
 
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
using ll= long long;
#define fast_io ios::sync_with_stdio(0); cin.tie(0)
#define inpint(x) int x; cin>>x
#define inpll(x) long long x; cin>>x
#define fl(i, n) for(int i=0; i<n; i++)
#define flo(i, n) for(int i=1; i<=n; i++)
#define int long long 
#define pi pair<int, int>
#define mp make_pair
#define ld long double

const int MOD = 7 + (int)1e9;
const int INF = (int)1e18;

//

void solve()
{
    int h, w;
    cin>>h>>w;

    // jewel on the square (i, j), an orb on the 
    //square (i, ℓ) and an ingot on
    //the square (k, j)

    vector<vector<int>> grid(h+2, vector<int>(w+2));
    vector<vector<int>> jp(h+2, vector<int>(w+2, 0));
    vector<vector<int>> op(h+2, vector<int>(w+2, 0));

    int ans = 0;

    for(int i=1; i<=h; i++)
    {
        string s;
        cin>>s;
        for(int j=1; j<=w; j++)
        {
            if(s[j-1]=='J') grid[i][j] = 0;
            else if(s[j-1]=='O') grid[i][j] = 1;
            else grid[i][j] = 2;
        }
    }


    for(int i=1; i<=h; i++)
    {
        for(int j=w; j>0; j--)
        {
            jp[i][j] = jp[i][j+1];
            op[i][j] = op[i-1][j];
            if(grid[i][j]==1) jp[i][j]++;
            else if(grid[i][j]==0) op[i][j] += jp[i][j];
            else ans += op[i][j];
        }
    }

    cout<<ans;
}

signed main()
{
    fast_io;

    int t=1; 
    //cin>>t;
    while(t--)
    {
        solve();
    }
    cout<<endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...