Submission #518411

#TimeUsernameProblemLanguageResultExecution timeMemory
518411Alex_tz307Bitaro the Brave (JOI19_ho_t1)C++17
100 / 100
105 ms89552 KiB
#include <bits/stdc++.h>

using namespace std;

void testCase() {
  int n, m;
  cin >> n >> m;
  vector<string> a(n);
  for (auto &s : a) {
    cin >> s;
  }
  vector<vector<int>> ingot(n + 1, vector<int>(m + 1)), orb(n + 1, vector<int>(m + 1));
  int64_t ans = 0;
  for (int i = n - 1; i >= 0; --i) {
    for (int j = m - 1; j >= 0; --j) {
      if (a[i][j] == 'J') {
        ans += (int64_t)ingot[i + 1][j] * orb[i][j + 1];
      }
      ingot[i][j] = ingot[i + 1][j] + (a[i][j] == 'I');
      orb[i][j] = orb[i][j + 1] + (a[i][j] == 'O');
    }
  }
  cout << ans << '\n';
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int tests = 1;
  for (int tc = 0; tc < tests; ++tc) {
    testCase();
  }
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...