Submission #979171

#TimeUsernameProblemLanguageResultExecution timeMemory
979171kilkuwuBitaro the Brave (JOI19_ho_t1)C++17
100 / 100
217 ms54404 KiB
#include <bits/stdc++.h>

#define nl '\n'

signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int H, W;
  std::cin >> H >> W;
  std::vector<std::string> S(H);
  for (int i = 0; i < H; i++) {
    std::cin >> S[i];
  }

  std::vector cnt(H, std::vector<int>(W + 1));


  for (int i = 0; i < H; i++) {
    for (int j = W - 1; j >= 0; j--) {
      cnt[i][j] = cnt[i][j + 1] + (S[i][j] == 'O');
    }
  }

  int64_t ans = 0;
  for (int j = 0; j < W; j++) {
    int64_t tot = 0;
    for (int i = 0; i < H; i++) {
      tot += (S[i][j] == 'J') * cnt[i][j];
      if (S[i][j] == 'I') {
        ans += tot;
      }
    }
  }

  std::cout << ans << nl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...