Submission #1319318

#TimeUsernameProblemLanguageResultExecution timeMemory
1319318djsksbrbfBitaro the Brave (JOI19_ho_t1)C++20
100 / 100
199 ms150588 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pii;
#define fi first
#define se second
#define pb push_back
const int MOD = 1e9 + 7;
const int MAX = 2e5 + 5;
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
#define int ll

signed main(){
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   
   int n, m; cin >> n >> m;
   char a[n + 5][m + 5];
   for(int i = 1 ; i <= n ; i++){
      for(int j = 1 ; j <= m ; j++){
         cin >> a[i][j];
      }
   }
   
   ll sufos[n + 5][m + 5];
   for(int i = 1 ; i <= n ; i++){
      sufos[i][m + 1] = 0;
      for(int j = m ; j >= 1 ; j--)sufos[i][j] = sufos[i][j + 1] + (a[i][j] == 'O');
   }
   
   ll sufis[m + 5][n + 5];
   for(int i = 1 ; i <= m ; i++){
      sufis[i][n + 1] = 0;
      for(int j = n ; j >= 1 ; j--)sufis[i][j] = sufis[i][j + 1] + (a[j][i] == 'I');
   }
   ll ans = 0;
   for(int i = 1 ; i <= n ; i++){
      for(int j = 1 ; j <= m ; j++){
         if(a[i][j] == 'J'){
            ans += sufos[i][j + 1]*sufis[j][i + 1];
         }
      }
   }
   cout << ans << endl;
   
   return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...