Submission #646850

#TimeUsernameProblemLanguageResultExecution timeMemory
646850tvladm2009Bitaro the Brave (JOI19_ho_t1)C++14
100 / 100
154 ms70824 KiB
#include <bits/stdc++.h>

using ll = long long;

int const nmax = 3000;

int a[1 + nmax][1 + nmax];
int ingots[1 + nmax][1 + nmax];

/*
1 -> jewel
2 -> orb
3 -> ingot
*/

int main() {
  std::ios_base::sync_with_stdio(0);
  std::cin.tie(0);

  int n, m;
  std::cin >> n >> m;
  for(int i = 1;i <= n; i++) {
    std::string s;
    std::cin >> s;
    for(int j = 1;j <= m; j++) {
      if(s[j - 1] == 'J')
        a[i][j] = 1;
      else if(s[j - 1] == 'O')
        a[i][j] = 2;
      else
        a[i][j] = 3;
    }
  }
  for(int i = n;i >= 1; i--) {
    for(int j = 1;j <= m; j++) {
      ingots[i][j] = ingots[i + 1][j];
      if(a[i][j] == 3)
        ingots[i][j]++;
    }
  }
  
  ll ans = 0;
  for(int i = 1;i <= n; i++) {
    int orbs = 0;
    for(int j = m; j >= 1; j--) {
      if(a[i][j] == 1) {
        ans += orbs * ingots[i][j];
      } else if(a[i][j] == 2) {
        orbs++;
      }
    }
  }
  std::cout << ans;
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...