Submission #775852

#TimeUsernameProblemLanguageResultExecution timeMemory
775852gun_ganBitaro the Brave (JOI19_ho_t1)C++17
100 / 100
583 ms75116 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MX = 3e3 + 7;
int N, M;
vector<int> vert[MX], hori[MX];
vector<pair<int, int>> pos;

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

      cin >> N >> M;
      for(int i = 0; i < N; i++) {
            for(int j = 0; j < M; j++) {
                  char c;
                  cin >> c;

                  if(c == 'J') {
                        pos.push_back({i, j});
                  } else if(c == 'O') {
                        hori[i].push_back(j);
                  } else {
                        vert[j].push_back(i);
                  }     
            }
      }

      ll ans = 0;
      for(auto [x, y] : pos) {
            auto p = lower_bound(hori[x].begin(), hori[x].end(), y) - hori[x].begin();
            auto q = lower_bound(vert[y].begin(), vert[y].end(), x) - vert[y].begin();

            ans += 1LL * (hori[x].size() - p) * (vert[y].size() - q);
      }

      cout << ans << '\n';
            
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...