이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
void solve(){
int n, m;
cin >> n >> m;
vector<vector<char>> grid(n, vector<char>(m));
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++)
cin >> grid[i][j];
}
vector<vi> i_down(n+1, vi(m+1)), o_right(n+1, vi(m+1));
for(int i = n-1; i >= 0; i--){
for(int j = 0; j < m; j++){
i_down[i][j] = i_down[i+1][j];
if(grid[i][j] == 'I')
i_down[i][j]++;
}
}
for(int j = m-1; j >= 0; j--){
for(int i = 0; i < n; i++){
o_right[i][j] = o_right[i][j+1];
if(grid[i][j] == 'O')
o_right[i][j]++;
}
}
ll ans = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(grid[i][j] == 'J')
ans += o_right[i][j]*i_down[i][j];
}
}
cout << ans << '\n';
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0);
int t = 1;
//cin >> t;
while(t--){
solve();
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |