답안 #940697

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
940697 2024-03-07T13:39:28 Z evenvalue Bitaro the Brave (JOI19_ho_t1) C++17
100 / 100
108 ms 89600 KB
#include <bits/stdc++.h>
using namespace std;

#ifdef evenvalue
  #include "debug.h"
#else
  #define debug(...)
#endif

using int64 = long long;
using ld = long double;

template<typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using max_heap = priority_queue<T, vector<T>, less<T>>;

namespace Read {
int Int() {
  int x;
  cin >> x;
  return x;
}
int64 Int64() {
  int64 x;
  cin >> x;
  return x;
}
char Char() {
  char c;
  cin >> c;
  return c;
}
string String() {
  string s;
  cin >> s;
  return s;
}
double Double() {
  return stod(String());
}
ld LongDouble() {
  return stold(String());
}
template<typename T1, typename T2>
pair<T1, T2> Pair() {
  pair<T1, T2> p;
  cin >> p.first >> p.second;
  return p;
}
template<typename T>
vector<T> Vec(const int n) {
  vector<T> v(n);
  for (T &x : v) {
    cin >> x;
  }
  return v;
}
template<typename T>
vector<vector<T>> VecVec(const int n, const int m) {
  vector<vector<T>> v(n);
  for (vector<T> &vec : v) {
    vec = Vec<T>(m);
  }
  return v;
}
}//namespace Read

constexpr int kInf = 1e9 + 10;
constexpr int64 kInf64 = 1e15 + 10;
constexpr int kMod = 1e9 + 7;
constexpr int kMaxN = 2e5 + 10;

inline void solution() {
  const auto n = Read::Int();
  const auto m = Read::Int();
  const auto grid = Read::Vec<string>(n);

  vector<vector<int>> below(n, vector<int>(m));
  vector<vector<int>> right(n, vector<int>(m));

  for (int j = 0; j < m; j++) {
    below[n - 1][j] = (grid[n - 1][j] == 'I');
  }
  for (int i = 0; i < n; i++) {
    right[i][m - 1] = (grid[i][m - 1] == 'O');
  }

  for (int i = n - 2; i >= 0; i--) {
    for (int j = 0; j < m; j++) {
      below[i][j] = below[i + 1][j] + (grid[i][j] == 'I');
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = m - 2; j >= 0; j--) {
      right[i][j] = right[i][j + 1] + (grid[i][j] == 'O');
    }
  }

  int64 ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (grid[i][j] != 'J') continue;
      ans += right[i][j] * 1LL * below[i][j];
    }
  }

  cout << ans << '\n';
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  //freopen(".in", "r", stdin);
  //freopen(".out", "w", stdout);

  cout << fixed << setprecision(10);

  int testcases = 1;
  //cin >> testcases;
  while (testcases--) {
    solution();
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 3 ms 2396 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 1628 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 3 ms 2900 KB Output is correct
19 Correct 3 ms 2652 KB Output is correct
20 Correct 3 ms 2908 KB Output is correct
21 Correct 4 ms 2760 KB Output is correct
22 Correct 3 ms 2652 KB Output is correct
23 Correct 3 ms 2908 KB Output is correct
24 Correct 5 ms 2976 KB Output is correct
25 Correct 3 ms 2652 KB Output is correct
26 Correct 3 ms 2908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 3 ms 2396 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 1628 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 3 ms 2900 KB Output is correct
19 Correct 3 ms 2652 KB Output is correct
20 Correct 3 ms 2908 KB Output is correct
21 Correct 4 ms 2760 KB Output is correct
22 Correct 3 ms 2652 KB Output is correct
23 Correct 3 ms 2908 KB Output is correct
24 Correct 5 ms 2976 KB Output is correct
25 Correct 3 ms 2652 KB Output is correct
26 Correct 3 ms 2908 KB Output is correct
27 Correct 95 ms 84704 KB Output is correct
28 Correct 1 ms 856 KB Output is correct
29 Correct 6 ms 6748 KB Output is correct
30 Correct 1 ms 496 KB Output is correct
31 Correct 72 ms 62404 KB Output is correct
32 Correct 82 ms 89116 KB Output is correct
33 Correct 81 ms 89212 KB Output is correct
34 Correct 94 ms 72104 KB Output is correct
35 Correct 78 ms 89048 KB Output is correct
36 Correct 76 ms 89412 KB Output is correct
37 Correct 108 ms 89600 KB Output is correct
38 Correct 58 ms 61784 KB Output is correct
39 Correct 56 ms 62036 KB Output is correct