제출 #1348673

#제출 시각아이디문제언어결과실행 시간메모리
1348673sorb852Bitaro the Brave (JOI19_ho_t1)C++17
100 / 100
170 ms103868 KiB
#include <iostream>
#include <vector>

#define ll long long

using namespace std;

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

  // freopen("other/input.txt", "r", stdin);

  int H, W;
  cin >> H >> W;

  vector<pair<int, int>> P;
  vector<vector<int>> l(H, vector<int>(W, 0));
  vector<vector<int>> k(H, vector<int>(W, 0));

  char buf;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> buf;
      l[i][j] = l[i][max(j - 1, 0)];
      k[i][j] = k[max(i - 1, 0)][j];
      switch (buf) {
      case 'J':
        P.emplace_back(i, j);
        break;
      case 'I':
        k[i][j]++;
        break;
      case 'O':
        l[i][j]++;
        break;
      }
    }
  }

  // for (int i = 0; i < H; i++) {
  //   for (int j = 0; j < W; j++) {
  //     cout << l[i][j] << ' ';
  //   }
  //   cout << endl;
  // }
  //
  // cout << "#############\n";
  //
  // for (int i = 0; i < H; i++) {
  //   for (int j = 0; j < W; j++) {
  //     cout << k[i][j] << ' ';
  //   }
  //   cout << endl;
  // }

  ll ans = 0;
  for (auto p : P) {
    int L = l[p.first][W - 1] - l[p.first][p.second];
    int K = k[H - 1][p.second] - k[p.first][p.second];
    ans += K * L;
  }

  cout << ans;

  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...