제출 #1359229

#제출 시각아이디문제언어결과실행 시간메모리
1359229husu1331Bitaro the Brave (JOI19_ho_t1)C++20
100 / 100
226 ms150588 KiB
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////////
#define int long long
#define endl "\n"
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 0x3F3F3F3F3F3F3F3F
#define ss second
#define ff first
#define pb push_back
#define ins insert
#define all(a) a.begin() , a.end()
#define input(a , n) for(int i = 0 ; i < n ; i ++) cin >> a[i]
//#define cin fin
//#define cout fout
///////////////////////////////////////////////
//ofstream fout ("ride.out");
//ifstream fin ("ride.in");
///////////////////////////////////////////////
const int sz = 2e5 + 5 ;
const int LG = 20 ;
const int N = 700 ;
const int mod = 1e9 + 7 ;
const int MAXM = 1e9 + 7 ;
///////////////////////////////////////////////
///////////////////////////////////////////////
void solve() {
  int n ; 
  cin >> n ;
  int m ;
  cin >> m ;
  char a[n + 1][m + 1] ;
  for(int i = 1 ; i <= n ; i ++) {
    for(int j = 1 ; j <= m ; j ++) {
      cin >> a[i][j] ;
    }
  }
  vector<vector<int>>sufrow_o(n + 2 , vector<int>(m + 2 , 0)) ;
  vector<vector<int>>sufcolm_i(n + 2 , vector<int>(m + 2 , 0)) ;
  for(int i = 1 ; i <= n ; i ++) {
    for(int j = 1 ; j <= m ; j ++) {
      if(a[i][j] == 'O') {
        sufrow_o[i][j] = 1 ;
      }
      if(a[i][j] == 'I') {
        sufcolm_i[i][j] = 1 ;
      }
    }
    //cout << endl ;
  }
  for(int i = 1; i <= n; i++) {
    for(int j = m - 1; j >= 1; j--) {
      sufrow_o[i][j] = sufrow_o[i][j] + sufrow_o[i][j + 1];
    }
  }
  for(int j = 1; j <= m; j++) {
    for(int i = n - 1; i >= 1; i--) {
      sufcolm_i[i][j] = sufcolm_i[i][j] + sufcolm_i[i + 1][j];
    }
  }
  int ans = 0 ;
  for(int i = 1 ; i <= n ; i ++) {
    for(int j = 1 ; j <= m ; j ++) {
      if(a[i][j] == 'J') {
        ans += sufrow_o[i][j + 1] * sufcolm_i[i + 1][j] ;
      }
    }
  }
  cout << ans ;
}
///////////////////////////////////////////////
///////////////////////////////////////////////
signed main() {
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  //sufcompute() ;
  IO ;
  int t = 1 ; // cin >> t ;
  while(t --) {
    solve() ;
    cout << endl ;
  }
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…