Submission #296894

# Submission time Handle Problem Language Result Execution time Memory
296894 2020-09-11T03:55:56 Z HynDuf Strah (COCI18_strah) C++11
110 / 110
137 ms 23940 KB
#include <bits/stdc++.h>

#define task "S"
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';}
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define pf push_front
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ___next
#define prev ___prev
#define y1 ___y1
#define left ___left
#define right ___right
#define y0 ___y0
#define div ___div
#define j0 ___j0
#define jn ___jn

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int N = 2002;
int n, m, h[N][N], D[N], top, l[N], r[N];
string s[N];
int main()
{
#ifdef HynDuf
    freopen(task".in", "r", stdin);
    //freopen(task".out", "w", stdout);
#else
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
    cin >> n >> m;
    rep(i, 1, n)
    {
        cin >> s[i];
        s[i] = '0' + s[i];
    }
    ll ans = 0;
    rep(i, 1, n)
    {
        rep(j, 1, m) h[i][j] = (s[i][j] == '.' ? h[i - 1][j] + 1 : 0);
        top = 0;
        D[0] = 0;
        rep(j, 1, m)
        {
            while (top && h[i][D[top]] > h[i][j]) top--;
            l[j] = j - D[top];
            D[++top] = j;
        }
        top = 0;
        D[0] = m + 1;
        Rep(j, m, 1)
        {
            while (top && h[i][D[top]] >= h[i][j]) top--;
            r[j] = D[top] - j;
            D[++top] = j;
            ans += (1LL * r[j] * (l[j] - 1) * l[j] / 2 + 1LL * l[j] * r[j] * (r[j] + 1) / 2) * h[i][j] * (h[i][j] + 1) / 2;
        }

    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2176 KB Output is correct
2 Correct 4 ms 2176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2176 KB Output is correct
2 Correct 4 ms 2176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2176 KB Output is correct
2 Correct 4 ms 2208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 9208 KB Output is correct
2 Correct 88 ms 17008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 15704 KB Output is correct
2 Correct 125 ms 22776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 10104 KB Output is correct
2 Correct 96 ms 18168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 9312 KB Output is correct
2 Correct 80 ms 20984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 96 ms 23804 KB Output is correct
2 Correct 137 ms 23940 KB Output is correct