Submission #228187

# Submission time Handle Problem Language Result Execution time Memory
228187 2020-04-30T07:28:24 Z Vimmer Strah (COCI18_strah) C++14
0 / 110
125 ms 22220 KB
#include <bits/stdc++.h>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")

#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 200005
#define M ll(1e9 + 7)

using namespace std;

typedef long double ld;

typedef long long ll;

typedef short int si;


int h[2005][2005], lf[2005], rg[2005];

vector <int> g;

int main()
{
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n, m;

    cin >> n >> m;

    string s[n];

    for (int i = 0; i < n; i++) cin >> s[i];

    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
        {
            if (s[i][j] == '#') {h[i][j] = 0; continue;}

            h[i][j] = 1;

            if (i != 0) h[i][j] += h[i - 1][j];
        }

    ll ans = 0;

    for (int i = 0; i < n; i++)
    {
        g.clear();

        for (int j = 0; j < m; j++)
        {
            while (sz(g) && h[i][g.back()] >= h[i][j]) g.pop_back();

            if (sz(g)) lf[j] = g.back(); else lf[j] = -1;

            g.pb(j);
        }

        g.clear();

        for (int j = m - 1; j >= 0; j--)
        {
            while (sz(g) && h[i][g.back()] >= h[i][j]) g.pop_back();

            if (sz(g)) rg[j] = g.back(); else rg[j] = m;

            g.pb(j);
        }

        for (int j = 0; j < m; j++)
        {
            ll l = j - lf[j], r = rg[j] - j;

            ll kl = r * (l * (l + 1)) / 2 + l * (r * (r + 1)) / 2 - r * l;

            ll hr = h[i][j];

            ans += kl * (hr * (hr + 1)) / 2;
        }
    }

    cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 2048 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 2048 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 2048 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 45 ms 8064 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 100 ms 13820 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 57 ms 8776 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 8960 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 125 ms 22220 KB Output isn't correct
2 Halted 0 ms 0 KB -