Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifdef DEBUG
- #define _GLIBCXX_DEBUG
- #endif
- #include <bits/stdc++.h>
- using namespace std;
- typedef long double ld;
- #ifdef DEBUG
- #define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
- #else
- #define eprintf(...) ;
- #endif
- #define sz(x) ((int) (x).size())
- #define TASK "text"
- const int inf = (int) 1.01e9;
- const long long infll = (long long) 1.01e18;
- const ld eps = 1e-9;
- const ld pi = acos((ld) -1);
- mt19937 mrand(random_device{} ());
- int rnd(int x) {
- return mrand() % x;
- }
- void precalc() {
- }
- vector<string> c;
- int read() {
- int r, cc;
- if (!(cin >> r) || !(cin >> cc)) {
- return false;
- }
- while (cin.peek() != '\n') {
- cin.get();
- }
- cin.get();
- c.clear();
- for (int i = 0; i < 2 * r - 1; i++) {
- string row;
- getline(cin, row);
- c.push_back(row);
- }
- if (!(r & 1)) {
- c.push_back("");
- c.push_back(c[0]);
- for (int i = 0; i < sz(c.back()); i++) {
- if (c.back()[i] == '-') {
- c.back()[i] = ' ';
- }
- }
- }
- return true;
- }
- void getPoint(int i, int j, int &x, int &y) {
- x = i / 2;
- y = (j + 2) / 4 + x / 2;
- }
- vector<vector<int>> es[3], d[4];
- vector<vector<int>> vals[2];
- vector<vector<int>> ps[2];
- vector<int> sums[2];
- long long res;
- void solve1() {
- int n = 0, m = 0;
- for (int i = 0; i < sz(c); i++) {
- const auto &row = c[i];
- for (int j = 0; j < sz(row); j++) {
- if (row[j] == 'x') {
- int x, y;
- getPoint(i, j, x, y);
- n = max(n, x + 1);
- m = max(m, y + 1);
- }
- }
- }
- for (int i = 0; i < 3; i++) {
- es[i] = vector<vector<int>>(n, vector<int>(m));
- }
- for (int i = 0; i < sz(c); i++) {
- const auto &row = c[i];
- for (int j = 0; j < sz(row); j++) {
- if (row[j] == '/') {
- int x, y;
- getPoint(i - 1, j + 1, x, y);
- es[0][x][y] = true;
- } else if (j + 1 < sz(row) && row[j] == 'x' && row[j + 1] == '-') {
- int x, y;
- getPoint(i, j, x, y);
- es[1][x][y] = true;
- } else if (row[j] == '\\') {
- int x, y;
- getPoint(i - 1, j - 1, x, y);
- es[2][x][y] = true;
- }
- }
- }
- for (int i = 0; i < 3; i++) {
- d[i] = es[i];
- }
- for (int i = n - 1; i >= 0; i--) {
- for (int j = m - 1; j >= 0; j--) {
- for (int dir = 0; dir < 3; dir++) {
- if (!d[dir][i][j]) {
- continue;
- }
- int ni = i, nj = j;
- if (dir == 0 || dir == 2) {
- ni++;
- }
- if (dir == 1 || dir == 2) {
- nj++;
- }
- d[dir][i][j] += d[dir][ni][nj];
- }
- }
- }
- d[3] = vector<vector<int>>(n, vector<int>(m, 0));
- for (int i = 0; i < n; i++) {
- d[3][i][0] = 0;
- for (int j = 1; j < m; j++) {
- d[3][i][j] = (es[1][i][j - 1] ? d[3][i][j - 1] + 1 : 0);
- }
- }
- vals[0] = vector<vector<int>>(m, vector<int>(n, 0));
- sums[0] = vector<int>(m, 0);
- ps[0] = vector<vector<int>>(m);
- vals[1] = vector<vector<int>>(n + m - 1, vector<int>(n, 0));
- sums[1] = vector<int>(n + m - 1, 0);
- ps[1] = vector<vector<int>>(n + m - 1);
- for (int i = n - 1; i >= 0; i--) {
- for (int j = 0; j < m; j++) {
- int xs[2] = {j, i - j + m - 1};
- for (int it = 0; it < 2; it++) {
- int x = xs[it];
- auto &vals = ::vals[it][x];
- auto &sum = sums[it][x];
- auto &ps = ::ps[it][x];
- while (sz(vals) > i + 1) {
- sum -= vals.back();
- vals.pop_back();
- }
- if (!d[2 * it][i][j]) {
- for (int ii = 0; ii < sz(ps); ii++) {
- if (ps[ii] < sz(vals)) {
- vals[ps[ii]]--;
- }
- }
- ps.clear();
- sum = 0;
- }
- }
- int t = (d[0][i][j] < d[2][i][j] ? 0 : 1);
- res += sums[t][xs[t]];
- for (int it = 0; it < 2; it++) {
- int x = xs[it];
- auto &vals = ::vals[it][x];
- auto &sum = sums[it][x];
- auto &ps = ::ps[it][x];
- int curd = i - (!it ? d[1][i][j] : d[3][i][j]);
- curd = max(0, curd);
- vals[curd]++;
- ps.push_back(curd);
- sum++;
- }
- }
- }
- }
- void solve() {
- res = 0;
- for (int it = 0; it < 2; it++) {
- solve1();
- reverse(c.begin(), c.end());
- for (int i = 0; i < sz(c); i++) {
- for (int j = 0; j < sz(c[i]); j++) {
- if (c[i][j] == '\\') {
- c[i][j] = '/';
- } else if (c[i][j] == '/') {
- c[i][j] = '\\';
- }
- }
- }
- }
- cout << res << "\n";
- }
- int main() {
- ios_base::sync_with_stdio(false);
- precalc();
- #ifdef DEBUG
- assert(freopen(TASK ".in", "r", stdin));
- assert(freopen(TASK ".out", "w", stdout));
- #endif
- while (read()) {
- solve();
- #ifdef DEBUG
- eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
- #endif
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement