이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |