Submission #654668

#TimeUsernameProblemLanguageResultExecution timeMemory
654668lunchbox1Bitaro the Brave (JOI19_ho_t1)C++17
100 / 100
103 ms89460 KiB
/*
 Bitaro the Brave
 https://oj.uz/problem/view/JOI19_ho_t1
*/
#include <bits/stdc++.h>
using namespace std;

const int N = 3000;

int main() {
 ios::sync_with_stdio(0), cin.tie(0);
 int n, m; cin >> n >> m;
 static string s[N];
 for (int i = 0; i < n; i++) cin >> s[i];
 static int co[N][N], ci[N][N];
 long long ans = 0;
 for (int i = n - 1; i >= 0; i--)
  for (int j = m - 1; j >= 0; j--) {
   if (j < m - 1) co[i][j] += co[i][j + 1];
   if (i < n - 1) ci[i][j] += ci[i + 1][j];
   if (s[i][j] == 'J') ans += co[i][j] * ci[i][j];
   else if (s[i][j] == 'O') co[i][j]++;
   else ci[i][j]++;
  }
 cout << ans << '\n';
 return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...